aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client/documents/DocumentTypes.ts71
-rw-r--r--src/client/documents/Documents.ts25
-rw-r--r--src/client/util/CurrentUserUtils.ts16
-rw-r--r--src/client/util/type_decls.d1
-rw-r--r--src/client/views/MainView.tsx2
-rw-r--r--src/client/views/collections/CollectionMapView.tsx269
-rw-r--r--src/client/views/collections/CollectionView.tsx2
-rw-r--r--src/client/views/collections/MapView/CollectionMapView.scss (renamed from src/client/views/collections/CollectionMapView.scss)22
-rw-r--r--src/client/views/collections/MapView/CollectionMapView.tsx273
-rw-r--r--src/client/views/nodes/DocumentContentsView.tsx3
-rw-r--r--src/client/views/nodes/MapBox/MapBox.scss32
-rw-r--r--src/client/views/nodes/MapBox/MapBox.tsx374
-rw-r--r--src/client/views/nodes/MapMarker/MapMarker.tsx23
-rw-r--r--src/client/views/nodes/PresBox.tsx14
-rw-r--r--src/client/views/presentationview/PresElementBox.tsx4
-rw-r--r--src/client/views/search/IconButton.tsx1
-rw-r--r--src/fields/Doc.ts4
-rw-r--r--src/fields/URLField.ts1
-rw-r--r--src/fields/documentSchemas.ts2
-rw-r--r--src/server/ApiManagers/DownloadManager.ts2
-rw-r--r--src/server/ApiManagers/SearchManager.ts1
-rw-r--r--src/server/GarbageCollector.ts2
-rw-r--r--src/server/remapUrl.ts3
-rw-r--r--src/server/updateProtos.ts2
-rw-r--r--src/server/websocket.ts1
25 files changed, 827 insertions, 323 deletions
diff --git a/src/client/documents/DocumentTypes.ts b/src/client/documents/DocumentTypes.ts
index 8565784b4..5bd5590b7 100644
--- a/src/client/documents/DocumentTypes.ts
+++ b/src/client/documents/DocumentTypes.ts
@@ -2,44 +2,47 @@ export enum DocumentType {
NONE = "none",
// core data types
- RTF = "rtf", // rich text
- IMG = "image", // image box
- WEB = "web", // web page or html clipping
- COL = "collection", // collection
- KVP = "kvp", // key value pane
- VID = "video", // video
- AUDIO = "audio", // audio
- PDF = "pdf", // pdf
- INK = "inks", // ink stroke
- SCREENSHOT = "screenshot", // view of a desktop application
- FONTICON = "fonticonbox", // font icon
+ RTF = "rtf",
+ IMG = "image",
+ WEB = "web",
+ COL = "collection",
+ KVP = "kvp",
+ VID = "video",
+ AUDIO = "audio",
+ PDF = "pdf",
+ INK = "inks",
+ SCREENSHOT = "screenshot",
+ FONTICON = "fonticonbox",
FILTER = "filter",
- SEARCH = "search", // search query
- LABEL = "label", // simple text label
- BUTTON = "button", // onClick button
- WEBCAM = "webcam", // webcam
- HTMLANCHOR = "htmlanchor", // text selection anchor in PDF/Web
- DATE = "date", // calendar view of a date
- SCRIPTING = "script", // script editor
- EQUATION = "equation", // equation editor
- FUNCPLOT = "funcplot", // function plotter
+ SEARCH = "search",
+ LABEL = "label",
+ BUTTON = "button",
+ WEBCAM = "webcam",
+ HTMLANCHOR = "htmlanchor",
+ DATE = "date",
+ SCRIPTING = "script",
+ EQUATION = "equation",
+ FUNCPLOT = "funcplot",
+ MAP = "map",
+
// special purpose wrappers that either take no data or are compositions of lower level types
- LINK = "link", // link (view of a document that acts as a link)
- LINKANCHOR = "linkanchor", // blue dot link anchor (view of a link document's anchor)
- IMPORT = "import", // directory import box (file system directory)
- SLIDER = "slider", // number slider (view of a number)
- PRES = "presentation", // presentation (view of a collection) --- shouldn't this be a view type? technically requires a special view in which documents must have their aliasOf fields filled in
- PRESELEMENT = "preselement",// presentation item (view of a document in a collection)
- COLOR = "color", // color picker (view of a color picker for a color string)
- YOUTUBE = "youtube", // youtube directory (view of you tube search results)
+ LINK = "link",
+ LINKANCHOR = "linkanchor",
+ IMPORT = "import",
+ SLIDER = "slider",
+ PRES = "presentation",
+ PRESELEMENT = "preselement",
+ COLOR = "color",
+ YOUTUBE = "youtube",
SEARCHITEM = "searchitem",
- COMPARISON = "comparison", // before/after view with slider (view of 2 images)
- GROUP = "group", // group of users
+ COMPARISON = "comparison",
+ GROUP = "group",
- LINKDB = "linkdb", // database of links ??? why do we have this
- SCRIPTDB = "scriptdb", // database of scripts
- GROUPDB = "groupdb", // database of groups
+ LINKDB = "linkdb",
+ SCRIPTDB = "scriptdb",
+ GROUPDB = "groupdb",
- TEXTANCHOR = "textanchor" // selection of text in a text box
+ TEXTANCHOR = "textanchor" // selection of text in a text box
+ ,
} \ No newline at end of file
diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts
index f1db3e32c..eb1bd2058 100644
--- a/src/client/documents/Documents.ts
+++ b/src/client/documents/Documents.ts
@@ -11,7 +11,7 @@ import { RichTextField } from "../../fields/RichTextField";
import { SchemaHeaderField } from "../../fields/SchemaHeaderField";
import { ComputedField, ScriptField } from "../../fields/ScriptField";
import { Cast, NumCast, StrCast } from "../../fields/Types";
-import { AudioField, ImageField, PdfField, VideoField, WebField, YoutubeField } from "../../fields/URLField";
+import { AudioField, ImageField, MapField, PdfField, VideoField, WebField, YoutubeField } from "../../fields/URLField";
import { SharingPermissions } from "../../fields/util";
import { MessageStore } from "../../server/Message";
import { Upload } from "../../server/SharedMediaTypes";
@@ -60,6 +60,7 @@ import { EquationBox } from "../views/nodes/EquationBox";
import { FunctionPlotBox } from "../views/nodes/FunctionPlotBox";
import { CurrentUserUtils } from "../util/CurrentUserUtils";
import { FieldViewProps } from "../views/nodes/FieldView";
+import { MapBox } from "../views/nodes/MapBox/MapBox";
const path = require('path');
const defaultNativeImageDim = Number(DFLT_IMAGE_NATIVE_DIM.replace("px", ""));
@@ -362,6 +363,10 @@ export namespace Docs {
layout: { view: PDFBox, dataField: defaultDataKey },
options: { _curPage: 1, _fitWidth: true, links: ComputedField.MakeFunction("links(self)") as any }
}],
+ [DocumentType.MAP, {
+ layout: { view: MapBox, dataField: defaultDataKey },
+ options: { _height: 600, _width: 800, links: ComputedField.MakeFunction("links(self)") as any }
+ }],
[DocumentType.IMPORT, {
layout: { view: DirectoryImportBox, dataField: defaultDataKey },
options: { _height: 150 }
@@ -797,6 +802,10 @@ export namespace Docs {
return InstanceFromProto(Prototypes.get(DocumentType.WEB), new HtmlField(html), options);
}
+ export function MapDocument(documents: Array<Doc>, options: DocumentOptions = {}) {
+ return InstanceFromProto(Prototypes.get(DocumentType.MAP), new List(documents), options);
+ }
+
export function KVPDocument(document: Doc, options: DocumentOptions = {}) {
return InstanceFromProto(Prototypes.get(DocumentType.KVP), document, { title: document.title + ".kvp", ...options });
}
@@ -822,7 +831,7 @@ export namespace Docs {
return InstanceFromProto(Prototypes.get(DocumentType.COL), new List(documents), { ...options, _viewType: CollectionViewType.Linear }, id);
}
- export function MapDocument(documents: Array<Doc>, options: DocumentOptions = {}) {
+ export function MapCollectionDocument(documents: Array<Doc>, options: DocumentOptions = {}) {
return InstanceFromProto(Prototypes.get(DocumentType.COL), new List(documents), { ...options, _viewType: CollectionViewType.Map });
}
@@ -1148,7 +1157,11 @@ export namespace DocUtils {
} else if (field instanceof List && field[0] instanceof Doc) {
created = Docs.Create.StackingDocument(DocListCast(field), resolved);
layout = CollectionView.LayoutString;
- } else {
+ } else if (field instanceof MapField) {
+ created = Docs.Create.MapDocument(DocListCast(field), resolved);
+ layout = MapBox.LayoutString;
+ }
+ else {
created = Docs.Create.TextDocument("", { ...{ _width: 200, _height: 25, _autoHeight: true }, ...resolved });
layout = FormattedTextBox.LayoutString;
}
@@ -1179,6 +1192,12 @@ export namespace DocUtils {
if (!options._width) options._width = 400;
if (!options._height) options._height = (options._width as number) * 1200 / 927;
}
+ //TODO:al+glr
+ // if (type.indexOf("map") !== -1) {
+ // ctor = Docs.Create.MapDocument;
+ // if (!options._width) options._width = 800;
+ // if (!options._height) options._height = (options._width as number) * 3 / 4;
+ // }
if (type.indexOf("html") !== -1) {
if (path.includes(window.location.hostname)) {
const s = path.split('/');
diff --git a/src/client/util/CurrentUserUtils.ts b/src/client/util/CurrentUserUtils.ts
index 22504f102..adc66c916 100644
--- a/src/client/util/CurrentUserUtils.ts
+++ b/src/client/util/CurrentUserUtils.ts
@@ -1,14 +1,15 @@
-import { computed, observable, reaction, action } from "mobx";
+import { computed, observable, reaction } from "mobx";
import * as rp from 'request-promise';
-import { DataSym, Doc, DocListCast, DocListCastAsync, AclReadonly } from "../../fields/Doc";
+import { DataSym, Doc, DocListCast, DocListCastAsync } from "../../fields/Doc";
import { Id } from "../../fields/FieldSymbols";
+import { InkTool } from "../../fields/InkField";
import { List } from "../../fields/List";
import { PrefetchProxy } from "../../fields/Proxy";
import { RichTextField } from "../../fields/RichTextField";
import { listSpec } from "../../fields/Schema";
import { SchemaHeaderField } from "../../fields/SchemaHeaderField";
import { ComputedField, ScriptField } from "../../fields/ScriptField";
-import { BoolCast, Cast, NumCast, PromiseValue, StrCast, DateCast } from "../../fields/Types";
+import { BoolCast, Cast, DateCast, NumCast, PromiseValue, StrCast } from "../../fields/Types";
import { nullAudio } from "../../fields/URLField";
import { SharingPermissions } from "../../fields/util";
import { Utils } from "../../Utils";
@@ -31,10 +32,8 @@ import { LinkManager } from "./LinkManager";
import { Scripting } from "./Scripting";
import { SearchUtil } from "./SearchUtil";
import { SelectionManager } from "./SelectionManager";
-import { UndoManager } from "./UndoManager";
import { SnappingManager } from "./SnappingManager";
-import { InkTool } from "../../fields/InkField";
-import { computedFn } from "mobx-utils";
+import { UndoManager } from "./UndoManager";
export let resolvedPorts: { server: number, socket: number };
@@ -458,6 +457,10 @@ export class CurrentUserUtils {
if (doc.emptyWebpage === undefined) {
doc.emptyWebpage = Docs.Create.WebDocument("", { title: "webpage", _nativeWidth: 850, isTemplateDoc: true, _height: 512, _width: 400, useCors: true, system: true, cloneFieldFilter: new List<string>(["system"]) });
}
+ if (doc.emptyMap === undefined) {
+ doc.emptyMap = Docs.Create.MapDocument([], { title: "map", _width: 800, _height: 600, system: true, cloneFieldFilter: new List<string>(["system"]) });
+ ((doc.emptyMap as Doc).proto as Doc)["dragFactory-count"] = 0;
+ }
if (doc.activeMobileMenu === undefined) {
this.setupActiveMobileMenu(doc);
}
@@ -477,6 +480,7 @@ export class CurrentUserUtils {
{ toolTip: "Tap to create a mobile view in a new pane, drag for a mobile view", title: "Phone", icon: "mobile", click: 'openOnRight(Doc.UserDoc().activeMobileMenu)', drag: 'this.dragFactory', dragFactory: doc.activeMobileMenu as Doc },
{ toolTip: "Tap to create a custom header note document, drag for a custom header note", title: "Custom", icon: "window-maximize", click: 'openOnRight(delegateDragFactory(this.dragFactory))', drag: 'delegateDragFactory(this.dragFactory)', dragFactory: doc.emptyHeader as Doc },
{ toolTip: "Toggle a Calculator REPL", title: "repl", icon: "calculator", click: 'addOverlayWindow("ScriptingRepl", { x: 300, y: 100, width: 200, height: 200, title: "Scripting REPL" })' },
+ { toolTip: "Tap to create a map in the new pane, drag for a map", title: "Map", icon: "map-marker-alt", click: 'openOnRight(copyDragFactory(this.dragFactory))', drag: 'copyDragFactory(this.dragFactory)', dragFactory: doc.emptyMap as Doc, noviceMode: true }
];
}
diff --git a/src/client/util/type_decls.d b/src/client/util/type_decls.d
index ac0bea46a..9063dc894 100644
--- a/src/client/util/type_decls.d
+++ b/src/client/util/type_decls.d
@@ -208,6 +208,7 @@ declare const Docs: {
PdfDocument(url: string, options?: DocumentOptions): Doc;
WebDocument(url: string, options?: DocumentOptions): Doc;
HtmlDocument(html: string, options?: DocumentOptions): Doc;
+ MapDocument(url: string, options?: DocumentOptions): Doc;
KVPDocument(document: Doc, options?: DocumentOptions): Doc;
FreeformDocument(documents: Doc[], options?: DocumentOptions): Doc;
SchemaDocument(columns: string[], documents: Doc[], options?: DocumentOptions): Doc;
diff --git a/src/client/views/MainView.tsx b/src/client/views/MainView.tsx
index f34851b00..836b8130b 100644
--- a/src/client/views/MainView.tsx
+++ b/src/client/views/MainView.tsx
@@ -169,7 +169,7 @@ export class MainView extends React.Component {
fa.faArrowAltCircleDown, fa.faArrowAltCircleUp, fa.faArrowAltCircleLeft, fa.faArrowAltCircleRight, fa.faStopCircle, fa.faCheckCircle, fa.faGripVertical,
fa.faSortUp, fa.faSortDown, fa.faTable, fa.faTh, fa.faThList, fa.faProjectDiagram, fa.faSignature, fa.faColumns, fa.faChevronCircleUp, fa.faUpload, fa.faBorderAll,
fa.faBraille, fa.faChalkboard, fa.faPencilAlt, fa.faEyeSlash, fa.faSmile, fa.faIndent, fa.faOutdent, fa.faChartBar, fa.faBan, fa.faPhoneSlash, fa.faGripLines,
- fa.faSave, fa.faBookmark);
+ fa.faSave, fa.faBookmark, fa.faMapMarkedAlt);
this.initAuthenticationRouters();
}
diff --git a/src/client/views/collections/CollectionMapView.tsx b/src/client/views/collections/CollectionMapView.tsx
deleted file mode 100644
index 2d7569d45..000000000
--- a/src/client/views/collections/CollectionMapView.tsx
+++ /dev/null
@@ -1,269 +0,0 @@
-import { GoogleApiWrapper, IMapProps, Map as GeoMap, Marker } from "google-maps-react";
-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;
-};
-
-interface DocLatLng {
- lat: FieldResult<Field>;
- lng: FieldResult<Field>;
-}
-
-// 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;
- }
-};
-
-@observer
-export class CollectionMapView extends CollectionSubView<MapSchema, Partial<IMapProps> & { google: any }>(MapSchema) {
-
- private _cancelAddrReq = new Map<string, boolean>();
- private _cancelLocReq = new Map<string, boolean>();
- private _initialLookupPending = new Map<string, boolean>();
- 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<Doc>, fieldKey: string, returnDefault: boolean = true): Opt<LocationData> => {
- 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;
- }
-
- 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();
- }
- }
-
- 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) :
- <Marker
- key={layout[Id]}
- label={StrCast(layout[`${this.props.fieldKey}-address`])}
- position={location}
- onClick={() => this.markerClick(layout, location)}
- icon={this.renderMarkerIcon(layout)}
- />;
- }
-
- 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;
- }
-
- private respondToLocationChange = async (doc: Doc, fieldKey: string, newLatLng: DocLatLng, oldLatLng: Opt<DocLatLng>) => {
- 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;
- }
-
- @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 <div className="collectionMapView" ref={this.createDashEventsTarget}>
- <div className={"collectionMapView-contents"}
- style={{ pointerEvents: active() ? undefined : "none" }}
- onWheel={e => e.stopPropagation()}
- onPointerDown={e => (e.button === 0 && !e.ctrlKey) && e.stopPropagation()} >
- <GeoMap
- google={google}
- zoom={center.zoom || 10}
- initialCenter={center}
- center={center}
- onIdle={(_props?: IMapProps, map?: google.maps.Map) => {
- 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());
- }
- }}
- >
- {this.reactiveContents}
- {mapLoc && StrCast(this.rootDoc[`${fieldKey}-mapCenter-address`]) ? this.renderMarker(this.rootDoc, `${fieldKey}-mapCenter`) : undefined}
- </GeoMap>
- </div>
- </div>;
- }
-
-}
-
-export default GoogleApiWrapper({
- apiKey: process.env.GOOGLE_MAPS!,
- LoadingContainer: () => {
- console.log(process.env.GOOGLE_MAPS);
- return <div className={"loadingWrapper"}>
- <img className={"loadingGif"} src={"/assets/loading.gif"} />
- </div>;
- }
-})(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 e225c4a11..a9be48278 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/CollectionMapView.scss b/src/client/views/collections/MapView/CollectionMapView.scss
index 870b7fda8..6ad0f3a92 100644
--- a/src/client/views/collections/CollectionMapView.scss
+++ b/src/client/views/collections/MapView/CollectionMapView.scss
@@ -1,13 +1,33 @@
.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: 300px;
+ 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;
+ }
+ }
}
}
@@ -27,4 +47,4 @@
width: 50px;
height: 50px;
}
-} \ No newline at end of file
+}
diff --git a/src/client/views/collections/MapView/CollectionMapView.tsx b/src/client/views/collections/MapView/CollectionMapView.tsx
new file mode 100644
index 000000000..d7025f6da
--- /dev/null
+++ b/src/client/views/collections/MapView/CollectionMapView.tsx
@@ -0,0 +1,273 @@
+import { GoogleMap, Marker, InfoWindow, InfoBox, useJsApiLoader, LoadScript, GoogleMapProps, StandaloneSearchBox, Autocomplete } from '@react-google-maps/api';
+import { observable, action, computed, Lambda, runInAction, IReactionDisposer } 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';
+import { DragManager } from '../../../util/DragManager';
+import { MapMarker } from '../../nodes/MapMarker/MapMarker';
+
+
+/**
+ * Idea behind storing a marker:
+ * 1. on the map api, have a button "add marker" that adds the marker on the map & store the marker as a node in the collection
+ * (but don't render the marker in the collection itself)
+ * 2. each marker, as a node, has the same feature as all other nodes for linking (the same way one could form a link between a node inside a child collection
+ * and a node outside the child collection)
+ *
+ * /util/LinkManager.ts -- link relations
+ *
+ */
+
+type MapSchema = makeInterface<[typeof documentSchema]>;
+const MapSchema = makeInterface(documentSchema);
+
+export type Coordinates = {
+ lat: number,
+ lng: number,
+}
+
+export type LocationData = {
+ id: string;
+ pos: Coordinates;
+};
+
+const mapContainerStyle = {
+ height: '100%',
+};
+
+const defaultCenter = {
+ lat: 38.685,
+ lng: -115.234,
+};
+
+const mapOptions = {
+ fullscreenControl: false,
+}
+
+const drawingManager = new google.maps.drawing.DrawingManager({
+ drawingControl: true,
+ drawingControlOptions: {
+ position: google.maps.ControlPosition.TOP_RIGHT,
+ drawingModes: [
+ google.maps.drawing.OverlayType.MARKER,
+ google.maps.drawing.OverlayType.CIRCLE,
+ google.maps.drawing.OverlayType.POLYLINE,
+ ],
+ },
+});
+
+const options = {
+ fields: ["formatted_address", "geometry", "name"], // note: level of details is charged by item per retrieval, not recommended to return all fields
+ strictBounds: false,
+ types: ["establishment"], // type pf places, subject of change according to user need
+} as google.maps.places.AutocompleteOptions;
+
+@observer
+export default class CollectionMapView extends CollectionSubView<MapSchema, Partial<GoogleMapProps>>(MapSchema) {
+ private _dropDisposer?: DragManager.DragDropDisposer;
+ private _disposers: { [name: string]: IReactionDisposer } = {};
+
+
+ @observable private _map = null as unknown as google.maps.Map;
+ @observable private selectedPlace: LocationData | undefined;
+ @observable private markerMap: { [id: string]: google.maps.Marker } = {};
+ @observable private center = defaultCenter;
+ @observable private zoom = 2.5;
+ @observable private clickedLatLng = null;
+ @observable private infoWindowOpen = false;
+ @observable private bounds = new window.google.maps.LatLngBounds();
+ @observable private inputRef = React.createRef<HTMLInputElement>();
+ @observable private buttonRef = React.createRef<HTMLDivElement>();
+ @observable private searchMarkers: google.maps.Marker[] = [];
+ @observable private searchBox = new window.google.maps.places.Autocomplete(this.inputRef.current!, options);
+
+ @observable private myPlaces: LocationData[] = [
+ { id: "id1", pos: { lat: 39.09366509575983, lng: -94.58751660204751 } },
+ { id: "id2", pos: { lat: 41.82399, lng: -71.41283 } },
+ { id: "id3", pos: { lat: 47.606214, lng: -122.33207 } },
+ ];
+
+ @action
+ private setSearchBox = (searchBox: any) => {
+ this.searchBox = searchBox;
+ }
+
+ // iterate myPlaces to size, center, and zoom map to contain all markers
+ private fitBounds = (map: google.maps.Map) => {
+ console.log('map bound is:' + this.bounds);
+ this.myPlaces ? this.myPlaces.map(place => {
+ this.bounds.extend(place.pos!);
+ }) : null;
+ map.fitBounds(this.bounds);
+ }
+
+ // store a reference to google map instance; fit map bounds to contain all markers
+ @action
+ private loadHandler = (map: google.maps.Map) => {
+ this._map = map;
+ drawingManager.setMap(map);
+ this.fitBounds(map);
+ }
+
+ @action
+ private markerClickHandler = (e: MouseEvent, place: any) => {
+ // set which place was clicked
+ this.selectedPlace = place;
+
+ console.log(this.selectedPlace);
+
+ // used so clicking a second marker works
+ if (this.infoWindowOpen) {
+ this.infoWindowOpen = false;
+ console.log("closeinfowindow")
+ }
+ this.infoWindowOpen = true;
+ console.log("open infowindow")
+ }
+
+ @action
+ private handleInfoWindowClose = () => {
+ if (this.infoWindowOpen) {
+ this.infoWindowOpen = false;
+ }
+ this.infoWindowOpen = false;
+ this.selectedPlace = undefined;
+ }
+
+ @action
+ private handlePlaceChanged = () => {
+ console.log(this.searchBox);
+ const place = this.searchBox.getPlace();
+
+ if (!place.geometry || !place.geometry.location) {
+ // user entered the name of a place that wasn't suggested & pressed the enter key, or place details request failed
+ window.alert("No details available for input: '" + place.name + "'");
+ return;
+ }
+
+ // zoom in on the location of the search result
+ if (place.geometry.viewport) {
+ console.log(this._map);
+ this._map.fitBounds(place.geometry.viewport);
+ } else {
+ console.log(this._map);
+ this._map.setCenter(place.geometry.location);
+ this._map.setZoom(17);
+ }
+
+ // customize icon => customized icon for the nature of the location selected
+ 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),
+ };
+
+ // put temporary cutomized marker on searched location
+ this.searchMarkers.forEach((marker) => {
+ marker.setMap(null);
+ });
+ this.searchMarkers = [];
+ this.searchMarkers.push(
+ new window.google.maps.Marker({
+ map: this._map,
+ icon,
+ title: place.name,
+ position: place.geometry.location,
+ })
+ )
+ }
+
+
+ @action
+ private addMarker = (location: google.maps.LatLng | undefined, map: google.maps.Map) => {
+ new window.google.maps.Marker({
+ position: location,
+ map: map
+ });
+ }
+
+ @action
+ private markerLoadHandler = (marker: google.maps.Marker, place: LocationData) => {
+ place.id ? this.markerMap[place.id] = marker : null;
+ }
+
+ render() {
+ const { Document, fieldKey, isContentActive: active } = this.props;
+
+ return <div className="collectionMapView" ref={this.createDashEventsTarget}>
+
+ <div className={"collectionMapView-contents"}
+ style={{ pointerEvents: active() ? undefined : "none", overflow: 'hidden' }}
+ onWheel={e => e.stopPropagation()}
+ onPointerDown={e => (e.button === 0 && !e.ctrlKey) && e.stopPropagation()} >
+ {/* <LoadScript
+ googleMapsApiKey={process.env.GOOGLE_MAPS!}
+ libraries={['places', 'drawing']}
+ > */}
+ <div className="map-wrapper">
+ <GoogleMap
+ mapContainerStyle={mapContainerStyle}
+ zoom={this.zoom}
+ center={this.center}
+ onLoad={map => this.loadHandler(map)}
+ options={mapOptions}
+ >
+ <Autocomplete
+ onLoad={this.setSearchBox}
+ onPlaceChanged={this.handlePlaceChanged}>
+ <input ref={this.inputRef} className="searchbox" type="text" placeholder="Search anywhere:" />
+ </Autocomplete>
+
+ {this.myPlaces ? this.myPlaces.map(place =>
+ <Marker
+ position={place.pos}
+ onLoad={marker => this.markerLoadHandler(marker, place)}
+ onClick={e => this.markerClickHandler(e, place)}
+ draggable={false}
+ />
+ ) : null}
+ {this.infoWindowOpen && this.selectedPlace && (
+ <InfoWindow
+ anchor={this.markerMap[this.selectedPlace.id!]}
+ onCloseClick={this.handleInfoWindowClose}
+ >
+ <div style={{ backgroundColor: 'white', opacity: 0.75, padding: 12 }}>
+ <div style={{ fontSize: 16 }}>
+ <div>
+ <img src="http://placekitten.com/200/300" />
+ <hr />
+ <form>
+ <label>Title: </label><br />
+ <input type="text" id="fname" name="fname"></input><br />
+ <label>Desription: </label><br />
+ <textarea style={{ height: 150 }} id="lname" name="lname" placeholder="Notes, a short description of this location, a brief comment, etc."></textarea>
+ </form>
+ <hr />
+ <div>
+ <button>New link+</button>
+ </div>
+ </div>
+ </div>
+ </div>
+ </InfoWindow>
+ )}
+ </GoogleMap>
+ </div>
+ {/* </LoadScript > */}
+ </div >
+ </div >;
+ }
+
+} \ No newline at end of file
diff --git a/src/client/views/nodes/DocumentContentsView.tsx b/src/client/views/nodes/DocumentContentsView.tsx
index 9b75cd8f9..cb07c949f 100644
--- a/src/client/views/nodes/DocumentContentsView.tsx
+++ b/src/client/views/nodes/DocumentContentsView.tsx
@@ -40,6 +40,7 @@ import { VideoBox } from "./VideoBox";
import { WebBox } from "./WebBox";
import React = require("react");
import XRegExp = require("xregexp");
+import { MapBox } from "./MapBox/MapBox";
const JsxParser = require('react-jsx-parser').default; //TODO Why does this need to be imported like this?
@@ -225,7 +226,7 @@ export class DocumentContentsView extends React.Component<DocumentViewProps & Fo
FormattedTextBox, ImageBox, DirectoryImportBox, FontIconBox, LabelBox, EquationBox, SliderBox, FieldView,
CollectionFreeFormView, CollectionDockingView, CollectionSchemaView, CollectionView, WebBox, KeyValueBox,
PDFBox, VideoBox, AudioBox, PresBox, YoutubeBox, PresElementBox, SearchBox, FilterBox, FunctionPlotBox,
- ColorBox, DashWebRTCVideo, LinkAnchorBox, InkingStroke, LinkBox, ScriptingBox,
+ ColorBox, DashWebRTCVideo, LinkAnchorBox, InkingStroke, LinkBox, ScriptingBox, MapBox,
ScreenshotBox,
HTMLtag, ComparisonBox
}}
diff --git a/src/client/views/nodes/MapBox/MapBox.scss b/src/client/views/nodes/MapBox/MapBox.scss
new file mode 100644
index 000000000..863907aaf
--- /dev/null
+++ b/src/client/views/nodes/MapBox/MapBox.scss
@@ -0,0 +1,32 @@
+.MapBox {
+ width: 100%;
+ height: 100%;
+ overflow: hidden;
+
+ .MapBox-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;
+ }
+ }
+ }
+}
diff --git a/src/client/views/nodes/MapBox/MapBox.tsx b/src/client/views/nodes/MapBox/MapBox.tsx
new file mode 100644
index 000000000..cc7bf6d84
--- /dev/null
+++ b/src/client/views/nodes/MapBox/MapBox.tsx
@@ -0,0 +1,374 @@
+import { Autocomplete, GoogleMap, GoogleMapProps, InfoBox, Marker } from '@react-google-maps/api';
+import { action, computed, IReactionDisposer, observable, ObservableMap, reaction, runInAction } from 'mobx';
+import { observer } from "mobx-react";
+import * as React from "react";
+import { Doc, WidthSym } from '../../../../fields/Doc';
+import { documentSchema } from '../../../../fields/documentSchemas';
+import { makeInterface } from '../../../../fields/Schema';
+import { NumCast } from '../../../../fields/Types';
+import { setupMoveUpEvents, emptyFunction } from '../../../../Utils';
+import { DragManager } from '../../../util/DragManager';
+import { undoBatch } from '../../../util/UndoManager';
+import { ViewBoxAnnotatableComponent, ViewBoxAnnotatableProps } from '../../DocComponent';
+import { SidebarAnnos } from '../../SidebarAnnos';
+import { FieldView, FieldViewProps } from '../FieldView';
+import "./MapBox.scss"
+
+type MapDocument = makeInterface<[typeof documentSchema]>;
+const MapDocument = 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 class MapBox extends ViewBoxAnnotatableComponent<ViewBoxAnnotatableProps & FieldViewProps & Partial<GoogleMapProps>, MapDocument>(MapDocument) {
+ private _dropDisposer?: DragManager.DragDropDisposer;
+ private _disposers: { [name: string]: IReactionDisposer } = {};
+ private _sidebarRef = React.createRef<SidebarAnnos>();
+ public static LayoutString(fieldKey: string) { return FieldView.LayoutString(MapBox, fieldKey); }
+
+ @observable private _map = null as unknown as google.maps.Map;
+ @observable private selectedPlace: LocationData = null as any;
+ @observable private markerMap = {};
+ @observable private center = defaultCenter;
+ @observable private zoom = 2.5;
+ @observable private clickedLatLng = null;
+ @observable private infoWindowOpen = false;
+ @observable private bounds = new window.google.maps.LatLngBounds();
+ @observable private inputRef = React.createRef<HTMLInputElement>();
+ @observable private buttonRef = React.createRef<HTMLDivElement>();
+ @observable private searchMarkers: google.maps.Marker[] = [];
+
+ private options = {
+ fields: ["formatted_address", "geometry", "name"], // note: level of details is charged by item per retrieval, not recommended to return all fields
+ strictBounds: false,
+ types: ["establishment"], // type pf places, subject of change according to user need
+ } as google.maps.places.AutocompleteOptions;
+
+ @observable private searchBox = new window.google.maps.places.Autocomplete(this.inputRef.current!, this.options);
+
+ @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 } },
+ ];
+
+ @action
+ private setSearchBox = (searchBox: any) => {
+ this.searchBox = searchBox;
+ }
+
+ @action
+ private setButton = (button: any) => {
+ this.buttonRef = button;
+ this._map.controls[google.maps.ControlPosition.TOP_RIGHT].push(this.buttonRef.current!)
+ }
+
+ // iterate myPlaces to size, center, and zoom map to contain all markers
+ private fitBounds = (map: google.maps.Map) => {
+ console.log('map bound is:' + this.bounds);
+ this.myPlaces.map(place => {
+ this.bounds.extend(place.pos);
+ return place.id;
+ });
+ map.fitBounds(this.bounds)
+ }
+
+ // store a reference to google map instance; fit map bounds to contain all markers
+ @action
+ private loadHandler = (map: google.maps.Map) => {
+ this._map = 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(<button onClick={() => console.log('click me to add marker!')}>Add Marker</button>, 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;
+ console.log("closeinfowindow")
+ }
+ else {
+ this.infoWindowOpen = true;
+ console.log("open infowindow")
+ }
+ }
+
+ sidebarAddDocument = (doc: Doc | Doc[], sidebarKey?: string) => {
+ if (!this.layoutDoc._showSidebar) this.toggleSidebar();
+ return this.addDocument(doc, sidebarKey);
+ }
+ sidebarBtnDown = (e: React.PointerEvent) => {
+ setupMoveUpEvents(this, e, (e, down, delta) => {
+ const localDelta = this.props.ScreenToLocalTransform().scale(this.props.scaling?.() || 1).transformDirection(delta[0], delta[1]);
+ const nativeWidth = NumCast(this.layoutDoc[this.fieldKey + "-nativeWidth"]);
+ const curNativeWidth = NumCast(this.layoutDoc.nativeWidth, nativeWidth);
+ const ratio = (curNativeWidth + localDelta[0] / (this.props.scaling?.() || 1)) / nativeWidth;
+ if (ratio >= 1) {
+ this.layoutDoc.nativeWidth = nativeWidth * ratio;
+ this.layoutDoc._width = this.layoutDoc[WidthSym]() + localDelta[0];
+ this.layoutDoc._showSidebar = nativeWidth !== this.layoutDoc._nativeWidth;
+ }
+ return false;
+ }, emptyFunction, this.toggleSidebar);
+ }
+ toggleSidebar = action(() => {
+ const nativeWidth = NumCast(this.layoutDoc[this.fieldKey + "-nativeWidth"]);
+ const ratio = ((!this.layoutDoc.nativeWidth || this.layoutDoc.nativeWidth === nativeWidth ? 250 : 0) + nativeWidth) / nativeWidth;
+ const curNativeWidth = NumCast(this.layoutDoc.nativeWidth, nativeWidth);
+ this.layoutDoc.nativeWidth = nativeWidth * ratio;
+ this.layoutDoc._width = this.layoutDoc[WidthSym]() * nativeWidth * ratio / curNativeWidth;
+ this.layoutDoc._showSidebar = nativeWidth !== this.layoutDoc._nativeWidth;
+ });
+ sidebarWidth = () => !this.layoutDoc._showSidebar ? 0 : (NumCast(this.layoutDoc.nativeWidth) - Doc.NativeWidth(this.dataDoc)) * this.props.PanelWidth() / NumCast(this.layoutDoc.nativeWidth);
+
+ @action
+ @undoBatch
+ private handleDragMarker = (marker: any, place: LocationData) => {
+ // if (marker != null) {
+ // place = {
+ // id: place.id,
+ // position: {
+ // lat: marker.latLng.lat().toFixed(3),
+ // lng: marker.latLng.lng().toFixed(3)
+ // }
+ // }
+
+ // console.log(place);
+ // console.log(this.myPlaces);
+ // }
+ }
+
+ @action
+ private handlePlaceChanged = () => {
+ console.log(this.searchBox);
+ const place = this.searchBox.getPlace();
+
+ if (!place.geometry || !place.geometry.location) {
+ // user entered the name of a place that wasn't suggested & pressed the enter key, or place details request failed
+ window.alert("No details available for input: '" + place.name + "'");
+ return;
+ }
+
+ // zoom in on the location of the search result
+ if (place.geometry.viewport) {
+ console.log(this._map);
+ this._map.fitBounds(place.geometry.viewport);
+ } else {
+ console.log(this._map);
+ this._map.setCenter(place.geometry.location);
+ this._map.setZoom(17);
+ }
+
+ /**
+ * customize icon => customized icon for the nature of the location selected (hard to tell from other pre-existing markers, probably won't implement
+ */
+ // 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),
+ // };
+
+ this.searchMarkers.forEach((marker) => {
+ marker.setMap(null);
+ });
+ this.searchMarkers = [];
+ this.searchMarkers.push(
+ new window.google.maps.Marker({
+ map: this._map,
+ title: place.name,
+ position: place.geometry.location,
+ })
+ )
+ }
+
+ // @computed get markerContent() {
+ // const allMarkers = this.childLayoutPairs
+ // const markerId = NumCast(this.layoutDoc._itemIndex);
+ // const selectedMarker = this.childLayoutPairs?.[markerId];
+ // const position = {
+ // lat: NumCast(this.layoutDoc.lat),
+ // lng: NumCast(this.layoutDoc.lng)
+ // }
+ // return <>
+ // {
+ // allMarkers?.map(place => (
+ // <Marker
+ // key={markerId}
+ // position={position}
+ // onClick={e => this.markerClickHandler(e, place.layout)} //??
+ // draggable={true}
+ // onDragEnd={marker => this.handleDragMarker(marker, place.layout)}
+ // />
+ // ))
+ // }
+ // {this.infoWindowOpen && selectedMarker && (
+ // <InfoBox
+ // //anchor={selectedMarker}
+ // // onCloseClick={this.handleInfoWindowClose}
+ // position={position}
+ // // options={{ enableEventPropagation: true }}
+ // >
+ // <div style={{ backgroundColor: 'white', opacity: 0.75, padding: 12 }}>
+ // <div style={{ fontSize: 16 }}>
+ // {/* the linkmenu as the ones in other nodes */}
+ // <div>
+ // <a>a link to another node</a>
+ // <hr />
+ // </div>
+ // <div>
+ // <a>a link to another node</a>
+ // <hr />
+ // </div>
+ // <div>
+ // <a>a link to another node</a>
+ // <hr />
+ // </div>
+ // <div>
+ // <button>New +</button>
+ // </div>
+ // </div>
+ // </div>
+ // </InfoBox>
+ // )}
+
+ // </>
+ // }
+
+ @action
+ private addMarker = (location: google.maps.LatLng | undefined, map: google.maps.Map) => {
+ new window.google.maps.Marker({
+ position: location,
+ map: map
+ });
+ }
+
+ // @action
+ // private renderMarkerToMap = (marker: Doc) => {
+ // const id = StrCast(marker.id);
+ // const lat = NumCast(marker.lat);
+ // const lng = NumCast(marker.lng);
+
+ // return <Marker
+ // key={id}
+ // position={{ lat: lat, lng: lng }}
+ // onClick={e => this.markerClickHandler(e, marker)}
+ // />
+ // }
+
+ render() {
+ const { Document, fieldKey, isContentActive: active } = this.props;
+
+ return <div className="MapBox">
+ HELLO WORLD!
+ {/*<div className={"MapBox-contents"}
+ style={{ pointerEvents: active() ? undefined : "none", overflow: 'hidden' }}
+ onWheel={e => e.stopPropagation()}
+ onPointerDown={e => (e.button === 0 && !e.ctrlKey) && e.stopPropagation()} >
+ // {/* <LoadScript
+ // googleMapsApiKey={process.env.GOOGLE_MAPS!}
+ // libraries={['places', 'drawing']}
+ // >
+ <div className="map-wrapper">
+ <GoogleMap
+ mapContainerStyle={mapContainerStyle}
+ zoom={this.zoom}
+ center={this.center}
+ onLoad={map => this.loadHandler(map)}
+ >
+ <Autocomplete
+ onLoad={this.setSearchBox}
+ onPlaceChanged={this.handlePlaceChanged}>
+ <input ref={this.inputRef} className="searchbox" type="text" placeholder="Search anywhere:" />
+ </Autocomplete>
+
+ <div onLoad={this.setButton}>
+ <div ref={this.buttonRef} className="add-button-UI" >
+ <div className="add-button-Text">Add Marker</div>
+ </div>
+ </div>
+
+ {this.myPlaces.map(place => (
+ <Marker
+ key={place.id}
+ position={place.pos}
+ // onLoad={marker => this.markerLoadHandler(marker, place)}
+ onClick={e => this.markerClickHandler(e, place)}
+ draggable={true}
+ onDragEnd={marker => this.handleDragMarker(marker, place)}
+ />
+ ))}
+ {this.infoWindowOpen && this.selectedPlace && (
+ <InfoBox
+ // anchor={this.markerMap[this.selectedPlace.id]}
+ // onCloseClick={this.handleInfoWindowClose}
+ position={this.selectedPlace.pos}
+ // options={{ enableEventPropagation: true }}
+ >
+ <div style={{ backgroundColor: 'white', opacity: 0.75, padding: 12 }}>
+ <div style={{ fontSize: 16 }}>
+ <div>
+ <a>a link to another node</a>
+ <hr />
+ </div>
+ <div>
+ <a>a link to another node</a>
+ <hr />
+ </div>
+ <div>
+ <a>a link to another node</a>
+ <hr />
+ </div>
+ <div>
+ <button>New +</button>
+ </div>
+ </div>
+ </div>
+ </InfoBox>
+ )}
+ </GoogleMap>
+ </div>
+ {/* </LoadScript >
+ <SidebarAnnos ref={this._sidebarRef}
+ {...this.props}
+ fieldKey={this.annotationKey}
+ rootDoc={this.rootDoc}
+ layoutDoc={this.layoutDoc}
+ dataDoc={this.dataDoc}
+ sidebarAddDocument={this.sidebarAddDocument}
+ moveDocument={this.moveDocument}
+ removeDocument={this.removeDocument}
+ isContentActive={this.isContentActive}
+ />
+ </div >*/}
+ </div >;
+ }
+
+} \ No newline at end of file
diff --git a/src/client/views/nodes/MapMarker/MapMarker.tsx b/src/client/views/nodes/MapMarker/MapMarker.tsx
new file mode 100644
index 000000000..9705986a8
--- /dev/null
+++ b/src/client/views/nodes/MapMarker/MapMarker.tsx
@@ -0,0 +1,23 @@
+//TODO: mock imagebox, create marker as a doc
+import { IReactionDisposer } from "mobx";
+import { observer } from "mobx-react";
+import * as React from "react";
+import { documentSchema } from "../../../../fields/documentSchemas";
+import { createSchema, makeInterface } from "../../../../fields/Schema";
+import { ViewBoxBaseComponent } from "../../DocComponent";
+import { FieldView, FieldViewProps } from "../FieldView";
+
+export const markerSchema = createSchema({
+ lat: "number",
+ lng: "number"
+});
+
+type MarkerDocument = makeInterface<[typeof markerSchema, typeof documentSchema]>;
+const MarkerDocument = makeInterface(markerSchema, documentSchema);
+
+@observer
+export class MapMarker extends ViewBoxBaseComponent<FieldViewProps, MarkerDocument>(MarkerDocument) {
+ public static LayoutString(fieldKey: string) { return FieldView.LayoutString(MapMarker, fieldKey); }
+ private _markerRef: React.RefObject<google.maps.Marker> = React.createRef();
+ private _disposers: { [name: string]: IReactionDisposer } = {};
+} \ No newline at end of file
diff --git a/src/client/views/nodes/PresBox.tsx b/src/client/views/nodes/PresBox.tsx
index f3fb6ff17..11a735645 100644
--- a/src/client/views/nodes/PresBox.tsx
+++ b/src/client/views/nodes/PresBox.tsx
@@ -81,6 +81,11 @@ const PresBoxDocument = makeInterface(documentSchema);
export class PresBox extends ViewBoxBaseComponent<FieldViewProps, PresBoxSchema>(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<FieldViewProps, PresBoxSchema>
}
}
+ //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<FieldViewProps, PresBoxSchema>
/**
* 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<FieldViewProps, PresBoxSchema>
load();
}
+ // The function pauses the auto presentation
@action
pauseAutoPres = () => {
if (this.layoutDoc.presStatus === PresStatus.Autoplay) {
@@ -592,6 +599,7 @@ export class PresBox extends ViewBoxBaseComponent<FieldViewProps, PresBoxSchema>
});
}
+ // 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<FieldViewProps, PresBoxSchema>
}
}
+ // The function allows for expanding the view of pres on toggle
@action toggleExpandMode = () => {
runInAction(() => this._expandBoolean = !this._expandBoolean);
this.rootDoc.expandBoolean = this._expandBoolean;
@@ -1254,7 +1263,7 @@ export class PresBox extends ViewBoxBaseComponent<FieldViewProps, PresBoxSchema>
<input className="presBox-input"
type="number" value={duration}
onChange={action((e) => this.setDurationTime(e.target.value))} /> s
- </div>
+ </div>
<div className="ribbon-propertyUpDown">
<div className="ribbon-propertyUpDownItem" onClick={undoBatch(() => this.setDurationTime(String(duration), 1000))}>
<FontAwesomeIcon icon={"caret-up"} />
@@ -1846,6 +1855,7 @@ export class PresBox extends ViewBoxBaseComponent<FieldViewProps, PresBoxSchema>
case DocumentType.VID: type = "Video"; break;
case DocumentType.IMG: type = "Image"; break;
case DocumentType.WEB: type = "Web page"; break;
+ case DocumentType.MAP: type = "Map"; break;
default: type = "Other node"; break;
}
}
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<FieldViewProps, PresDoc
e.preventDefault();
}
+ /**
+ * Function to drag and drop the pres element to a diferent location
+ */
startDrag = (e: PointerEvent) => {
const miniView: boolean = this.toolbarWidth <= 100;
const activeItem = this.rootDoc;
@@ -242,6 +245,7 @@ export class PresElementBox extends ViewBoxBaseComponent<FieldViewProps, PresDoc
e.stopPropagation();
});
+ // set the value/title of the individual pres element
@undoBatch
@action
onSetValue = (value: string) => {
diff --git a/src/client/views/search/IconButton.tsx b/src/client/views/search/IconButton.tsx
index 2dd6b1b79..6cf3a5f72 100644
--- a/src/client/views/search/IconButton.tsx
+++ b/src/client/views/search/IconButton.tsx
@@ -70,6 +70,7 @@ export class IconButton extends React.Component<IconButtonProps>{
case (DocumentType.RTF): return "sticky-note";
case (DocumentType.VID): return "video";
case (DocumentType.WEB): return "globe-asia";
+ case (DocumentType.MAP): return "map-marker-alt";
default: return "caret-down";
}
}
diff --git a/src/fields/Doc.ts b/src/fields/Doc.ts
index 464a8ad05..d73e9a016 100644
--- a/src/fields/Doc.ts
+++ b/src/fields/Doc.ts
@@ -20,7 +20,7 @@ import { RichTextField } from "./RichTextField";
import { listSpec } from "./Schema";
import { ComputedField, ScriptField } from "./ScriptField";
import { Cast, FieldValue, NumCast, StrCast, ToConstructor } from "./Types";
-import { AudioField, ImageField, PdfField, VideoField, WebField } from "./URLField";
+import { AudioField, ImageField, MapField, PdfField, VideoField, WebField } from "./URLField";
import { deleteProperty, GetEffectiveAcl, getField, getter, makeEditable, makeReadOnly, normalizeEmail, setter, SharingPermissions, updateFunction } from "./util";
import JSZip = require("jszip");
@@ -618,6 +618,7 @@ export namespace Doc {
else if (value instanceof AudioField) return { url: value.url.href, __type: "audio" };
else if (value instanceof VideoField) return { url: value.url.href, __type: "video" };
else if (value instanceof WebField) return { url: value.url.href, __type: "web" };
+ else if (value instanceof MapField) return { url: value.url.href, __type: "map" };
else if (value instanceof DateField) return { date: value.toString(), __type: "date" };
else if (value instanceof ProxyField) return { fieldId: value.fieldId, __type: "proxy" };
else if (value instanceof Array && key !== "fields") return { fields: value, __type: "list" };
@@ -1197,6 +1198,7 @@ export namespace Doc {
case DocumentType.INK: return "pen-nib";
case DocumentType.PDF: return "file-pdf";
case DocumentType.LINK: return "link";
+ case DocumentType.MAP: return "map-marker-alt"
default: return "question";
}
}
diff --git a/src/fields/URLField.ts b/src/fields/URLField.ts
index fb71160ca..48535edf0 100644
--- a/src/fields/URLField.ts
+++ b/src/fields/URLField.ts
@@ -48,6 +48,7 @@ export const nullAudio = "https://actions.google.com/sounds/v1/alarms/beep_short
@scriptingGlobal @Deserializable("video") export class VideoField extends URLField { }
@scriptingGlobal @Deserializable("pdf") export class PdfField extends URLField { }
@scriptingGlobal @Deserializable("web") export class WebField extends URLField { }
+@scriptingGlobal @Deserializable("map") export class MapField extends URLField { }
@scriptingGlobal @Deserializable("youtube") export class YoutubeField extends URLField { }
@scriptingGlobal @Deserializable("webcam") export class WebCamField extends URLField { }
diff --git a/src/fields/documentSchemas.ts b/src/fields/documentSchemas.ts
index f17a390a6..b114fcf2d 100644
--- a/src/fields/documentSchemas.ts
+++ b/src/fields/documentSchemas.ts
@@ -27,6 +27,8 @@ export const documentSchema = createSchema({
z: "number", // z "coordinate" - non-zero specifies the overlay layer of a freeformview
zIndex: "number", // zIndex of a document in a freeform view
_scrollTop: "number", // scroll position of a scrollable document (pdf, text, web)
+ lat: "number",
+ lng: "number",
// appearance properties on the layout
"_backgroundGrid-spacing": "number", // the size of the grid for collection views
diff --git a/src/server/ApiManagers/DownloadManager.ts b/src/server/ApiManagers/DownloadManager.ts
index 0d4472fdc..2175b6db6 100644
--- a/src/server/ApiManagers/DownloadManager.ts
+++ b/src/server/ApiManagers/DownloadManager.ts
@@ -112,7 +112,7 @@ async function getDocs(id: string) {
const pathname = new URL(urlString).pathname;
files.add(pathname);
}
- } else if (["audio", "image", "video", "pdf", "web"].includes(field.__type)) {
+ } else if (["audio", "image", "video", "pdf", "web", "map"].includes(field.__type)) {
const url = new URL(field.url);
const pathname = url.pathname;
files.add(pathname);
diff --git a/src/server/ApiManagers/SearchManager.ts b/src/server/ApiManagers/SearchManager.ts
index 775e90520..a74e13a62 100644
--- a/src/server/ApiManagers/SearchManager.ts
+++ b/src/server/ApiManagers/SearchManager.ts
@@ -185,6 +185,7 @@ export namespace SolrManager {
"pdf": ["_t", "url"],
"audio": ["_t", "url"],
"web": ["_t", "url"],
+ "map": ["_t", "url"],
"date": ["_d", value => new Date(value.date).toISOString()],
"proxy": ["_i", "fieldId"],
"prefetch_proxy": ["_i", "fieldId"],
diff --git a/src/server/GarbageCollector.ts b/src/server/GarbageCollector.ts
index 7c441e3c0..c60880882 100644
--- a/src/server/GarbageCollector.ts
+++ b/src/server/GarbageCollector.ts
@@ -45,7 +45,7 @@ function addDoc(doc: any, ids: string[], files: { [name: string]: string[] }) {
}
exts.push(ext);
}
- } else if (["audio", "image", "video", "pdf", "web"].includes(field.__type)) {
+ } else if (["audio", "image", "video", "pdf", "web", "map"].includes(field.__type)) {
const url = new URL(field.url);
const pathname = url.pathname;
const ext = path.extname(pathname);
diff --git a/src/server/remapUrl.ts b/src/server/remapUrl.ts
index 7178add93..e9f9da25a 100644
--- a/src/server/remapUrl.ts
+++ b/src/server/remapUrl.ts
@@ -8,7 +8,8 @@ const suffixMap: { [type: string]: true } = {
"pdf": true,
"audio": true,
"web": true,
- "image": true
+ "image": true,
+ "map": true,
};
async function update() {
diff --git a/src/server/updateProtos.ts b/src/server/updateProtos.ts
index e9860bd61..c5552f6bf 100644
--- a/src/server/updateProtos.ts
+++ b/src/server/updateProtos.ts
@@ -1,7 +1,7 @@
import { Database } from "./database";
const protos =
- ["text", "image", "web", "collection", "kvp", "video", "audio", "pdf", "icon", "import", "linkdoc"];
+ ["text", "image", "web", "collection", "kvp", "video", "audio", "pdf", "icon", "import", "linkdoc", "map"];
(async function () {
await Promise.all(
diff --git a/src/server/websocket.ts b/src/server/websocket.ts
index 4ae97913f..115baa0be 100644
--- a/src/server/websocket.ts
+++ b/src/server/websocket.ts
@@ -229,6 +229,7 @@ export namespace WebSocket {
"pdf": ["_t", "url"],
"audio": ["_t", "url"],
"web": ["_t", "url"],
+ "map": ["_t", "url"],
"script": ["_t", value => value.script.originalScript],
"RichTextField": ["_t", value => value.Text],
"date": ["_d", value => new Date(value.date).toISOString()],