Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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