Skip to content

Commit

Permalink
Set up general popup
Browse files Browse the repository at this point in the history
  • Loading branch information
Toby Twigger committed Jul 1, 2023
1 parent 98ef545 commit 48dff5b
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion resources/js/ui/tools/maps/controls/ElevationControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ElevationControl implements Control {
}

initialise(map: Map, triggerStateUpdate: () => void) {

this.triggerStateUpdate = triggerStateUpdate;
}

modifyState(state: MapState, oldState: MapState): MapState {
Expand Down
2 changes: 1 addition & 1 deletion resources/js/ui/tools/maps/controls/FullscreenControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class FullscreenControl implements Control {
}

initialise(map: Map, triggerStateUpdate: () => void) {

this.triggerStateUpdate = triggerStateUpdate;
}

modifyState(state: MapState, oldState: MapState): MapState {
Expand Down
1 change: 1 addition & 0 deletions resources/js/ui/tools/maps/controls/GeolocateControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class GeolocateControl implements Control {
};

initialise(map: Map, triggerStateUpdate: () => void) {
this.triggerStateUpdate = triggerStateUpdate;
}

modifyState(state: MapState, oldState: MapState): MapState {
Expand Down
1 change: 1 addition & 0 deletions resources/js/ui/tools/maps/controls/NavigationControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class NavigationControl implements Control {
};

initialise(map: Map, triggerStateUpdate: () => void) {
this.triggerStateUpdate = triggerStateUpdate;
}

modifyState(state: MapState, oldState: MapState): MapState {
Expand Down
7 changes: 6 additions & 1 deletion resources/js/ui/tools/maps/controls/RoutingControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class RoutingControl implements Control {

initialise(map: Map, triggerStateUpdate: () => void) {
let self = this;
this.triggerStateUpdate = triggerStateUpdate;

map.on('click', (e: MapMouseEvent) => {
if((e.originalEvent.target as HTMLElement).classList.contains('clickable') === false) {
Expand All @@ -31,6 +32,7 @@ class RoutingControl implements Control {
this.existingGeneralPopup = null;
} else {
// Otherwise, create a new popup
// TODO Set the marker the popup uses
this.existingGeneralPopup = createPopup()
.addButton('Add to Start', () => {
console.log('Add to start');
Expand Down Expand Up @@ -89,15 +91,18 @@ class RoutingControl implements Control {
.setLocation({longitude: e.lngLat.lng, latitude: e.lngLat.lat})
.create();

this.triggerStateUpdate();
}

this.triggerStateUpdate();
}
})
}

modifyState(state: MapState, oldState: MapState): MapState {
if(this.existingGeneralPopup) {
state.popups.routingGeneralPopup = this.existingGeneralPopup;
} else {
state.popups.routingGeneralPopup = null;
}
return state;
}
Expand Down
1 change: 1 addition & 0 deletions resources/js/ui/tools/maps/controls/ScaleControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class ScaleControl implements Control {
};

initialise(map: Map, triggerStateUpdate: () => void) {
this.triggerStateUpdate = triggerStateUpdate;
}

modifyState(state: MapState, oldState: MapState): MapState {
Expand Down
5 changes: 3 additions & 2 deletions resources/js/ui/tools/maps/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Map {

private _controls: Control[];

debouncedRedraw: () => void = throttle(this.redrawRaw.bind(this), 500);
debouncedRedraw: () => void = debounce(this.redrawRaw.bind(this), 50);

private stateUpdatedCallbacks: ((state: MapState) => void)[] = [];

Expand Down Expand Up @@ -191,7 +191,8 @@ class Map {
}

// Add popups to the map
let popups = Object.keys(state.popups);
let popups = Object.keys(state.popups)
.filter((key) => state.popups[key] !== null);

let popupIdsToKeep: string[] = [];
for(let popupKey of popups) {
Expand Down
2 changes: 1 addition & 1 deletion resources/js/ui/tools/maps/types/MapType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ interface MapState {
[key: string]: MapMarkerCollection
},
popups: {
[key: string]: MapMarkerPopup
[key: string]: MapMarkerPopup|null
}
}

Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"target": "es5",
"module": "es2015",
"module": "es2020",
"moduleResolution": "node",
"baseUrl": "./",
"strict": true, // Enable strict type-checking options
Expand Down

0 comments on commit 48dff5b

Please sign in to comment.