Skip to content

Instantly share code, notes, and snippets.

@LarsBergqvist
Created January 23, 2021 12:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LarsBergqvist/f723d7f57e2c6d7de2ff3e9ff2f8f78b to your computer and use it in GitHub Desktop.
Save LarsBergqvist/f723d7f57e2c6d7de2ff3e9ff2f8f78b to your computer and use it in GitHub Desktop.
Update an OpenLayers map with markers
private setupMap(input: MapInput) {
this.positions = input.markerPosisitons;
this.userPos = input.userPos;
if (!this.map) {
this.initilizeMap();
}
const view = this.map.getView();
if (this.positions.length > 0) {
view.setCenter(fromLonLat([this.positions[0].lng, this.positions[0].lat]));
} else if (this.userPos && this.userPos.lat && this.userPos.lng) {
view.setCenter(fromLonLat([this.userPos.lng, this.userPos.lat]));
}
const zoomLevel =
this.positions.length < 2 ? MapComponent.ZoomLevelSingleMarker : MapComponent.ZoomLevelSeveralMarkers;
view.setZoom(zoomLevel);
this.updateMarkers(this.positions, true);
this.updateUserMarker(this.userPos);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment