Any event target can be used to dispatch generic goog.events.Event instances with an arbitrary type. In cases where we dispatch custom events, we should not use type values that collide with those used for generic events (at least internally). This allows listeners a better chance of knowing what kind of argument they will receive. As subsequent change will clean up the enumeration and add a bit more consistency.
59 lines
1.6 KiB
JavaScript
59 lines
1.6 KiB
JavaScript
goog.require('ol.Geolocation');
|
|
goog.require('ol.Map');
|
|
goog.require('ol.Overlay');
|
|
goog.require('ol.OverlayPositioning');
|
|
goog.require('ol.RendererHints');
|
|
goog.require('ol.View2D');
|
|
goog.require('ol.dom.Input');
|
|
goog.require('ol.layer.Tile');
|
|
goog.require('ol.source.OSM');
|
|
|
|
|
|
var map = new ol.Map({
|
|
layers: [
|
|
new ol.layer.Tile({
|
|
source: new ol.source.OSM()
|
|
})
|
|
],
|
|
renderers: ol.RendererHints.createFromQueryData(),
|
|
target: 'map',
|
|
view: new ol.View2D({
|
|
center: [0, 0],
|
|
zoom: 2
|
|
})
|
|
});
|
|
|
|
var geolocation = new ol.Geolocation();
|
|
geolocation.bindTo('projection', map.getView());
|
|
|
|
var track = new ol.dom.Input(document.getElementById('track'));
|
|
track.bindTo('checked', geolocation, 'tracking');
|
|
|
|
geolocation.on('propertychange', function() {
|
|
$('#accuracy').text(geolocation.getAccuracy() + ' [m]');
|
|
$('#altitude').text(geolocation.getAltitude() + ' [m]');
|
|
$('#altitudeAccuracy').text(geolocation.getAltitudeAccuracy() + ' [m]');
|
|
$('#heading').text(geolocation.getHeading() + ' [rad]');
|
|
$('#speed').text(geolocation.getSpeed() + ' [m/s]');
|
|
});
|
|
|
|
var marker = new ol.Overlay({
|
|
element: /** @type {Element} */ ($('<i/>').addClass('icon-flag').get(0)),
|
|
positioning: ol.OverlayPositioning.BOTTOM_LEFT,
|
|
stopEvent: false
|
|
});
|
|
map.addOverlay(marker);
|
|
// bind the marker position to the device location.
|
|
marker.bindTo('position', geolocation);
|
|
|
|
geolocation.on('change:accuracy', function() {
|
|
$(marker.getElement()).tooltip({
|
|
title: this.getAccuracy() + 'm from this point'
|
|
});
|
|
});
|
|
geolocation.on('error', function(error) {
|
|
var info = document.getElementById('info');
|
|
info.innerHTML = error.message;
|
|
info.style.display = '';
|
|
});
|