-
Notifications
You must be signed in to change notification settings - Fork 4
/
leaflet-geojson-tile-layer-demo.html
77 lines (73 loc) · 2.96 KB
/
leaflet-geojson-tile-layer-demo.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<!DOCTYPE html>
<html>
<head>
<title>US States - Leaflet GeoJSON Tile Layer Example - glenrobertson’s block #6203331</title>
<link rel="stylesheet" href="http://leafletjs.com/dist/leaflet.css" />
<!--[if lte IE 8]> <link rel="stylesheet" href="http://leafletjs.com/static/leaflet/leaflet.ie.css" /> <![endif]-->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="http://leafletjs.com/dist/leaflet.js"></script>
<script src="js/TileLayer.GeoJSON.js"></script>
<style>html,body,.content,#leaflet-map{margin:0; padding:0; width:100%; height:100%}
.content{position:relative}
h1,cite,a{margin:0; padding:0; width:100%; height:120px; font-size:64px}
h1{background-color:#fff; position:absolute; top:0; left:0; font-weight:300; letter-spacing:-2px; margin:.3em 0 .1em 0}
h1 a{color:#000; display:block}
h1 cite{font-style:normal}
</style>
</head>
<body>
<div class="content">
<div id="leaflet-map"></div>
<script>
var map = new L.Map('leaflet-map'),
cloudmadeUrl = 'http://{s}.tile.cloudmade.com/1a1b06b230af4efdbb989ea99e9841af/997/256/{z}/{x}/{y}.png',
cloudmadeAttribution = 'Map data © 2011 OpenStreetMap contributors, Imagery © 2011 CloudMade';
map.setView(new L.LatLng(38.617, -100.261), 4);
var baseLayer = new L.TileLayer(cloudmadeUrl, { attribution: cloudmadeAttribution});
map.addLayer(baseLayer);
var style = {
"clickable": true,
"color": "#00D",
"fillColor": "#00D",
"weight": 1.0,
"opacity": 0.3,
"fillOpacity": 0.2
};
var hoverStyle = {
"fillOpacity": 0.5
};
var geojsonURL = 'http://polymaps.appspot.com/state/{z}/{x}/{y}.json';
var geojsonTileLayer = new L.TileLayer.GeoJSON(geojsonURL, {
clipTiles: true,
unique: function (feature) {
return feature.id;
}
}, {
style: style,
onEachFeature: function (feature, layer) {
if (feature.properties) {
var popupString = '<div class="popup">';
for (var k in feature.properties) {
var v = feature.properties[k];
popupString += k + ': ' + v + '<br />';
}
popupString += '</div>';
layer.bindPopup(popupString);
}
if (!(layer instanceof L.Point)) {
layer.on('mouseover', function () {
layer.setStyle(hoverStyle);
});
layer.on('mouseout', function () {
layer.setStyle(style);
});
}
}
}
);
map.addLayer(geojsonTileLayer);
</script>
<h1><cite><a href="http://bl.ocks.org/glenrobertson/6203331">US States - Leaflet GeoJSON Tile Layer Example</a></cite></h1>
</div>
</body>
</html>