summaryrefslogtreecommitdiff
path: root/misc/openlayers/examples/geolocation.js
diff options
context:
space:
mode:
authorChris Schlaeger <chris@linux.com>2014-08-12 21:56:44 +0200
committerChris Schlaeger <chris@linux.com>2014-08-12 21:56:44 +0200
commitea346a785dc1b3f7c156f6fc33da634e1f1a627b (patch)
treeaf67530553d20b6e82ad60fd79593e9c4abf5565 /misc/openlayers/examples/geolocation.js
parent59741cd535c47f25971bf8c32b25da25ceadc6d5 (diff)
downloadpostrunner-ea346a785dc1b3f7c156f6fc33da634e1f1a627b.zip
Adding jquery, flot and openlayers to be included with the GEM.v0.0.4
Diffstat (limited to 'misc/openlayers/examples/geolocation.js')
-rw-r--r--misc/openlayers/examples/geolocation.js112
1 files changed, 112 insertions, 0 deletions
diff --git a/misc/openlayers/examples/geolocation.js b/misc/openlayers/examples/geolocation.js
new file mode 100644
index 0000000..3d8d6f4
--- /dev/null
+++ b/misc/openlayers/examples/geolocation.js
@@ -0,0 +1,112 @@
+var style = {
+ fillColor: '#000',
+ fillOpacity: 0.1,
+ strokeWidth: 0
+};
+
+var map = new OpenLayers.Map('map');
+var layer = new OpenLayers.Layer.OSM( "Simple OSM Map");
+var vector = new OpenLayers.Layer.Vector('vector');
+map.addLayers([layer, vector]);
+
+map.setCenter(
+ new OpenLayers.LonLat(-71.147, 42.472).transform(
+ new OpenLayers.Projection("EPSG:4326"),
+ map.getProjectionObject()
+ ), 12
+);
+
+var pulsate = function(feature) {
+ var point = feature.geometry.getCentroid(),
+ bounds = feature.geometry.getBounds(),
+ radius = Math.abs((bounds.right - bounds.left)/2),
+ count = 0,
+ grow = 'up';
+
+ var resize = function(){
+ if (count>16) {
+ clearInterval(window.resizeInterval);
+ }
+ var interval = radius * 0.03;
+ var ratio = interval/radius;
+ switch(count) {
+ case 4:
+ case 12:
+ grow = 'down'; break;
+ case 8:
+ grow = 'up'; break;
+ }
+ if (grow!=='up') {
+ ratio = - Math.abs(ratio);
+ }
+ feature.geometry.resize(1+ratio, point);
+ vector.drawFeature(feature);
+ count++;
+ };
+ window.resizeInterval = window.setInterval(resize, 50, point, radius);
+};
+
+var geolocate = new OpenLayers.Control.Geolocate({
+ bind: false,
+ geolocationOptions: {
+ enableHighAccuracy: false,
+ maximumAge: 0,
+ timeout: 7000
+ }
+});
+map.addControl(geolocate);
+var firstGeolocation = true;
+geolocate.events.register("locationupdated",geolocate,function(e) {
+ vector.removeAllFeatures();
+ var circle = new OpenLayers.Feature.Vector(
+ OpenLayers.Geometry.Polygon.createRegularPolygon(
+ new OpenLayers.Geometry.Point(e.point.x, e.point.y),
+ e.position.coords.accuracy/2,
+ 40,
+ 0
+ ),
+ {},
+ style
+ );
+ vector.addFeatures([
+ new OpenLayers.Feature.Vector(
+ e.point,
+ {},
+ {
+ graphicName: 'cross',
+ strokeColor: '#f00',
+ strokeWidth: 2,
+ fillOpacity: 0,
+ pointRadius: 10
+ }
+ ),
+ circle
+ ]);
+ if (firstGeolocation) {
+ map.zoomToExtent(vector.getDataExtent());
+ pulsate(circle);
+ firstGeolocation = false;
+ this.bind = true;
+ }
+});
+geolocate.events.register("locationfailed",this,function() {
+ OpenLayers.Console.log('Location detection failed');
+});
+document.getElementById('locate').onclick = function() {
+ vector.removeAllFeatures();
+ geolocate.deactivate();
+ document.getElementById('track').checked = false;
+ geolocate.watch = false;
+ firstGeolocation = true;
+ geolocate.activate();
+};
+document.getElementById('track').onclick = function() {
+ vector.removeAllFeatures();
+ geolocate.deactivate();
+ if (this.checked) {
+ geolocate.watch = true;
+ firstGeolocation = true;
+ geolocate.activate();
+ }
+};
+document.getElementById('track').checked = false;