-
-
Save Zverik/ddcfaf2da25a3dfda00a3d93a62f218d to your computer and use it in GitHub Desktop.
Fuel stations import in the UK
This file contains 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> | |
<meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no' /> | |
<style> | |
body { margin:0; padding:0; } | |
#map { position:absolute; top:0; bottom:0; width:100%; } | |
.marker-properties { | |
border-collapse:collapse; | |
/*border:1px solid #eee;*/ | |
font-size:11px; | |
margin:0; | |
} | |
.marker-properties th { | |
white-space:nowrap; | |
border:1px solid #eee; | |
padding:5px 10px; | |
} | |
.marker-properties td { | |
border:1px solid #eee; | |
padding:5px 10px; | |
} | |
.marker-properties tr:last-child td, | |
.marker-properties tr:last-child th { | |
border-bottom:none; | |
} | |
.marker-properties tr:nth-child(even) th, | |
.marker-properties tr:nth-child(even) td { | |
background-color:#f7f7f7; | |
} | |
.tag-type-heading td { | |
padding-top: 20px; | |
padding-left: 2px; | |
border-style: none; | |
font-weight:bold; | |
font-size:1.1em; | |
} | |
</style> | |
<script src='//api.tiles.mapbox.com/mapbox.js/v2.2.2/mapbox.js'></script> | |
<script src='//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js' ></script> | |
<script src='//unpkg.com/leaflet-hash@0.2.1/leaflet-hash.js'></script> | |
<link href='//api.tiles.mapbox.com/mapbox.js/v2.2.2/mapbox.css' rel='stylesheet' /> | |
</head> | |
<body> | |
<div id='map'></div> | |
<script type='text/javascript'> | |
L.mapbox.accessToken = 'pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXFhYTA2bTMyeW44ZG0ybXBkMHkifQ.gUGbDOPUN1v1fTs5SeOR4A'; | |
var map = L.mapbox.map('map'); | |
var layers = { | |
'Satellite': L.mapbox.tileLayer('mapbox.satellite'), | |
'OpenStreetMap': L.tileLayer('https://a.tile.openstreetmap.org/{z}/{x}/{y}.png', { | |
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors' | |
}) | |
}; | |
layers['OpenStreetMap'].addTo(map); | |
L.control.layers(layers, null, {collapsed: false}).addTo(map); | |
$.getJSON('map.geojson', function(geojson) { | |
var geojsonLayer = L.mapbox.featureLayer(geojson).addTo(map); | |
var bounds = geojsonLayer.getBounds(); | |
if (bounds.isValid()) { | |
map.fitBounds(geojsonLayer.getBounds()); | |
} else { | |
map.setView([0, 0], 2); | |
} | |
var hash = new L.Hash(map); | |
geojsonLayer.eachLayer(function(l) { | |
showProperties(l); | |
}); | |
}); | |
function showProperties(l) { | |
var properties = l.toGeoJSON().properties; | |
var popupContent = $("<div></div>"); | |
osm_object_link = 'new node'; | |
if (properties['action'] == 'modify') { | |
osm_id = properties['osm_type'] + '/' + properties['osm_id']; | |
osm_object_link = '<a href="http://www.openstreetmap.org/'+osm_id+'">' + | |
osm_id + '</a></p>' | |
} | |
popupContent.html( | |
'<p><span style="color:' + properties['marker-color'] + ';">' + | |
properties['action'] + | |
'</span> ' + osm_object_link + '</p>' | |
); | |
if (properties['ref_coords']) | |
popupContent.append('<p>Dataset position:' + properties['ref_coords'] + '</p>'); | |
if (properties['ref_distance']) | |
popupContent.append('<p>Distance from OSM to dataset:' + properties['ref_distance'] + ' m</p>'); | |
var table = document.createElement('table'); | |
table.setAttribute('class', 'marker-properties display') | |
lastTagType = ''; | |
for (var key in properties) { | |
if (key.startsWith('tag')) { | |
parts = key.split('.'); | |
tag_type = parts[0]; | |
osm_key = parts[1]; | |
if (tag_type!=lastTagType) { | |
var tr = createTableHeading(tag_type); | |
table.appendChild(tr); | |
lastTagType = tag_type; | |
} | |
var tr = createTableRows(osm_key, properties[key]); | |
table.appendChild(tr); | |
} | |
} | |
if (table) popupContent.append(table); | |
l.bindPopup(popupContent[0]); | |
} | |
function createTableHeading(tag_type) { | |
if (tag_type == 'tags') { | |
headingText = 'Tags:'; | |
} else if (tag_type == 'tags_changed') { | |
headingText = 'Tags to change:'; | |
} else if (tag_type == 'tags_removed') { | |
headingText = 'Tags to remove:'; | |
} else if (tag_type == 'tags_new') { | |
headingText = 'New tags to add:'; | |
} else { | |
headingText = tag_type; //unknown type | |
} | |
var tr = document.createElement('tr'); | |
var att = document.createAttribute('class'); | |
att.value = 'tag-type-heading'; | |
tr.setAttributeNode(att); | |
var td = document.createElement('td'); | |
heading = document.createTextNode(headingText); | |
td.appendChild(heading); | |
var att = document.createAttribute("colspan"); | |
att.value = "2"; | |
td.setAttributeNode(att); | |
tr.appendChild(td); | |
return tr; | |
} | |
function createTableRows(key, value) { | |
var tr = document.createElement('tr'); | |
var th = document.createElement('th'); | |
var td = document.createElement('td'); | |
key = document.createTextNode(key); | |
value = document.createTextNode(value); | |
th.appendChild(key); | |
td.appendChild(value); | |
tr.appendChild(th); | |
tr.appendChild(td); | |
return tr | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment