Created
October 27, 2016 10:57
-
-
Save here-devblog-gists/e3bf03616d0d6242894c35a6a5ed1e26 to your computer and use it in GitHub Desktop.
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
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