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
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
9.389655392000064,
11.609017976000073
],
[
9.390877940000049,
11.608662704000038
],
[
9.391544138000027,
11.607758699000042
],
[
9.391630272000041,
11.607086469000022
],
[
9.39138684100004,
11.606295301000042
],
[
9.392275100000061,
11.606181038000042
],
[
9.392834212000023,
11.605836373000043
],
[
9.394256070000038,
11.606051202000058
],
[
9.394782645000019,
11.605826547000046
],
[
9.395407041000054,
11.605171008000067
],
[
9.395630254000023,
11.604186469000066
],
[
9.395407031000046,
11.60342898300007
],
[
9.394968950000019,
11.60290690600004
],
[
9.393915151000042,
11.602495563000046
],
[
9.393136979000074,
11.602614676000028
],
[
9.392768947000034,
11.602206905000056
],
[
9.391715151000026,
11.601795562000062
],
[
9.39083252800003,
11.601958374000047
],
[
9.390413004000036,
11.600847533000032
],
[
9.389456058000063,
11.600248799000038
],
[
9.388543940000032,
11.600248799000038
],
[
9.387635668000028,
11.600793102000067
],
[
9.387106849000073,
11.60085942200004
],
[
9.386683462000063,
11.600384365000021
],
[
9.387283610000052,
11.599862715000027
],
[
9.387595941000027,
11.599162660000044
],
[
9.38878081000007,
11.59903592900002
],
[
9.389212409000036,
11.598755296000032
],
[
9.389843941000036,
11.599051203000043
],
[
9.390975078000052,
11.598981040000066
],
[
9.391906997000033,
11.598171009000051
],
[
9.392076208000047,
11.596850362000053
],
[
9.39155533200005,
11.595982018000027
],
[
9.390866678000064,
11.595580484000035
],
[
9.390070160000048,
11.595506251000073
],
[
9.38908759000003,
11.595944707000054
],
[
9.388229838000028,
11.595606249000067
],
[
9.387433320000069,
11.595680482000033
],
[
9.386744665000036,
11.596082016000022
],
[
9.386204069000028,
11.59703734100003
],
[
9.385456376000034,
11.597024020000047
],
[
9.38463142000006,
11.597406642000063
],
[
9.383882610000054,
11.596473450000072
],
[
9.383106904000043,
11.596204116000022
],
[
9.382906980000028,
11.59502898100004
],
[
9.38228260200003,
11.594373448000052
],
[
9.381643620000032,
11.594124018000056
],
[
9.380624930000065,
11.594218957000065
],
[
9.380044671000062,
11.594582017000048
],
[
9.379608214000028,
11.595204235000038
],
[
9.378619200000058,
11.595364066000055
],
[
9.377793013000028,
11.596128981000046
],
[
9.377566176000071,
11.596999993000052
],
[
9.377694950000032,
11.597665565000055
],
[
9.378144655000026,
11.598317975000041
],
[
9.378943944000067,
11.598751202000072
],
[
9.379668956000044,
11.598787639000019
],
[
9.380086998000023,
11.599852464000035
],
[
9.38104393900005,
11.600451205000068
],
[
9.381956057000023,
11.600451205000068
],
[
9.38294917400003,
11.599806482000075
],
[
9.384068574000024,
11.599393365000022
],
[
9.38501918600002,
11.600435931000048
],
[
9.38429492600005,
11.601634423000062
],
[
9.38419862200004,
11.602638780000062
],
[
9.38537015600002,
11.604406251000054
],
[
9.384617362000027,
11.604673448000026
],
[
9.383855877000029,
11.60564128900006
],
[
9.383823729000026,
11.606649625000042
],
[
9.384263151000026,
11.607437659000025
],
[
9.384924899000053,
11.607881037000025
],
[
9.385600001000054,
11.608008002000073
],
[
9.386567239000042,
11.607735529000022
],
[
9.386851587000022,
11.608668774000021
],
[
9.387367890223365,
11.60919341210245
],
[
9.389432109776754,
11.60919341210245
],
[
9.389655392000064,
11.609017976000073
]
],
[
[
9.388536837000059,
11.60446233400006
],
[
9.388964340000028,
11.603806901000038
],
[
9.389767462000064,
11.60364163200006
],
[
9.389798610000069,
11.60483878000002
],
[
9.390013172000065,
11.605404699000072
],
[
9.389027763000056,
11.605560403000023
],
[
9.388536837000059,
11.60446233400006
]
]
]
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
9.360455275000048,
11.582517978000052
],
[
9.361699998000061,
11.582908005000034
],
[
9.362480763000063,
11.582735931000055
],
[
9.363306904000066,
11.581971008000036
],
[
9.36351926000003,
11.58132659600005
],
[
9.363359193000063,
11.58033018100002
],
[
9.36286884900005,
11.579706902000051
],
[
9.362077827000062,
11.57913729000006
],
[
9.361115140000036,
11.578795561000046
],
[
9.360433355000051,
11.578880483000033
],
[
9.359597506000055,
11.579435897000051
],
[
9.358419245000047,
11.579564065000053
],
[
9.357593104000042,
11.580328982000024
],
[
9.357366280000061,
11.581199994000029
],
[
9.357593094000036,
11.582071010000046
],
[
9.358122161000038,
11.582662706000061
],
[
9.35920000100003,
11.583008007000043
],
[
9.360455275000048,
11.582517978000052
]
]
]
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
9.366483573000037,
11.593337277000042
],
[
9.365675063000024,
11.592718958000031
],
[
9.364433324000059,
11.592680484000025
],
[
9.363547612000046,
11.593297634000063
],
[
9.362584855000021,
11.593095563000075
],
[
9.361363216000028,
11.59366233300005
],
[
9.360923805000025,
11.594450363000018
],
[
9.360955940000052,
11.59545870000005
],
[
9.36136320400004,
11.596137663000034
],
[
9.362285486000072,
11.596660358000062
],
[
9.362294948000054,
11.597965566000026
],
[
9.362744654000037,
11.598617976000067
],
[
9.364,
11.599108005000058
],
[
9.365077901000062,
11.598762705000068
],
[
9.366183599000065,
11.597662715000066
],
[
9.366530203000023,
11.596486469000066
],
[
9.36628364100005,
11.59569006400005
],
[
9.366801325000038,
11.594738781000045
],
[
9.366801321000024,
11.594061208000026
],
[
9.366483573000037,
11.593337277000042
]
]
]
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
9.357482542000069,
11.57692654900006
],
[
9.358048235000068,
11.576368774000056
],
[
9.358330064000027,
11.575286467000067
],
[
9.358106864000034,
11.574528980000022
],
[
9.357175020000053,
11.573718955000057
],
[
9.356157693000055,
11.573623815000072
],
[
9.354870178000054,
11.573306250000027
],
[
9.354216620000043,
11.57351563000003
],
[
9.353493136000052,
11.57422898200002
],
[
9.353266317000019,
11.575099995000071
],
[
9.353356060000065,
11.575658701000064
],
[
9.353844751000052,
11.576417979000038
],
[
9.354533356000044,
11.576819518000033
],
[
9.355442301000037,
11.576876187000037
],
[
9.35615640000003,
11.577175982000025
],
[
9.357482542000069,
11.57692654900006
]
]
]
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
9.373280812000074,
11.600035931000034
],
[
9.374205058000028,
11.599065566000034
],
[
9.374330549000033,
11.598503004000062
],
[
9.37498080900002,
11.598335933000042
],
[
9.375859297000032,
11.597469808000024
],
[
9.376033823000055,
11.596699996000039
],
[
9.375806986000041,
11.595828984000033
],
[
9.376084856000032,
11.595404439000047
],
[
9.376766681000047,
11.595319516000071
],
[
9.377536792000054,
11.59483766300002
],
[
9.378030186000045,
11.593713521000039
],
[
9.377859271000032,
11.592830185000023
],
[
9.377368905000024,
11.592206906000055
],
[
9.376531306000059,
11.59182209700003
],
[
9.37618356100006,
11.590837275000068
],
[
9.375043615000036,
11.590124017000047
],
[
9.373919214000066,
11.590264064000051
],
[
9.373289069000064,
11.590745265000063
],
[
9.37236894500006,
11.590081292000034
],
[
9.372730155000054,
11.589113522000046
],
[
9.372383548000071,
11.587937279000071
],
[
9.371466664000023,
11.587280485000063
],
[
9.370670170000038,
11.587206252000042
],
[
9.36923333800007,
11.587380483000057
],
[
9.368193059000019,
11.58822898200003
],
[
9.367680682000067,
11.589973391000054
],
[
9.368087043000058,
11.59135246300002
],
[
9.36871921000005,
11.591835931000047
],
[
9.369536638000055,
11.59200687100002
],
[
9.369480665000024,
11.592726598000066
],
[
9.369887032000063,
11.593652464000057
],
[
9.37095638000005,
11.594275982000054
],
[
9.371669057000075,
11.594270376000052
],
[
9.371280649000026,
11.595173393000035
],
[
9.37127772900004,
11.596396228000058
],
[
9.370144661000039,
11.596882019000073
],
[
9.369655925000073,
11.597641291000055
],
[
9.369655918000033,
11.598758700000072
],
[
9.369916393000038,
11.599262716000052
],
[
9.370724917000073,
11.599881041000057
],
[
9.372499999000066,
11.600208005000066
],
[
9.373280812000074,
11.600035931000034
]
]
]
}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment