-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathindex.html
48 lines (42 loc) · 1.62 KB
/
index.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
<html>
<head>
<title>México - Mapa</title>
<meta charset="UTF-8">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.3/leaflet.css"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.3/leaflet.js"></script>
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<style>
#map{ height: 100% }
</style>
</head>
<body>
<div id="map"></div>
<script>
var map = new L.Map("map", {center: [19.4326, -99.13], zoom: 5})
.addLayer(new L.TileLayer("http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"));
$.getJSON("states.geojson",function(data){
L.geoJson(data).addTo(map);
});
var munjson;
$.getJSON("municipalities.geojson", setgeoJson);
function setgeoJson(data)
{
var geoJsonLayer = L.geoJson(data, {
style: function(feature){
var fillColor;
colors = ["#85C1E9", "#A9CCE3", "#3498DB", "#2E86C1", "#2874A6"];
fillColor = colors[Math.floor(Math.random() * colors.length)];
return { color: "#fff", weight: 0.2, fillColor: fillColor, fillOpacity: .5 };
},
onEachFeature: function(feature, layer){
layer.bindPopup( "<strong>" + feature.properties.mun_name + "</strong><br/> Código de municipio: " + feature.properties.mun_code + "<br/> Código de estado: " + feature.properties.state_code )
}
}
).addTo(map);
geoJsonLayer.eachLayer(function (layer) {
layer._path.id = 'estado' + layer.feature.properties.state_code+'-mun'+layer.feature.properties.mun_code;
});
}
</script>
</body>
</html>