From 73f0e51298866db9afb83c1c9086c6e9234ff131 Mon Sep 17 00:00:00 2001 From: Aubrey-Li <63608597+Aubrey-Li@users.noreply.github.com> Date: Sat, 26 Jun 2021 13:00:52 -0700 Subject: overflow issue --- .../views/collections/CollectionMapView.scss | 13 +- src/client/views/collections/CollectionMapView.tsx | 315 ++++++--------------- 2 files changed, 101 insertions(+), 227 deletions(-) (limited to 'src') diff --git a/src/client/views/collections/CollectionMapView.scss b/src/client/views/collections/CollectionMapView.scss index 870b7fda8..e87c02611 100644 --- a/src/client/views/collections/CollectionMapView.scss +++ b/src/client/views/collections/CollectionMapView.scss @@ -1,6 +1,7 @@ .collectionMapView { width: 100%; height: 100%; + overflow: hidden; .collectionMapView-contents { width: 100%; @@ -8,6 +9,16 @@ > div { position: unset !important; // when the sidebar filter flys out, this prevents the map from extending outside the document box } + + .dash-label { + position: absolute; + top: 1rem; + left: 5rem; + color: black; + z-index: 10; + margin: 0; + padding: 0; + } } } @@ -27,4 +38,4 @@ width: 50px; height: 50px; } -} \ No newline at end of file +} diff --git a/src/client/views/collections/CollectionMapView.tsx b/src/client/views/collections/CollectionMapView.tsx index 2d7569d45..2203176de 100644 --- a/src/client/views/collections/CollectionMapView.tsx +++ b/src/client/views/collections/CollectionMapView.tsx @@ -1,4 +1,4 @@ -import { GoogleApiWrapper, IMapProps, Map as GeoMap, Marker } from "google-maps-react"; +import { GoogleMap, Marker, InfoWindow, LoadScript, GoogleMapProps } from '@react-google-maps/api'; import { action, computed, Lambda, runInAction } from "mobx"; import { observer } from "mobx-react"; import { Doc, DocListCast, Field, FieldResult, Opt } from "../../../fields/Doc"; @@ -22,248 +22,111 @@ export type LocationData = google.maps.LatLngLiteral & { zoom?: number; }; -interface DocLatLng { - lat: FieldResult; - lng: FieldResult; -} - -// Nowhere, Oklahoma -const defaultLocation = { lat: 35.1592238, lng: -98.444512, zoom: 15 }; -const noResults = "ZERO_RESULTS"; - -const query = async (data: string | google.maps.LatLngLiteral) => { - const contents = typeof data === "string" ? `address=${data.replace(/\s+/g, "+")}` : `latlng=${data.lat},${data.lng}`; - const target = `https://maps.googleapis.com/maps/api/geocode/json?${contents}&key=${process.env.GOOGLE_MAPS_GEO}`; - try { - return JSON.parse(await requestPromise.get(target)); - } catch { - return undefined; - } +const mapContainerStyle = { + width: '100%', + heiht: '100%', + overflow: 'hidden', }; -@observer -export class CollectionMapView extends CollectionSubView & { google: any }>(MapSchema) { - - private _cancelAddrReq = new Map(); - private _cancelLocReq = new Map(); - private _initialLookupPending = new Map(); - private responders: { locationDisposer: Lambda, addressDisposer: Lambda }[] = []; - /** - * Note that all the uses of runInAction below are not included - * as a way to update observables (documents handle this already - * in their property setters), but rather to create a single bulk - * update and thus prevent uneeded invocations of the location- - * and address–updating reactions. - */ - - private getLocation = (doc: Opt, fieldKey: string, returnDefault: boolean = true): Opt => { - if (doc) { - const titleLoc = StrCast(doc.title).startsWith("@") ? StrCast(doc.title).substring(1) : undefined; - const lat = Cast(doc[`${fieldKey}-lat`], "number", null) || (Cast(doc[`${fieldKey}-lat`], "string", null) && Number(Cast(doc[`${fieldKey}-lat`], "string", null))) || undefined; - const lng = Cast(doc[`${fieldKey}-lng`], "number", null) || (Cast(doc[`${fieldKey}-lng`], "string", null) && Number(Cast(doc[`${fieldKey}-lng`], "string", null))) || undefined; - const zoom = Cast(doc[`${fieldKey}-zoom`], "number", null) || (Cast(doc[`${fieldKey}-zoom`], "string", null) && Number(Cast(doc[`${fieldKey}-zoom`], "string", null))) || undefined; - const address = titleLoc || StrCast(doc[`${fieldKey}-address`], StrCast(doc.title).replace(/^-/, "")); - if (titleLoc || (address && (lat === undefined || lng === undefined))) { - const id = doc[Id]; - if (!this._initialLookupPending.get(id)) { - this._initialLookupPending.set(id, true); - setTimeout(() => { - titleLoc && Doc.SetInPlace(doc, `${fieldKey}-address`, titleLoc, true); - this.respondToAddressChange(doc, fieldKey, address).then(() => this._initialLookupPending.delete(id)); - }); - } - } - return (lat === undefined || lng === undefined) ? (returnDefault ? defaultLocation : undefined) : { lat, lng, zoom }; - } - return undefined; - } +const defaultCenter = { + lat: 0, + lng: 0, +} +//-----------------------------test map marker----------------------------------- +// const map = new google.maps.Map(document.getElementById('map')!, { +// zoom: 10, +// center: new google.maps.LatLng(-33.92, 151.25), +// mapTypeId: google.maps.MapTypeId.ROADMAP +// }); + +// // test display markers +// let locations = [ +// ['Bondi Beach', -33.890542, 151.274856, 4], +// ['Coogee Beach', -33.923036, 151.259052, 5], +// ['Cronulla Beach', -34.028249, 151.157507, 3], +// ['Manly Beach', -33.80010128657071, 151.28747820854187, 2], +// ['Maroubra Beach', -33.950198, 151.259302, 1] +// ]; + +// const infowindow = new google.maps.InfoWindow(); +// let marker: google.maps.Marker +// let i: number + +// for (i = 0; i < locations.length; i++) { +// marker = new google.maps.Marker({ +// position: new google.maps.LatLng(locations[i][1] as number, locations[i][2] as number), +// map: map +// }); + +// google.maps.event.addListener(marker, 'click', (function (marker, i) { +// return function () { +// infowindow.setContent(locations[i][0] as string); +// infowindow.open(map, marker); +// } +// })(marker, i)); +// } + +//---------------------------------------------------------------- - private markerClick = async (layout: Doc, { lat, lng, zoom }: LocationData) => { - const batch = UndoManager.StartBatch("marker click"); - const { fieldKey } = this.props; - runInAction(() => { - this.layoutDoc[`${fieldKey}-mapCenter-lat`] = lat; - this.layoutDoc[`${fieldKey}-mapCenter-lng`] = lng; - zoom && (this.layoutDoc[`${fieldKey}-mapCenter-zoom`] = zoom); - }); - if (layout.isLinkButton && DocListCast(layout.links).length) { - await LinkManager.traverseLink(undefined, layout, (doc: Doc, where: string, finished?: () => void) => { - this.props.addDocTab(doc, where); - finished?.(); - }, false, this.props.ContainingCollectionDoc, batch.end, undefined); - } else { - ScriptCast(layout.onClick)?.script.run({ this: layout, self: Cast(layout.rootDocument, Doc, null) || layout }); - batch.end(); - } - } +@observer +export default class CollectionMapView extends CollectionSubView(MapSchema) { - private renderMarkerIcon = (layout: Doc) => { - const { Document } = this.props; - const fieldKey = Doc.LayoutFieldKey(layout); - const iconUrl = StrCast(layout.mapIconUrl, StrCast(Document.mapIconUrl)); - if (iconUrl) { - const iconWidth = NumCast(layout[`${fieldKey}-iconWidth`], 45); - const iconHeight = NumCast(layout[`${fieldKey}-iconHeight`], 45); - const iconSize = new google.maps.Size(iconWidth, iconHeight); - return { - size: iconSize, - scaledSize: iconSize, - url: iconUrl - }; - } - } - private renderMarker = (layout: Doc, fieldKey?: string) => { - const location = this.getLocation(layout, fieldKey || Doc.LayoutFieldKey(layout)); - return !location ? (null) : - this.markerClick(layout, location)} - icon={this.renderMarkerIcon(layout)} - />; - } + render() { + const { childLayoutPairs } = this; + const { Document, fieldKey, isContentActive: active } = this.props; - private respondToAddressChange = async (doc: Doc, fieldKey: string, newAddress: string, oldAddress?: string) => { - if (newAddress === oldAddress) { - return false; - } - const response = await query(newAddress); - const id = doc[Id]; - if (!response || response.status === noResults) { - this._cancelAddrReq.set(id, true); - doc[`${fieldKey}-address`] = oldAddress; - return false; - } - const { geometry, formatted_address } = response.results[0]; - const { lat, lng } = geometry.location; - runInAction(() => { - if (doc[`${fieldKey}-lat`] !== lat || doc[`${fieldKey}-lng`] !== lng) { - this._cancelLocReq.set(id, true); - Doc.SetInPlace(doc, `${fieldKey}-lat`, lat, true); - Doc.SetInPlace(doc, `${fieldKey}-lng`, lng, true); - } - if (formatted_address !== newAddress) { - this._cancelAddrReq.set(id, true); - Doc.SetInPlace(doc, `${fieldKey}-address`, formatted_address, true); - } - }); - return true; - } + // const { isLoaded, loadError } = useLoadScript({ + // googleMapsApiKey: 'AIzaSyALJU8DfCAqEAS0OqMDCmkE0otlz4H81fg', + // libraries: ['places'] + // }) - private respondToLocationChange = async (doc: Doc, fieldKey: string, newLatLng: DocLatLng, oldLatLng: Opt) => { - if (newLatLng === oldLatLng) { - return false; - } - const response = await query({ lat: NumCast(newLatLng.lat), lng: NumCast(newLatLng.lng) }); - const id = doc[Id]; - if (!response || response.status === noResults) { - this._cancelLocReq.set(id, true); - runInAction(() => { - doc[`${fieldKey}-lat`] = oldLatLng?.lat; - doc[`${fieldKey}-lng`] = oldLatLng?.lng; - }); - return false; - } - const { formatted_address } = response.results[0]; - if (formatted_address !== doc[`${fieldKey}-address`]) { - this._cancelAddrReq.set(doc[Id], true); - Doc.SetInPlace(doc, `${fieldKey}-address`, formatted_address, true); - } - return true; - } + // if (loadError) return "Error loading maps"; + // if (!isLoaded) return "Loading Maps"; - @computed get reactiveContents() { - this.responders.forEach(({ locationDisposer, addressDisposer }) => { - locationDisposer(); - addressDisposer(); - }); - this.responders = []; - return this.childLayoutPairs.map(({ layout }) => { - const fieldKey = Doc.LayoutFieldKey(layout); - const id = layout[Id]; - this.responders.push({ - locationDisposer: computed(() => ({ lat: layout[`${fieldKey}-lat`], lng: layout[`${fieldKey}-lng`] })) - .observe(({ oldValue, newValue }) => { - if (this._cancelLocReq.get(id)) { - this._cancelLocReq.set(id, false); - } else if (newValue.lat !== undefined && newValue.lng !== undefined) { - this.respondToLocationChange(layout, fieldKey, newValue, oldValue); - } - }), - addressDisposer: computed(() => Cast(layout[`${fieldKey}-address`], "string", null)) - .observe(({ oldValue, newValue }) => { - if (this._cancelAddrReq.get(id)) { - this._cancelAddrReq.set(id, false); - } else if (newValue?.length) { - this.respondToAddressChange(layout, fieldKey, newValue, oldValue); - } - }) - }); - return this.renderMarker(layout); - }); - } - render() { - const { childLayoutPairs } = this; - const { Document, fieldKey, isContentActive: active, google } = this.props; - const mapLoc = this.getLocation(this.rootDoc, `${fieldKey}-mapCenter`, false); - let center = mapLoc; - if (center === undefined) { - const childLocations = childLayoutPairs.map(({ layout }) => this.getLocation(layout, Doc.LayoutFieldKey(layout), false)); - center = childLocations.find(location => location) || defaultLocation; - } return
+
e.stopPropagation()} onPointerDown={e => (e.button === 0 && !e.ctrlKey) && e.stopPropagation()} > - { - if (this.layoutDoc._lockedTransform) { - // reset zoom (ideally, we could probably can tell the map to disallow zooming somehow instead) - map?.setZoom(center?.zoom || 10); - map?.setCenter({ lat: center?.lat!, lng: center?.lng! }); - } else { - const zoom = map?.getZoom(); - (center?.zoom !== zoom) && undoBatch(action(() => { - Document[`${fieldKey}-mapCenter-zoom`] = zoom; - }))(); - } - }} - onDragend={(_props?: IMapProps, map?: google.maps.Map) => { - if (this.layoutDoc._lockedTransform) { - // reset the drag (ideally, we could probably can tell the map to disallow dragging somehow instead) - map?.setCenter({ lat: center?.lat!, lng: center?.lng! }); - } else { - undoBatch(action(({ lat, lng }) => { - Document[`${fieldKey}-mapCenter-lat`] = lat(); - Document[`${fieldKey}-mapCenter-lng`] = lng(); - }))(map?.getCenter()); - } - }} +

+ Dash! +

+ - {this.reactiveContents} - {mapLoc && StrCast(this.rootDoc[`${fieldKey}-mapCenter-address`]) ? this.renderMarker(this.rootDoc, `${fieldKey}-mapCenter`) : undefined} -
+ + + + + +
-
; + ; } } -export default GoogleApiWrapper({ - apiKey: process.env.GOOGLE_MAPS!, - LoadingContainer: () => { - console.log(process.env.GOOGLE_MAPS); - return
- -
; - } -})(CollectionMapView) as any; \ No newline at end of file +// export default GoogleApiWrapper({ +// // apiKey: process.env.REACT_APP_DASH_GOOGLE_MAPS_API_KEY!, +// apiKey: 'AIzaSyALJU8DfCAqEAS0OqMDCmkE0otlz4H81fg', +// LoadingContainer: () => { +// console.log(process.env.REACT_APP_DASH_GOOGLE_MAPS_API_KEY); +// return
+// +//
; +// } +// })(CollectionMapView) as any; \ No newline at end of file -- cgit v1.2.3-70-g09d2 From 0a152e2ca315171c5b8a80c8f3c2dc57c6e14c65 Mon Sep 17 00:00:00 2001 From: geireann Date: Mon, 28 Jun 2021 12:48:53 -0400 Subject: map overflow fix --- src/client/views/collections/CollectionMapView.tsx | 35 +++++++++++----------- 1 file changed, 17 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/client/views/collections/CollectionMapView.tsx b/src/client/views/collections/CollectionMapView.tsx index 2203176de..77a7c3ee0 100644 --- a/src/client/views/collections/CollectionMapView.tsx +++ b/src/client/views/collections/CollectionMapView.tsx @@ -23,9 +23,7 @@ export type LocationData = google.maps.LatLngLiteral & { }; const mapContainerStyle = { - width: '100%', - heiht: '100%', - overflow: 'hidden', + height: '100%', }; @@ -96,23 +94,24 @@ export default class CollectionMapView extends CollectionSubView - - - - - +
+ + + + +
; -- cgit v1.2.3-70-g09d2 From dbff7ae16f240f80b8b8131d35929b4a2135d0aa Mon Sep 17 00:00:00 2001 From: Aubrey-Li <63608597+Aubrey-Li@users.noreply.github.com> Date: Mon, 28 Jun 2021 10:28:52 -0700 Subject: env updates --- maps.env | 1 - .../views/collections/CollectionMapView.scss | 11 +--------- src/client/views/collections/CollectionMapView.tsx | 25 ++++++++++------------ 3 files changed, 12 insertions(+), 25 deletions(-) delete mode 100644 maps.env (limited to 'src') diff --git a/maps.env b/maps.env deleted file mode 100644 index d475c04ad..000000000 --- a/maps.env +++ /dev/null @@ -1 +0,0 @@ -REACT_APP_DASH_GOOGLE_MAPS_API_KEY="AIzaSyALJU8DfCAqEAS0OqMDCmkE0otlz4H81fg" diff --git a/src/client/views/collections/CollectionMapView.scss b/src/client/views/collections/CollectionMapView.scss index e87c02611..874511533 100644 --- a/src/client/views/collections/CollectionMapView.scss +++ b/src/client/views/collections/CollectionMapView.scss @@ -6,19 +6,10 @@ .collectionMapView-contents { width: 100%; height: 100%; + overflow: hidden; > div { position: unset !important; // when the sidebar filter flys out, this prevents the map from extending outside the document box } - - .dash-label { - position: absolute; - top: 1rem; - left: 5rem; - color: black; - z-index: 10; - margin: 0; - padding: 0; - } } } diff --git a/src/client/views/collections/CollectionMapView.tsx b/src/client/views/collections/CollectionMapView.tsx index 2203176de..67864f92f 100644 --- a/src/client/views/collections/CollectionMapView.tsx +++ b/src/client/views/collections/CollectionMapView.tsx @@ -87,19 +87,15 @@ export default class CollectionMapView extends CollectionSubView + +
e.stopPropagation()} + onPointerDown={e => (e.button === 0 && !e.ctrlKey) && e.stopPropagation()} > -
e.stopPropagation()} - onPointerDown={e => (e.button === 0 && !e.ctrlKey) && e.stopPropagation()} > -

- Dash! -

- - -
+ +
+
; } -- cgit v1.2.3-70-g09d2 From d675e32fdf2f4e0ca5a7adf8cbc5b462e81bc7f0 Mon Sep 17 00:00:00 2001 From: Aubrey-Li <63608597+Aubrey-Li@users.noreply.github.com> Date: Mon, 5 Jul 2021 13:28:54 -0700 Subject: searchbox zoom in and center on search --- package-lock.json | 138 +++++++++ package.json | 2 + .../views/collections/CollectionMapView.scss | 32 --- src/client/views/collections/CollectionMapView.tsx | 127 --------- src/client/views/collections/CollectionView.tsx | 2 +- .../collections/MapView/CollectionMapView.scss | 50 ++++ .../collections/MapView/CollectionMapView.tsx | 312 +++++++++++++++++++++ src/client/views/nodes/PresBox.tsx | 13 +- .../views/presentationview/PresElementBox.tsx | 4 + 9 files changed, 518 insertions(+), 162 deletions(-) delete mode 100644 src/client/views/collections/CollectionMapView.scss delete mode 100644 src/client/views/collections/CollectionMapView.tsx create mode 100644 src/client/views/collections/MapView/CollectionMapView.scss create mode 100644 src/client/views/collections/MapView/CollectionMapView.tsx (limited to 'src') diff --git a/package-lock.json b/package-lock.json index 9032ebba8..9f82ee33f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -586,6 +586,134 @@ "react-is": "^16.8.0" } }, + "@reach/auto-id": { + "version": "0.15.2", + "resolved": "https://registry.npmjs.org/@reach/auto-id/-/auto-id-0.15.2.tgz", + "integrity": "sha512-K7d5qhYBlBHIjy+IpSEAyMeB5VTZ9m0tZdr7xyNd5Fr6oeefHEvJiJGuQpubP5bDoe7ShC3y0VQGFmT0g7KcZg==", + "requires": { + "@reach/utils": "0.15.2", + "tslib": "^2.3.0" + }, + "dependencies": { + "tslib": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.0.tgz", + "integrity": "sha512-N82ooyxVNm6h1riLCoyS9e3fuJ3AMG2zIZs2Gd1ATcSFjSA23Q0fzjjZeh0jbJvWVDZ0cJT8yaNNaaXHzueNjg==" + } + } + }, + "@reach/combobox": { + "version": "0.15.2", + "resolved": "https://registry.npmjs.org/@reach/combobox/-/combobox-0.15.2.tgz", + "integrity": "sha512-FjF1Tm7rvAI14joBD+2kco9Hlrmsum2ps0Atd4+UJpKAhQFZ2zmxi4oK1WeFavm4LQwuzAV2MFL+7Oe0TgrsUQ==", + "requires": { + "@reach/auto-id": "0.15.2", + "@reach/descendants": "0.15.2", + "@reach/popover": "0.15.2", + "@reach/portal": "0.15.2", + "@reach/utils": "0.15.2", + "prop-types": "^15.7.2", + "tslib": "^2.3.0" + }, + "dependencies": { + "tslib": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.0.tgz", + "integrity": "sha512-N82ooyxVNm6h1riLCoyS9e3fuJ3AMG2zIZs2Gd1ATcSFjSA23Q0fzjjZeh0jbJvWVDZ0cJT8yaNNaaXHzueNjg==" + } + } + }, + "@reach/descendants": { + "version": "0.15.2", + "resolved": "https://registry.npmjs.org/@reach/descendants/-/descendants-0.15.2.tgz", + "integrity": "sha512-GdQXWVpscss89MOhWh+sL4TnIn0qX1y+Te3wE72aKQrz/QCR69JFEW4wftovmF7rFm4/kDZcp14lMy512U6VlA==", + "requires": { + "@reach/utils": "0.15.2", + "tslib": "^2.3.0" + }, + "dependencies": { + "tslib": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.0.tgz", + "integrity": "sha512-N82ooyxVNm6h1riLCoyS9e3fuJ3AMG2zIZs2Gd1ATcSFjSA23Q0fzjjZeh0jbJvWVDZ0cJT8yaNNaaXHzueNjg==" + } + } + }, + "@reach/observe-rect": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@reach/observe-rect/-/observe-rect-1.2.0.tgz", + "integrity": "sha512-Ba7HmkFgfQxZqqaeIWWkNK0rEhpxVQHIoVyW1YDSkGsGIXzcaW4deC8B0pZrNSSyLTdIk7y+5olKt5+g0GmFIQ==" + }, + "@reach/popover": { + "version": "0.15.2", + "resolved": "https://registry.npmjs.org/@reach/popover/-/popover-0.15.2.tgz", + "integrity": "sha512-92Ov7VPXjn4ciOVupeekki03lSMz9NAmw2BjWYE9mVvYWKyDx5jx2srtbkIqUaSCkAVV3KEsFUia8aMm60FDZg==", + "requires": { + "@reach/portal": "0.15.2", + "@reach/rect": "0.15.2", + "@reach/utils": "0.15.2", + "tabbable": "^4.0.0", + "tslib": "^2.3.0" + }, + "dependencies": { + "tslib": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.0.tgz", + "integrity": "sha512-N82ooyxVNm6h1riLCoyS9e3fuJ3AMG2zIZs2Gd1ATcSFjSA23Q0fzjjZeh0jbJvWVDZ0cJT8yaNNaaXHzueNjg==" + } + } + }, + "@reach/portal": { + "version": "0.15.2", + "resolved": "https://registry.npmjs.org/@reach/portal/-/portal-0.15.2.tgz", + "integrity": "sha512-5x+dchGr4btRnLazwmyCYbSPVJAIrw0eXwhz7Vj9uT/EIp43WzOtTcODdLOoH6Ol2QLjX1Yt/fBjdK9+UAKxSA==", + "requires": { + "@reach/utils": "0.15.2", + "tslib": "^2.3.0" + }, + "dependencies": { + "tslib": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.0.tgz", + "integrity": "sha512-N82ooyxVNm6h1riLCoyS9e3fuJ3AMG2zIZs2Gd1ATcSFjSA23Q0fzjjZeh0jbJvWVDZ0cJT8yaNNaaXHzueNjg==" + } + } + }, + "@reach/rect": { + "version": "0.15.2", + "resolved": "https://registry.npmjs.org/@reach/rect/-/rect-0.15.2.tgz", + "integrity": "sha512-S2lzvvfclUHdvgcfW/eoz0i729HJvG5f6ayVaXcKz+X6LKF9i9Jdhfwsz7b3UmnSCihKNs0cX5tyWfWr1E1JFw==", + "requires": { + "@reach/observe-rect": "1.2.0", + "@reach/utils": "0.15.2", + "prop-types": "^15.7.2", + "tiny-warning": "^1.0.3", + "tslib": "^2.3.0" + }, + "dependencies": { + "tslib": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.0.tgz", + "integrity": "sha512-N82ooyxVNm6h1riLCoyS9e3fuJ3AMG2zIZs2Gd1ATcSFjSA23Q0fzjjZeh0jbJvWVDZ0cJT8yaNNaaXHzueNjg==" + } + } + }, + "@reach/utils": { + "version": "0.15.2", + "resolved": "https://registry.npmjs.org/@reach/utils/-/utils-0.15.2.tgz", + "integrity": "sha512-Lr1SJ5X4hEjD/M0TAonURM8wytM/JuPSuIP7t+e5cil34pThyLsBvTGeNfmpSgaLJ5vlsv0x9u6g4SRAEr84Og==", + "requires": { + "tiny-warning": "^1.0.3", + "tslib": "^2.3.0" + }, + "dependencies": { + "tslib": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.0.tgz", + "integrity": "sha512-N82ooyxVNm6h1riLCoyS9e3fuJ3AMG2zIZs2Gd1ATcSFjSA23Q0fzjjZeh0jbJvWVDZ0cJT8yaNNaaXHzueNjg==" + } + } + }, "@react-google-maps/api": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/@react-google-maps/api/-/api-2.2.0.tgz", @@ -17122,6 +17250,11 @@ "integrity": "sha512-9QNk5KwDF+Bvz+PyObkmSYjI5ksVUYtjW7AU22r2NKcfLJcXp96hkDWU3+XndOsUb+AQ9QhfzfCT2O+CNWT5Tw==", "dev": true }, + "tabbable": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/tabbable/-/tabbable-4.0.0.tgz", + "integrity": "sha512-H1XoH1URcBOa/rZZWxLxHCtOdVUEev+9vo5YdYhC9tCY4wnybX+VQrCYuy9ubkg69fCBxCONJOSLGfw0DWMffQ==" + }, "table-layout": { "version": "0.4.5", "resolved": "https://registry.npmjs.org/table-layout/-/table-layout-0.4.5.tgz", @@ -18341,6 +18474,11 @@ "resolved": "https://registry.npmjs.org/use-memo-one/-/use-memo-one-1.1.1.tgz", "integrity": "sha512-oFfsyun+bP7RX8X2AskHNTxu+R3QdE/RC5IefMbqptmACAA/gfol1KDD5KRzPsGMa62sWxGZw+Ui43u6x4ddoQ==" }, + "use-places-autocomplete": { + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/use-places-autocomplete/-/use-places-autocomplete-1.9.3.tgz", + "integrity": "sha512-9N05hAAKttkx3e6WVW6MR2q53v2FN2TbmwAAPES26gUINb8P5ZzHvoT4D/E+NLY3qnGehGffYRm1Iflro29GQQ==" + }, "util": { "version": "0.11.1", "resolved": "https://registry.npmjs.org/util/-/util-0.11.1.tgz", diff --git a/package.json b/package.json index 9df32995c..666ebc946 100644 --- a/package.json +++ b/package.json @@ -125,6 +125,7 @@ "@hig/theme-context": "^2.1.3", "@hig/theme-data": "^2.16.1", "@material-ui/core": "^4.11.0", + "@reach/combobox": "^0.15.2", "@react-google-maps/api": "^2.2.0", "@react-three/fiber": "^6.0.16", "@types/cors": "^2.8.8", @@ -270,6 +271,7 @@ "typescript-collections": "^1.3.3", "typescript-language-server": "^0.4.0", "url-loader": "^1.1.2", + "use-places-autocomplete": "^1.9.3", "uuid": "^3.4.0", "valid-url": "^1.0.9", "web-request": "^1.0.7", diff --git a/src/client/views/collections/CollectionMapView.scss b/src/client/views/collections/CollectionMapView.scss deleted file mode 100644 index 874511533..000000000 --- a/src/client/views/collections/CollectionMapView.scss +++ /dev/null @@ -1,32 +0,0 @@ -.collectionMapView { - width: 100%; - height: 100%; - overflow: hidden; - - .collectionMapView-contents { - width: 100%; - height: 100%; - overflow: hidden; - > div { - position: unset !important; // when the sidebar filter flys out, this prevents the map from extending outside the document box - } - } -} - -.loadingWrapper { - width: 100%; - height: 100%; - background-color: pink; - display: flex; - flex-direction: column; - justify-content: center; - align-items: center; - text-align: center; - - .loadingGif { - align-self: center; - justify-self: center; - width: 50px; - height: 50px; - } -} diff --git a/src/client/views/collections/CollectionMapView.tsx b/src/client/views/collections/CollectionMapView.tsx deleted file mode 100644 index 07755ed71..000000000 --- a/src/client/views/collections/CollectionMapView.tsx +++ /dev/null @@ -1,127 +0,0 @@ -import { GoogleMap, Marker, InfoWindow, LoadScript, GoogleMapProps } from '@react-google-maps/api'; -import { action, computed, Lambda, runInAction } from "mobx"; -import { observer } from "mobx-react"; -import { Doc, DocListCast, Field, FieldResult, Opt } from "../../../fields/Doc"; -import { documentSchema } from "../../../fields/documentSchemas"; -import { Id } from "../../../fields/FieldSymbols"; -import { makeInterface } from "../../../fields/Schema"; -import { Cast, NumCast, ScriptCast, StrCast } from "../../../fields/Types"; -import { LinkManager } from "../../util/LinkManager"; -import { undoBatch, UndoManager } from "../../util/UndoManager"; -import "./CollectionMapView.scss"; -import { CollectionSubView } from "./CollectionSubView"; -import React = require("react"); -import requestPromise = require("request-promise"); - -type MapSchema = makeInterface<[typeof documentSchema]>; -const MapSchema = makeInterface(documentSchema); - -export type LocationData = google.maps.LatLngLiteral & { - address?: string - resolvedAddress?: string; - zoom?: number; -}; - -const mapContainerStyle = { - height: '100%', -}; - - -const defaultCenter = { - lat: 0, - lng: 0, -} -//-----------------------------test map marker----------------------------------- -// const map = new google.maps.Map(document.getElementById('map')!, { -// zoom: 10, -// center: new google.maps.LatLng(-33.92, 151.25), -// mapTypeId: google.maps.MapTypeId.ROADMAP -// }); - -// // test display markers -// let locations = [ -// ['Bondi Beach', -33.890542, 151.274856, 4], -// ['Coogee Beach', -33.923036, 151.259052, 5], -// ['Cronulla Beach', -34.028249, 151.157507, 3], -// ['Manly Beach', -33.80010128657071, 151.28747820854187, 2], -// ['Maroubra Beach', -33.950198, 151.259302, 1] -// ]; - -// const infowindow = new google.maps.InfoWindow(); -// let marker: google.maps.Marker -// let i: number - -// for (i = 0; i < locations.length; i++) { -// marker = new google.maps.Marker({ -// position: new google.maps.LatLng(locations[i][1] as number, locations[i][2] as number), -// map: map -// }); - -// google.maps.event.addListener(marker, 'click', (function (marker, i) { -// return function () { -// infowindow.setContent(locations[i][0] as string); -// infowindow.open(map, marker); -// } -// })(marker, i)); -// } - -//---------------------------------------------------------------- - -@observer -export default class CollectionMapView extends CollectionSubView(MapSchema) { - - - render() { - const { childLayoutPairs } = this; - const { Document, fieldKey, isContentActive: active } = this.props; - - // const { isLoaded, loadError } = useLoadScript({ - // googleMapsApiKey: 'AIzaSyALJU8DfCAqEAS0OqMDCmkE0otlz4H81fg', - // libraries: ['places'] - // }) - - // if (loadError) return "Error loading maps"; - // if (!isLoaded) return "Loading Maps"; - - - return
- -
e.stopPropagation()} - onPointerDown={e => (e.button === 0 && !e.ctrlKey) && e.stopPropagation()} > - -
- - - - -
-
-
-
; - } - -} - -// export default GoogleApiWrapper({ -// // apiKey: process.env.REACT_APP_DASH_GOOGLE_MAPS_API_KEY!, -// apiKey: 'AIzaSyALJU8DfCAqEAS0OqMDCmkE0otlz4H81fg', -// LoadingContainer: () => { -// console.log(process.env.REACT_APP_DASH_GOOGLE_MAPS_API_KEY); -// return
-// -//
; -// } -// })(CollectionMapView) as any; \ No newline at end of file diff --git a/src/client/views/collections/CollectionView.tsx b/src/client/views/collections/CollectionView.tsx index fb60265e3..65188e6f3 100644 --- a/src/client/views/collections/CollectionView.tsx +++ b/src/client/views/collections/CollectionView.tsx @@ -25,7 +25,7 @@ import { CollectionDockingView } from "./CollectionDockingView"; import { CollectionFreeFormView } from './collectionFreeForm/CollectionFreeFormView'; import { CollectionGridView } from './collectionGrid/CollectionGridView'; import { CollectionLinearView } from './CollectionLinearView'; -import CollectionMapView from './CollectionMapView'; +import CollectionMapView from './MapView/CollectionMapView'; import { CollectionMulticolumnView } from './collectionMulticolumn/CollectionMulticolumnView'; import { CollectionMultirowView } from './collectionMulticolumn/CollectionMultirowView'; import { CollectionPileView } from './CollectionPileView'; diff --git a/src/client/views/collections/MapView/CollectionMapView.scss b/src/client/views/collections/MapView/CollectionMapView.scss new file mode 100644 index 000000000..c76f1d4b9 --- /dev/null +++ b/src/client/views/collections/MapView/CollectionMapView.scss @@ -0,0 +1,50 @@ +.collectionMapView { + width: 100%; + height: 100%; + overflow: hidden; + + .collectionMapView-contents { + width: 100%; + height: 100%; + overflow: hidden; + > div { + position: unset !important; // when the sidebar filter flys out, this prevents the map from extending outside the document box + } + + .map-wrapper { + .searchbox { + box-sizing: border-box; + border: 1px solid transparent; + width: 240px; + height: 32px; + padding: 0 12px; + border-radius: 3px; + box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3); + font-size: 14px; + outline: none; + text-overflow: ellipses; + position: absolute; + left: 50%; + margin-left: -120px; + } + } + } +} + +.loadingWrapper { + width: 100%; + height: 100%; + background-color: pink; + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + text-align: center; + + .loadingGif { + align-self: center; + justify-self: center; + width: 50px; + height: 50px; + } +} diff --git a/src/client/views/collections/MapView/CollectionMapView.tsx b/src/client/views/collections/MapView/CollectionMapView.tsx new file mode 100644 index 000000000..b3a5bdbff --- /dev/null +++ b/src/client/views/collections/MapView/CollectionMapView.tsx @@ -0,0 +1,312 @@ +import { GoogleMap, Marker, InfoWindow, InfoBox, LoadScript, GoogleMapProps, StandaloneSearchBox, DrawingManager } from '@react-google-maps/api'; +import { observable, action, computed, Lambda, runInAction } from "mobx"; +import { observer } from "mobx-react"; +import { Doc, DocListCast, Field, FieldResult, Opt } from "../../../../fields/Doc"; +import { documentSchema } from "../../../../fields/documentSchemas"; +import { Id } from "../../../../fields/FieldSymbols"; +import { makeInterface } from "../../../../fields/Schema"; +import { Cast, NumCast, ScriptCast, StrCast } from "../../../../fields/Types"; +import { LinkManager } from "../../../util/LinkManager"; +import { undoBatch, UndoManager } from "../../../util/UndoManager"; +import "./CollectionMapView.scss"; +import { CollectionSubView } from "../CollectionSubView"; +import React = require("react"); +import requestPromise = require("request-promise"); +import ReactDOM from 'react-dom'; + + +type MapSchema = makeInterface<[typeof documentSchema]>; +const MapSchema = makeInterface(documentSchema); + +export type LocationData = { + id?: number; + pos?: { lat: number, lng: number }; +}; + +const mapContainerStyle = { + height: '100%', +}; + +const defaultCenter = { + lat: 38.685, + lng: -115.234, +}; + +@observer +export default class CollectionMapView extends CollectionSubView(MapSchema) { + + @observable private mapRef = null as any; + @observable private selectedPlace: LocationData = { id: undefined, pos: undefined }; + @observable private markerMap = {}; + @observable private center = defaultCenter; + @observable private zoom = 2.5; + @observable private clickedLatLng = null; + @observable private infoWindowOpen = false; + + @observable private myPlaces = [ + { id: 1, pos: { lat: 39.09366509575983, lng: -94.58751660204751 } }, + { id: 2, pos: { lat: 41.82399, lng: -71.41283 } }, + { id: 3, pos: { lat: 47.606214, lng: -122.33207 } }, + { id: 4, pos: { lat: 36.7783, lng: 119.4179 } } + ]; + + // iterate myPlaces to size, center, and zoom map to contain all markers + private fitBounds = (map: any) => { + const bounds = new window.google.maps.LatLngBounds(); + console.log('map bound is:' + bounds); + this.myPlaces.map(place => { + bounds.extend(place.pos); + return place.id; + }); + map.fitBounds(bounds) + } + + // store a reference to google map instance; fit map bounds to contain all markers + @action + private loadHandler = (map: any) => { + this.mapRef = map; + this.fitBounds(map); + + // //add a custom control for button add marker + // //TODO: why this doesn't work + // const google = window.google; + // console.log("google window: " + google) + // const controlButtonDiv = document.createElement('div'); + // ReactDOM.render(, controlButtonDiv); + // map.controls[google.maps.ControlPosition.TOP_RIGHT].push(controlButtonDiv); + } + + @action + private markerClickHandler = (e: MouseEvent, place: LocationData) => { + // set which place was clicked + this.selectedPlace = place + + console.log(this.selectedPlace.id); + console.log(this.selectedPlace.pos); + + // used so clicking a second marker works + if (this.infoWindowOpen) { + this.infoWindowOpen = false; + } + + this.infoWindowOpen = true; + } + + @action + private handleInfoWindowClose = () => { + if (this.infoWindowOpen) { + this.infoWindowOpen = false; + } + this.infoWindowOpen = false; + this.selectedPlace = { id: undefined, pos: undefined }; + } + + // @action + // private markerLoadHandler = (marker: any, place: LocationData) => { + // if (marker != null) { + // this.markerMap[place.id] = marker; + // } + // } + + @action + @undoBatch + private handleDragMarker = (marker: any, place: LocationData) => { + if (marker != null) { + place = { + id: place.id, + pos: { + lat: marker.latLng.lat().toFixed(3), + lng: marker.latLng.lng().toFixed(3) + } + } + + console.log(place); + console.log(this.myPlaces); + } + } + + /** + * func that handles user's search location and zoom/pan on the input location + */ + private searchLocation = () => { + + } + + /** + * func that adds marker to google maps + */ + @undoBatch + private addMarker = () => { + + } + + /** + * func that updates suggested results (and auto-complete) during user input + */ + private handleChange = () => { + + } + + // private mapRef = document.getElementById("map") + // private markers: google.maps.Marker[] = []; + @observable private input: HTMLInputElement | undefined; + + @action + private setInputRef = (element: HTMLInputElement) => { + this.input = element; + console.log("htmlinputelement is:" + this.input) + } + // private searchBox = new window.google.maps.places.SearchBox(this.input); + + private handlePlacesChanged = () => { + const searchBox = new window.google.maps.places.SearchBox(this.input!) + const places = searchBox.getPlaces(); + + console.log(places); + + if (places.length == 0) { return; } + + // // clear out old markers + // this.markers.forEach((marker) => { + // marker.setMap(null); + // }); + // this.markers = [] + + // // for each place, get icon, name, location + const bounds = new window.google.maps.LatLngBounds(); + places.forEach((place) => { + if (!place.geometry || !place.geometry.location) { + console.log("Returned place contains no geometry"); + return; + } + + // const icon = { + // url: place.icon as string, + // size: new google.maps.Size(71, 71), + // origin: new google.maps.Point(0, 0), + // anchor: new google.maps.Point(17, 34), + // scaledSize: new google.maps.Size(25, 25), + // } + + // //create a marker for each place + // this.markers.push( + // new google.maps.Marker({ + // mapRef, + // title: place.name, + // position: place.geometry.location, + // }) + // ); + + if (place.geometry.viewport) { + // only geocodes have viewport + bounds.union(place.geometry.viewport); + } + else { + bounds.extend(place.geometry.location); + } + }); + } + + // private setBounds = () => { + // const places = this.searchBox.getPlaces(); + // if (places.length == 0) { return; } + + // const bounds = new google.maps.LatLngBounds(); + // places.forEach((place) => { + // if (!place.geometry || !place.geometry.location) { + // console.log("Returned place contains no geometry"); + // return; + // } + + // if (place.geometry.viewport) { + // // only geocodes have viewport + // bounds.union(place.geometry.viewport); + // } + // else { + // bounds.extend(place.geometry.location); + // } + // }); + + // return bounds + // } + + private onPolygonComplete = (polygon: any) => { + console.log(polygon) + } + + private onMarkerComplete = (marker: any) => { + this.myPlaces.push(marker) + } + + render() { + const { Document, fieldKey, isContentActive: active } = this.props; + + return
+ +
e.stopPropagation()} + onPointerDown={e => (e.button === 0 && !e.ctrlKey) && e.stopPropagation()} > + +
+ this.loadHandler(map)} + > + + + + + {this.myPlaces.map(place => ( + this.markerLoadHandler(marker, place)} + onClick={e => this.markerClickHandler(e, place)} + draggable={true} + onDragEnd={marker => this.handleDragMarker(marker, place)} + /> + ))} + {this.infoWindowOpen && this.selectedPlace && ( + + + + )} + {/* */} + +
+
+
+
; + } + +} \ No newline at end of file diff --git a/src/client/views/nodes/PresBox.tsx b/src/client/views/nodes/PresBox.tsx index f3fb6ff17..693348613 100644 --- a/src/client/views/nodes/PresBox.tsx +++ b/src/client/views/nodes/PresBox.tsx @@ -80,7 +80,12 @@ const PresBoxDocument = makeInterface(documentSchema); @observer export class PresBox extends ViewBoxBaseComponent(PresBoxDocument) { public static LayoutString(fieldKey: string) { return FieldView.LayoutString(PresBox, fieldKey); } - + + /** + * transitions & effects for documents + * @param renderDoc + * @param layoutDoc + */ static renderEffectsDoc(renderDoc: any, layoutDoc: Doc) { const effectProps = { left: layoutDoc.presEffectDirection === PresEffect.Left, @@ -258,6 +263,7 @@ export class PresBox extends ViewBoxBaseComponent } } + //TODO: al: it seems currently that tempMedia doesn't stop onslidechange after clicking the button; the time the tempmedia stop depends on the start & end time // No more frames in current doc and next slide is defined, therefore move to next slide nextSlide = (activeNext: Doc) => { const targetNext = Cast(activeNext.presentationTargetDoc, Doc, null); @@ -453,7 +459,7 @@ export class PresBox extends ViewBoxBaseComponent /** * Uses the viewfinder to progressivize through the different views of a single collection. - * @param presTargetDoc: document for which internal zoom is used + * @param activeItem: document for which internal zoom is used */ zoomProgressivizeNext = (activeItem: Doc) => { const targetDoc: Doc = this.targetDoc; @@ -569,6 +575,7 @@ export class PresBox extends ViewBoxBaseComponent load(); } + // The function pauses the auto presentation @action pauseAutoPres = () => { if (this.layoutDoc.presStatus === PresStatus.Autoplay) { @@ -592,6 +599,7 @@ export class PresBox extends ViewBoxBaseComponent }); } + // The function allows for viewing the pres path on toggle @action togglePath = (srcContext: Doc, off?: boolean) => { if (off) { this._pathBoolean = false; @@ -602,6 +610,7 @@ export class PresBox extends ViewBoxBaseComponent } } + // The function allows for expanding the view of pres on toggle @action toggleExpandMode = () => { runInAction(() => this._expandBoolean = !this._expandBoolean); this.rootDoc.expandBoolean = this._expandBoolean; diff --git a/src/client/views/presentationview/PresElementBox.tsx b/src/client/views/presentationview/PresElementBox.tsx index f15d51764..19893af7e 100644 --- a/src/client/views/presentationview/PresElementBox.tsx +++ b/src/client/views/presentationview/PresElementBox.tsx @@ -164,6 +164,9 @@ export class PresElementBox extends ViewBoxBaseComponent { const miniView: boolean = this.toolbarWidth <= 100; const activeItem = this.rootDoc; @@ -242,6 +245,7 @@ export class PresElementBox extends ViewBoxBaseComponent { -- cgit v1.2.3-70-g09d2 From 89ae6933ed13209497151c6a09bc88f600c53a57 Mon Sep 17 00:00:00 2001 From: Aubrey-Li <63608597+Aubrey-Li@users.noreply.github.com> Date: Mon, 5 Jul 2021 16:40:34 -0700 Subject: zoom & pan onSearch --- .../collections/MapView/CollectionMapView.tsx | 45 +++++++++++----------- 1 file changed, 23 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/client/views/collections/MapView/CollectionMapView.tsx b/src/client/views/collections/MapView/CollectionMapView.tsx index b3a5bdbff..42059b61c 100644 --- a/src/client/views/collections/MapView/CollectionMapView.tsx +++ b/src/client/views/collections/MapView/CollectionMapView.tsx @@ -149,18 +149,21 @@ export default class CollectionMapView extends CollectionSubView(); - @action - private setInputRef = (element: HTMLInputElement) => { - this.input = element; - console.log("htmlinputelement is:" + this.input) - } - // private searchBox = new window.google.maps.places.SearchBox(this.input); + // @action + // private setInputRef = (element: HTMLInputElement) => { + // if (this.inputRef.current) { + // this.inputRef! = element; + // console.log("htmlinputelement is:" + this.inputRef) + // } + // } + + @observable private searchBox = new window.google.maps.places.SearchBox(this.inputRef.current!); private handlePlacesChanged = () => { - const searchBox = new window.google.maps.places.SearchBox(this.input!) - const places = searchBox.getPlaces(); + console.log(this.searchBox); + const places = this.searchBox.getPlaces(); console.log(places); @@ -207,6 +210,14 @@ export default class CollectionMapView extends CollectionSubView { + this.searchBox.setBounds(this.mapRef.getBounds()) + } + + private onCenterChanged = () => { + + } + // private setBounds = () => { // const places = this.searchBox.getPlaces(); // if (places.length == 0) { return; } @@ -230,14 +241,6 @@ export default class CollectionMapView extends CollectionSubView { - console.log(polygon) - } - - private onMarkerComplete = (marker: any) => { - this.myPlaces.push(marker) - } - render() { const { Document, fieldKey, isContentActive: active } = this.props; @@ -257,10 +260,12 @@ export default class CollectionMapView extends CollectionSubView this.loadHandler(map)} + onBoundsChanged={this.onBoundsChanged} + onCenterChanged={this.onCenterChanged} > - + {this.myPlaces.map(place => ( @@ -298,10 +303,6 @@ export default class CollectionMapView extends CollectionSubView )} - {/* */} -- cgit v1.2.3-70-g09d2 From 5f3486d68dd6a6c2b13acf7127188220a4012290 Mon Sep 17 00:00:00 2001 From: Aubrey-Li <63608597+Aubrey-Li@users.noreply.github.com> Date: Tue, 6 Jul 2021 19:50:08 -0700 Subject: fix link to map; ownerdocument error --- deploy/index.html | 1 + package-lock.json | 321 +++++++++++++++++++++ package.json | 1 + .../collections/MapView/CollectionMapView.tsx | 206 +++++++------ 4 files changed, 422 insertions(+), 107 deletions(-) (limited to 'src') diff --git a/deploy/index.html b/deploy/index.html index dda0c6457..33cc0906a 100644 --- a/deploy/index.html +++ b/deploy/index.html @@ -7,6 +7,7 @@ + - + - + -