Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

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