Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function HEREMap (mapContainer, platform, mapOptions) {
this.platform = platform;
this.position = mapOptions.center;
var defaultLayers = platform.createDefaultLayers();
// Instantiate wrapped HERE map
this.map = new H.Map(mapContainer, defaultLayers.normal.map, mapOptions);
// Basic behavior: Zooming and panning
var behavior = new H.mapevents.Behavior(new H.mapevents.MapEvents(this.map));
// Watch the user's geolocation and display it
navigator.geolocation.watchPosition(this.updateMyPosition.bind(this));
// Resize the map when the window is resized
window.addEventListener('resize', this.resizeToFit.bind(this));
}
HEREMap.prototype.updateMyPosition = function(event) {
this.position = {
lat: event.coords.latitude,
lng: event.coords.longitude
};
// Remove old location marker if it exists
if (this.myLocationMarker) {
this.removeMarker(this.myLocationMarker);
}
this.myLocationMarker = this.addMarker(this.position);
this.map.setCenter(this.position);
};
HEREMap.prototype.addMarker = function(coordinates) {
var marker = new H.map.Marker(coordinates);
this.map.addObject(marker);
return marker;
};
HEREMap.prototype.removeMarker = function(marker) {
this.map.removeObject(marker);
};
HEREMap.prototype.resizeToFit = function() {
this.map.getViewPort().resize();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.