-
Notifications
You must be signed in to change notification settings - Fork 36
/
scripts.js
61 lines (47 loc) · 1.39 KB
/
scripts.js
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
(function() {
var map = L.map('map', {
attributionControl: false
});
L.tileLayer('http://{s}.tile.stamen.com/{style}/{z}/{x}/{y}.png', { style: 'toner-background' }).addTo(map);
$.getJSON("states.min.geojson", function(data) {
var info = L.control();
info.update = function (props) {
this._div.innerHTML = (props ? '<b>' + props['STATE_NAME'] + '</b>' : 'Hover over a state');
};
info.onAdd = function (map) {
this._div = L.DomUtil.create('div', 'info'); // create a div with a class "info"
this.update();
return this._div;
};
info.addTo(map);
var geojson = L.geoJson(data, {
style: function (feature) {
return {
color: '#3498db',
weight: 2,
fillOpacity: 0.5
};
},
onEachFeature: function (feature, layer) {
// layer.bindPopup(feature.properties['STATE_NAME']);
layer
.on('mouseover', function(e) {
layer.setStyle({
weight: 4,
fillOpacity: 0.8
});
info.update(layer.feature.properties);
})
.on('mouseout', function(e) {
geojson.resetStyle(layer);
info.update();
})
}
})
geojson.addTo(map);
var bounds = geojson.getBounds();
map.fitBounds(bounds);
map.options.maxBounds = bounds;
map.options.minZoom = map.getZoom();
});
})();