Last active
August 29, 2015 14:13
-
-
Save pgiraud/f2f69246630f39fa3ce5 to your computer and use it in GitHub Desktop.
OpenLayers - Geolocation spoofer
This file contains hidden or 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
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <link rel="stylesheet" href="style.css"> | |
| <script src="http://openlayers.org/en/master/build/ol.js"></script> | |
| </head> | |
| <body> | |
| <div id="map"></div> | |
| <textarea id="positions"></textarea> | |
| </body> | |
| <script src="script.js"></script> | |
| </html> |
This file contains hidden or 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
| var projection = ol.proj.get('EPSG:3857'); | |
| var view = new ol.View({ | |
| center: [0, 0], | |
| projection: projection, | |
| extent: projection.getExtent(), | |
| zoom: 2 | |
| }); | |
| var map = new ol.Map({ | |
| layers: [ | |
| new ol.layer.Tile({ | |
| source: new ol.source.OSM() | |
| }) | |
| ], | |
| target: 'map', | |
| controls: ol.control.defaults({ | |
| attributionOptions: /** @type {olx.control.AttributionOptions} */ ({ | |
| collapsible: false | |
| }) | |
| }), | |
| view: view | |
| }); | |
| var vectorLayer = new ol.layer.Vector({ | |
| source: new ol.source.GeoJSON({ | |
| projection: 'EPSG:3857', | |
| url: 'zones.json' | |
| }) | |
| }); | |
| map.addLayer(vectorLayer); | |
| var source = vectorLayer.getSource(); | |
| var listenerKey = source.on('change', function() { | |
| if (source.getState() == 'ready') { | |
| var extent = source.getExtent(); | |
| map.getView().fitExtent(source.getExtent(), map.getSize()); | |
| source.unByKey(listenerKey); | |
| } | |
| }); | |
| var positions = []; | |
| map.on('singleclick', function(evt) { | |
| positions.push(evt.coordinate); | |
| document.getElementById('positions').value = JSON.stringify(positions, undefined, 2); | |
| }); |
This file contains hidden or 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
| #map { | |
| width: 600px; | |
| height: 400px; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment