Skip to content

Instantly share code, notes, and snippets.

@pgiraud
Last active August 29, 2015 14:13
Show Gist options
  • Select an option

  • Save pgiraud/f2f69246630f39fa3ce5 to your computer and use it in GitHub Desktop.

Select an option

Save pgiraud/f2f69246630f39fa3ce5 to your computer and use it in GitHub Desktop.
OpenLayers - Geolocation spoofer
<!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>
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);
});
#map {
width: 600px;
height: 400px;
}
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment