aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBob Zeleznik <zzzman@gmail.com>2020-04-13 18:45:52 -0400
committerBob Zeleznik <zzzman@gmail.com>2020-04-13 18:45:52 -0400
commit78986ae808dc9bbb5763e3f74097b7a1bc61f49a (patch)
treebfcab7269b137699d8c1d1d298e6835c8ed76171 /src
parent87268612b9b765d74f1a5317b0894be0ceb1dfd1 (diff)
more mapview adjustments
Diffstat (limited to 'src')
-rw-r--r--src/client/documents/Documents.ts4
-rw-r--r--src/client/views/PreviewCursor.tsx2
-rw-r--r--src/client/views/collections/CollectionMapView.scss3
-rw-r--r--src/client/views/collections/CollectionMapView.tsx104
4 files changed, 69 insertions, 44 deletions
diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts
index 3f46c4013..e6f3b21ca 100644
--- a/src/client/documents/Documents.ts
+++ b/src/client/documents/Documents.ts
@@ -49,10 +49,6 @@ import { ContextMenuProps } from "../views/ContextMenuItem";
import { ContextMenu } from "../views/ContextMenu";
import { LinkBox } from "../views/nodes/LinkBox";
import { ScreenshotBox } from "../views/nodes/ScreenshotBox";
-import CollectionMapView from "../views/collections/CollectionMapView";
-import LocationField, { LocationData } from "../../new_fields/LocationField";
-import { action } from "mobx";
-const requestImageSize = require('../util/request-image-size');
const path = require('path');
export interface DocumentOptions {
diff --git a/src/client/views/PreviewCursor.tsx b/src/client/views/PreviewCursor.tsx
index 92ba13d2f..df30c1215 100644
--- a/src/client/views/PreviewCursor.tsx
+++ b/src/client/views/PreviewCursor.tsx
@@ -113,7 +113,7 @@ export class PreviewCursor extends React.Component<{}> {
addLiveText: (doc: Doc) => void,
getTransform: () => Transform,
addDocument: (doc: Doc) => boolean,
- nudge: (nudgeX: number, nudgeY: number) => void) {
+ nudge: (nudgeX: number, nudgeY: number) => boolean) {
this._clickPoint = [x, y];
this._onKeyPress = onKeyPress;
this._addLiveTextDoc = addLiveText;
diff --git a/src/client/views/collections/CollectionMapView.scss b/src/client/views/collections/CollectionMapView.scss
index df7853da6..c74433902 100644
--- a/src/client/views/collections/CollectionMapView.scss
+++ b/src/client/views/collections/CollectionMapView.scss
@@ -1,7 +1,4 @@
.collectionMapView-contents {
width: 100%;
height: 100%;
-}
-.collectionMapView-contents-none {
- pointer-events: none;
} \ No newline at end of file
diff --git a/src/client/views/collections/CollectionMapView.tsx b/src/client/views/collections/CollectionMapView.tsx
index 5075bbf7a..569f8ba7a 100644
--- a/src/client/views/collections/CollectionMapView.tsx
+++ b/src/client/views/collections/CollectionMapView.tsx
@@ -1,13 +1,20 @@
+import { GoogleApiWrapper, Map, MapProps, Marker } from "google-maps-react";
import { observer } from "mobx-react";
-import { makeInterface } from "../../../new_fields/Schema";
+import { Doc, Opt, DocListCast } from "../../../new_fields/Doc";
import { documentSchema } from "../../../new_fields/documentSchemas";
-import React = require("react");
-import { Map, Marker, MapProps, GoogleApiWrapper } from "google-maps-react";
-import { NumCast, StrCast } from "../../../new_fields/Types";
-import { CollectionSubView } from "./CollectionSubView";
-import { Utils } from "../../../Utils";
-import { Opt } from "../../../new_fields/Doc";
+import { Id } from "../../../new_fields/FieldSymbols";
+import { makeInterface } from "../../../new_fields/Schema";
+import { Cast, NumCast, ScriptCast, StrCast } from "../../../new_fields/Types";
+import { TraceMobx } from "../../../new_fields/util";
import "./CollectionMapView.scss";
+import { CollectionSubView } from "./CollectionSubView";
+import React = require("react");
+import { DocumentManager } from "../../util/DocumentManager";
+import { UndoManager } from "../../util/UndoManager";
+import { returnTrue } from "../../../Utils";
+import { CancellationError } from "bluebird";
+import { ln } from "shelljs";
+import { dfareporting } from "googleapis/build/src/apis/dfareporting";
type MapDocument = makeInterface<[typeof documentSchema]>;
const MapDocument = makeInterface(documentSchema);
@@ -17,28 +24,65 @@ export type LocationData = google.maps.LatLngLiteral & { address?: string };
@observer
class CollectionMapView extends CollectionSubView<MapDocument, Partial<MapProps> & { google: any }>(MapDocument) {
+ getLocation = (doc: Opt<Doc>, fieldKey: string, defaultLocation?: LocationData) => {
+ if (doc) {
+ let lat: Opt<number> = Cast(doc[fieldKey + "-lat"], "number", null);
+ let lng: Opt<number> = Cast(doc[fieldKey + "-lng"], "number", null);
+ const address = Cast(doc[fieldKey + "-address"], "string", null);
+ if (address) {
+ // use geo service to convert to lat/lng
+ lat = lat;
+ lng = lng;
+ }
+ if (lat === undefined) lat = defaultLocation?.lat;
+ if (lng === undefined) lng = defaultLocation?.lng;
+ return ({ lat, lng });
+ }
+ return ({ lat: 35.1592238, lng: -98.4466577 });
+ }
+ renderMarker(layout: Doc, icon: Opt<google.maps.Icon>) {
+ const location = this.getLocation(layout, "location");
+ return location.lat === undefined || location.lng === undefined ? (null) :
+ <Marker
+ key={layout[Id]}
+ label={StrCast(layout.title)}
+ position={{ lat: location.lat, lng: location.lng }}
+ onClick={async () => {
+ this.props.Document.mapCenterLat = location.lat;
+ this.props.Document.mapCenterLng = location.lng;
+ if (layout.isLinkButton && DocListCast(layout.links).length) {
+ const batch = UndoManager.StartBatch("follow link click");
+ await DocumentManager.Instance.FollowLink(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 });
+ }
+ }}
+ icon={icon}
+ />;
+ }
render() {
- const { childLayoutPairs, props } = this;
- const { Document } = props;
- const center: LocationData = { lat: NumCast(Document.mapCenterLat), lng: NumCast(Document.mapCenterLng) };
- if (!center.lat) {
- center.lat = childLayoutPairs.length ? NumCast(childLayoutPairs[0].layout.locationLat, 0) : 0;
- center.lng = childLayoutPairs.length ? NumCast(childLayoutPairs[0].layout.locationLng, 0) : 0;
+ const { childLayoutPairs } = this;
+ const { Document } = this.props;
+ let center = this.getLocation(Document, this.props.fieldKey + "-mapCenter");
+ if (center.lat === undefined) {
+ center = this.getLocation(childLayoutPairs.map(pair => pair.layout).find(returnTrue), "location", { lat: 35.1592238, lng: -98.4466577 });
}
- return (
- <div className={"collectionMapView-contents" + (this.props.active() ? "" : "-none")}
- onPointerDown={e => (this.props.active() && e.button === 0 && !e.ctrlKey) && e.stopPropagation()} >
+ TraceMobx();
+ return center.lat === undefined || center.lng === undefined ? (null) :
+ <div className={"collectionMapView-contents"}
+ style={{ pointerEvents: this.props.active() ? undefined : "none" }}
+ onWheel={e => e.stopPropagation()}
+ onPointerDown={e => (e.button === 0 && !e.ctrlKey) && e.stopPropagation()} >
<Map
google={this.props.google}
zoom={NumCast(Document.zoom, 10)}
- center={center}
- initialCenter={center}
+ center={{ lat: center.lat, lng: center.lng }}
+ initialCenter={{ lat: center.lat, lng: center.lng }}
>
{childLayoutPairs.map(({ layout }) => {
- const location: LocationData = {
- lat: NumCast(childLayoutPairs[0].layout.locationLat, 0),
- lng: NumCast(childLayoutPairs[0].layout.locationLng, 0)
- };
let icon: Opt<google.maps.Icon>, iconUrl: Opt<string>;
if ((iconUrl = StrCast(Document.mapIconUrl, null))) {
const iconSize = new google.maps.Size(NumCast(layout.mapIconWidth, 45), NumCast(layout.mapIconHeight, 45));
@@ -48,22 +92,10 @@ class CollectionMapView extends CollectionSubView<MapDocument, Partial<MapProps>
url: iconUrl
};
}
- return (
- <Marker
- key={Utils.GenerateGuid()}
- label={StrCast(layout.title)}
- position={location}
- onClick={() => {
- Document.mapCenterLat = location.lat;
- Document.mapCenterLng = location.lng;
- }}
- icon={icon}
- />
- );
+ return this.renderMarker(layout, icon);
})}
</Map>
- </div>
- );
+ </div>;
}
}