Skip to content

Commit

Permalink
Merge pull request stadiamaps#154 from CatMe0w/patch-marker-fix
Browse files Browse the repository at this point in the history
Fix duplicated markers in web
  • Loading branch information
ianthetechie authored Jul 16, 2024
2 parents a01e5c2 + 76e4b17 commit 841eefd
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion web/src/ferrostar-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class FerrostarCore extends LitElement {
}

updated(changedProperties: any) {
if (changedProperties.has('locationProvider') && this.locationProvider) {
if (changedProperties.has("locationProvider") && this.locationProvider) {
this.locationProvider.updateCallback = this.onLocationUpdated.bind(this);
}
}
Expand Down Expand Up @@ -113,6 +113,8 @@ class FerrostarCore extends LitElement {
const initialTripState = this.navigationController.getInitialState(startingLocation);
this.handleStateUpdate(initialTripState, startingLocation);

this.resetMap();

const polyline = L.polyline(route.geometry, { color: "red" }).addTo(this.map!);
this.map!.fitBounds(polyline.getBounds());

Expand All @@ -139,6 +141,14 @@ class FerrostarCore extends LitElement {
this.currentLocationMapMarker!.setLatLng(this.locationProvider.lastLocation.coordinates);
}

private resetMap() {
this.map!.eachLayer((layer) => {
if (layer instanceof L.Marker || layer instanceof L.Polyline) {
this.map!.removeLayer(layer);
}
});
}

render() {
return html`<div id="map"></div>`;
}
Expand Down

0 comments on commit 841eefd

Please sign in to comment.