1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
|
/* eslint-disable react/button-has-type */
import { IconLookup, faAdd, faArrowDown, faArrowLeft, faArrowsRotate, faBicycle, faCalendarDays, faCar, faDiamondTurnRight, faEdit, faPersonWalking, faRoute } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { Autocomplete, Checkbox, FormControlLabel, TextField } from '@mui/material';
import { IconButton } from '@dash/components';
import { Position } from 'geojson';
import { IReactionDisposer, ObservableMap, action, makeObservable, observable, reaction, runInAction } from 'mobx';
import { observer } from 'mobx-react';
import * as React from 'react';
import { CirclePicker, ColorResult } from 'react-color';
import { returnFalse, setupMoveUpEvents } from '../../../../ClientUtils';
import { unimplementedFunction } from '../../../../Utils';
import { Doc, Opt } from '../../../../fields/Doc';
import { NumCast, StrCast } from '../../../../fields/Types';
import { CalendarManager } from '../../../util/CalendarManager';
import { SettingsManager } from '../../../util/SettingsManager';
import { AntimodeMenu, AntimodeMenuProps } from '../../AntimodeMenu';
import { DocumentView } from '../DocumentView';
import './MapAnchorMenu.scss';
import { MapboxApiUtility, TransportationType } from './MapboxApiUtility';
import { MarkerIcons } from './MarkerIcons';
// import { GPTPopup, GPTPopupMode } from './../../GPTPopup/GPTPopup';
type MapAnchorMenuType = 'standard' | 'routeCreation' | 'calendar' | 'customize' | 'route';
@observer
export class MapAnchorMenu extends AntimodeMenu<AntimodeMenuProps> {
// eslint-disable-next-line no-use-before-define
static Instance: MapAnchorMenu;
private _disposer: IReactionDisposer | undefined;
private _commentRef = React.createRef<HTMLDivElement>();
private _fileInputRef = React.createRef<HTMLInputElement>();
public onMakeAnchor: () => Opt<Doc> = () => undefined; // Method to get anchor from text search
public Center: () => void = unimplementedFunction;
public OnClick: (e: PointerEvent) => void = unimplementedFunction;
// public OnAudio: (e: PointerEvent) => void = unimplementedFunction;
public StartDrag: (e: PointerEvent, ele: HTMLElement) => void = unimplementedFunction;
public Highlight: (color: string, isTargetToggler: boolean, savedAnnotations?: ObservableMap<number, HTMLDivElement[]>, addAsAnnotation?: boolean) => Opt<Doc> = () => undefined;
public GetAnchor: (savedAnnotations: Opt<ObservableMap<number, HTMLDivElement[]>>, addAsAnnotation: boolean) => Opt<Doc> = () => undefined;
public Delete: () => void = unimplementedFunction;
// public MakeTargetToggle: () => void = unimplementedFunction;
// public ShowTargetTrail: () => void = unimplementedFunction;
public IsTargetToggler: () => boolean = returnFalse;
public DisplayRoute: (routeInfoMap: Record<TransportationType, any> | undefined, type: TransportationType) => void = unimplementedFunction;
public AddNewRouteToMap: (coordinates: Position[], origin: string, destination: any, createPinForDestination: boolean) => void = unimplementedFunction;
public CreatePin: (feature: any) => void = unimplementedFunction;
public UpdateMarkerColor: (color: string) => void = unimplementedFunction;
public UpdateMarkerIcon: (iconKey: string) => void = unimplementedFunction;
public Hide: () => void = unimplementedFunction;
public OpenAnimationPanel: (routeDoc: Doc | undefined) => void = unimplementedFunction;
@observable
menuType: MapAnchorMenuType = 'standard';
@action
public setMenuType = (menuType: MapAnchorMenuType) => {
this.menuType = menuType;
};
private allMapPinDocs: Doc[] = [];
private pinDoc: Doc | undefined = undefined;
private routeDoc: Doc | undefined = undefined;
private title: string | undefined = undefined;
public setPinDoc(pinDoc: Doc | undefined) {
if (pinDoc) {
this.pinDoc = pinDoc;
this.title = StrCast(pinDoc.title ? pinDoc.title : `${NumCast(pinDoc.longitude)}, ${NumCast(pinDoc.latitude)}`);
}
}
public setRouteDoc(routeDoc: Doc | undefined) {
if (routeDoc) {
this.routeDoc = routeDoc;
this.title = StrCast(routeDoc.title ?? 'Map route');
}
}
@action
public Reset() {
this.destinationSelected = false;
this.currentRouteInfoMap = undefined;
this.destinationFeatures = [];
this.selectedDestinationFeature = undefined;
this.allMapPinDocs = [];
this.title = undefined;
this.routeDoc = undefined;
this.pinDoc = undefined;
}
public setAllMapboxPins(pinDocs: Doc[]) {
this.allMapPinDocs = pinDocs;
pinDocs.forEach((p, idx) => {
console.log(`Pin ${idx}: ${p.title}`);
});
}
public get Active() {
return this._left > 0;
}
constructor(props: any) {
super(props);
makeObservable(this);
MapAnchorMenu.Instance = this;
MapAnchorMenu.Instance._canFade = false;
}
componentWillUnmount() {
this.destinationFeatures = [];
this.destinationSelected = false;
this.selectedDestinationFeature = undefined;
this.currentRouteInfoMap = undefined;
this._disposer?.();
}
componentDidMount() {
this._disposer = reaction(
() => DocumentView.Selected().slice(),
() => MapAnchorMenu.Instance.fadeOut(true)
);
}
// audioDown = (e: React.PointerEvent) => {
// setupMoveUpEvents(this, e, returnFalse, returnFalse, e => this.OnAudio?.(e));
// };
// cropDown = (e: React.PointerEvent) => {
// setupMoveUpEvents(
// this,
// e,
// (e: PointerEvent) => {
// this.StartCropDrag(e, this._commentCont.current!);
// return true;
// },
// returnFalse,
// e => this.OnCrop?.(e)
// );
// };
notePointerDown = (e: React.PointerEvent) => {
setupMoveUpEvents(
this,
e,
moveEv => {
this.StartDrag(moveEv, this._commentRef.current!);
return true;
},
returnFalse,
clickEv => this.OnClick(clickEv)
);
};
static top = React.createRef<HTMLDivElement>();
// public get Top(){
// return this.top
// }
@action
DirectionsClick = () => {
this.menuType = 'routeCreation';
};
@action
CustomizeClick = () => {
this.currentRouteInfoMap = undefined;
this.menuType = 'customize';
};
@action
BackClick = () => {
this.currentRouteInfoMap = undefined;
this.menuType = 'standard';
};
@action
TriggerFileInputClick = () => {
if (this._fileInputRef) {
this._fileInputRef.current?.click(); // Trigger the file input click event
}
};
@action
onMarkerColorChange = (color: ColorResult) => {
if (this.pinDoc) {
this.pinDoc.markerColor = color.hex;
}
};
revertToOriginalMarker = () => {
if (this.pinDoc) {
this.pinDoc.markerType = 'MAP_PIN';
this.pinDoc.markerColor = '#ff5722';
}
};
onMarkerIconChange = (iconKey: string) => {
if (this.pinDoc) {
this.pinDoc.markerType = iconKey;
}
};
@observable
destinationFeatures: any[] = [];
@observable
destinationSelected: boolean = false;
@observable
selectedDestinationFeature: any = undefined;
@observable
createPinForDestination: boolean = true;
@observable
currentRouteInfoMap: Record<TransportationType, any> | undefined = undefined;
@observable
selectedTransportationType: TransportationType = 'driving';
@action
handleTransportationTypeChange = (newType: TransportationType) => {
if (newType !== this.selectedTransportationType) {
this.selectedTransportationType = newType;
this.DisplayRoute(this.currentRouteInfoMap, newType);
}
};
@action
handleSelectedDestinationFeature = (destinationFeature: any) => {
this.selectedDestinationFeature = destinationFeature;
};
@action
toggleCreatePinForDestinationCheckbox = () => {
this.createPinForDestination = !this.createPinForDestination;
};
@action
handleDestinationSearchChange = async (searchText: string) => {
if (this.selectedDestinationFeature !== undefined) this.selectedDestinationFeature = undefined;
const features = await MapboxApiUtility.forwardGeocodeForFeatures(searchText);
if (features) {
runInAction(() => {
this.destinationFeatures = features;
});
}
};
getRoutes = async (destinationFeature: any) => {
const currentPinLong: number = NumCast(this.pinDoc?.longitude);
const currentPinLat: number = NumCast(this.pinDoc?.latitude);
if (currentPinLong && currentPinLat && destinationFeature.center) {
const routeInfoMap = await MapboxApiUtility.getDirections([currentPinLong, currentPinLat], destinationFeature.center);
if (routeInfoMap) {
runInAction(() => {
this.currentRouteInfoMap = routeInfoMap;
});
this.DisplayRoute(routeInfoMap, 'driving');
}
}
// get route menu, set it equal to here
// create a temporary route
// create pin if createPinForDestination was clicked
};
HandleAddRouteClick = () => {
if (this.currentRouteInfoMap && this.selectedTransportationType && this.selectedDestinationFeature) {
const { coordinates } = this.currentRouteInfoMap[this.selectedTransportationType];
console.log(coordinates);
console.log(this.selectedDestinationFeature);
this.AddNewRouteToMap(coordinates, this.title ?? '', this.selectedDestinationFeature, this.createPinForDestination);
}
};
getMarkerIcon = (): JSX.Element | undefined => {
if (this.pinDoc) {
const markerType = StrCast(this.pinDoc.markerType);
const markerColor = StrCast(this.pinDoc.markerColor);
return MarkerIcons.getFontAwesomeIcon(markerType, '2x', markerColor);
}
return undefined;
};
getDirectionsButton: JSX.Element = (<IconButton tooltip="Get directions" onPointerDown={this.DirectionsClick} icon={<FontAwesomeIcon icon={faDiamondTurnRight as IconLookup} />} color={SettingsManager.userColor} />);
getAddToCalendarButton = (docType: string): JSX.Element => (
<IconButton
tooltip="Add to calendar"
onPointerDown={() => {
CalendarManager.Instance.open(undefined, docType === 'pin' ? this.pinDoc : this.routeDoc);
}}
icon={<FontAwesomeIcon icon={faCalendarDays as IconLookup} />}
color={SettingsManager.userColor}
/>
);
addToCalendarButton: JSX.Element = (
<IconButton tooltip="Add to calendar" onPointerDown={() => CalendarManager.Instance.open(undefined, this.pinDoc)} icon={<FontAwesomeIcon icon={faCalendarDays as IconLookup} />} color={SettingsManager.userColor} />
);
getLinkNoteToDocButton = (docType: string): JSX.Element => (
<div ref={this._commentRef}>
<IconButton
tooltip={`Link Note to ${docType === 'pin' ? 'Pin' : 'Route'}`} //
onPointerDown={this.notePointerDown}
icon={<FontAwesomeIcon icon="sticky-note" />}
color={SettingsManager.userColor}
/>
</div>
);
linkNoteToPinOrRoutenButton: JSX.Element = (
<div ref={this._commentRef}>
<IconButton
tooltip="Link Note to Pin" //
onPointerDown={this.notePointerDown}
icon={<FontAwesomeIcon icon="sticky-note" />}
color={SettingsManager.userColor}
/>
</div>
);
customizePinButton: JSX.Element = (<IconButton tooltip="Customize pin" onPointerDown={this.CustomizeClick} icon={<FontAwesomeIcon icon={faEdit as IconLookup} />} color={SettingsManager.userColor} />);
centerOnPinButton: JSX.Element = (
<IconButton
tooltip="Center on pin" //
onPointerDown={this.Center}
icon={<FontAwesomeIcon icon="compress-arrows-alt" />}
color={SettingsManager.userColor}
/>
);
backButton: JSX.Element = (
<IconButton
tooltip="Go back" //
onPointerDown={this.BackClick}
icon={<FontAwesomeIcon icon={faArrowLeft as IconLookup} />}
color={SettingsManager.userColor}
/>
);
addRouteButton: JSX.Element = (
<IconButton
tooltip="Add route" //
onPointerDown={this.HandleAddRouteClick}
icon={<FontAwesomeIcon icon={faAdd as IconLookup} />}
color={SettingsManager.userColor}
/>
);
getDeleteButton = (type: string) => (
<IconButton
tooltip={`Delete ${type === 'pin' ? 'Pin' : 'Route'}`} //
onPointerDown={this.Delete}
icon={<FontAwesomeIcon icon="trash-alt" />}
color={SettingsManager.userColor}
/>
);
animateRouteButton: JSX.Element = (<IconButton tooltip="Animate route" onPointerDown={() => this.OpenAnimationPanel(this.routeDoc)} icon={<FontAwesomeIcon icon={faRoute as IconLookup} />} color={SettingsManager.userColor} />);
revertToOriginalMarkerButton = (
<IconButton
tooltip="Revert to original" //
onPointerDown={() => this.revertToOriginalMarker()}
icon={<FontAwesomeIcon icon={faArrowsRotate as IconLookup} />}
color={SettingsManager.userColor}
/>
);
render() {
const buttons = (
<div className="menu-buttons" style={{ display: 'flex' }}>
{this.menuType === 'standard' && (
<>
{this.getDeleteButton('pin')}
{this.getDirectionsButton}
{this.getAddToCalendarButton('pin')}
{this.getLinkNoteToDocButton('pin')}
{this.customizePinButton}
{this.centerOnPinButton}
</>
)}
{this.menuType === 'routeCreation' && (
<>
{this.backButton}
{this.addRouteButton}
</>
)}
{this.menuType === 'route' && (
<>
{this.getDeleteButton('route')}
{this.animateRouteButton}
{this.getAddToCalendarButton('route')}
{this.getLinkNoteToDocButton('route')}
</>
)}
{this.menuType === 'customize' && (
<>
{this.backButton}
{this.revertToOriginalMarkerButton}
</>
)}
{/* {this.IsTargetToggler !== returnFalse && (
<Toggle
tooltip={'Make target visibility toggle on click'}
type={Type.PRIM}
toggleType={ToggleType.BUTTON}
toggleStatus={this.IsTargetToggler()}
onClick={this.MakeTargetToggle}
icon={<FontAwesomeIcon icon="thumbtack" />}
color={SettingsManager.userColor}
/>
)} */}
</div>
);
return this.getElement(
<div ref={MapAnchorMenu.top} className="map-anchor-menu-container">
{this.menuType === 'standard' && <div>{this.title}</div>}
{this.menuType === 'routeCreation' && (
<div className="direction-inputs" style={{ display: 'flex', flexDirection: 'column' }}>
<TextField fullWidth disabled value={this.title} />
<FontAwesomeIcon icon={faArrowDown as IconLookup} size="xs" />
<Autocomplete
fullWidth
id="route-destination-searcher"
onInputChange={(e: any, searchText: any) => this.handleDestinationSearchChange(searchText)}
onChange={(e: any, feature: any, reason: any) => {
if (reason === 'clear') {
this.handleSelectedDestinationFeature(undefined);
} else if (reason === 'selectOption') {
this.handleSelectedDestinationFeature(feature);
}
}}
options={this.destinationFeatures.filter(feature => feature.place_name).map(feature => feature)}
getOptionLabel={(feature: any) => feature.place_name}
// eslint-disable-next-line react/jsx-props-no-spreading
renderInput={(params: any) => <TextField {...params} placeholder="Enter a destination" />}
/>
{!this.selectedDestinationFeature
? null
: !this.allMapPinDocs.some(pinDoc => pinDoc.title === this.selectedDestinationFeature.place_name) && (
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', gap: '5px' }}>
<FormControlLabel label="Create pin for destination?" control={<Checkbox color="success" checked={this.createPinForDestination} onChange={this.toggleCreatePinForDestinationCheckbox} />} />
</div>
)}
<button id="get-routes-button" disabled={!this.selectedDestinationFeature} onClick={() => this.getRoutes(this.selectedDestinationFeature)}>
Get routes
</button>
{/* <input
placeholder="Origin"
/> */}
</div>
)}
{this.currentRouteInfoMap && (
<div className="current-route-info-container">
<div className="transportation-icons-container">
<IconButton
tooltip="Driving route"
onPointerDown={() => this.handleTransportationTypeChange('driving')}
icon={<FontAwesomeIcon icon={faCar as IconLookup} />}
color={this.selectedTransportationType === 'driving' ? 'lightblue' : 'grey'}
/>
<IconButton
tooltip="Cycling route"
onPointerDown={() => this.handleTransportationTypeChange('cycling')}
icon={<FontAwesomeIcon icon={faBicycle as IconLookup} />}
color={this.selectedTransportationType === 'cycling' ? 'lightblue' : 'grey'}
/>
<IconButton
tooltip="Walking route"
onPointerDown={() => this.handleTransportationTypeChange('walking')}
icon={<FontAwesomeIcon icon={faPersonWalking as IconLookup} />}
color={this.selectedTransportationType === 'walking' ? 'lightblue' : 'grey'}
/>
</div>
<div className="selected-route-details-container">
<div>Duration: {this.currentRouteInfoMap[this.selectedTransportationType].duration}</div>
<div>Distance: {this.currentRouteInfoMap[this.selectedTransportationType].distance}</div>
</div>
</div>
)}
{this.menuType === 'customize' && (
<div className="customized-marker-container">
<div className="current-marker-container">
<div>Current Marker: </div>
<div>{this.getMarkerIcon()}</div>
</div>
<div className="color-picker-container" style={{ marginBottom: '10px' }}>
<CirclePicker circleSize={15} circleSpacing={7} width="100%" onChange={color => this.onMarkerColorChange(color)} />
</div>
<div className="all-markers-container">
{Object.keys(MarkerIcons.FAMarkerIconsMap).map(iconKey => (
<div key={iconKey} className="marker-icon">
<IconButton onPointerDown={() => this.onMarkerIconChange(iconKey)} icon={MarkerIcons.getFontAwesomeIcon(iconKey, '1x', 'white')} />
</div>
))}
</div>
<div style={{ width: '100%', height: '3px', color: 'white' }} />
</div>
)}
{this.menuType === 'route' && this.routeDoc && <div>{StrCast(this.routeDoc.title)}</div>}
{buttons}
</div>,
true
);
}
}
|