Update an OpenLayers map with markers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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