-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLR_Mexico_Municipalities.HTML
181 lines (149 loc) · 4.92 KB
/
LR_Mexico_Municipalities.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<html>
<head>
<title>Leaflet BEJERANO MEXICO</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.css" />
<link rel="stylesheet" href="http://leaflet.github.io/Leaflet.draw/leaflet.draw.css"/>
<style type="text/css">
</style>
<script src="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.js"></script>
<script src="http://code.jquery.com/jquery-2.1.0.min.js"></script>
<!--<link rel="points" type="application/json" href="https://rawgit.com/boehnert/GeoJson/master/coolPlaces.geojson">
<script src="https://rawgit.com/boehnert/GeoJson/master/coolPlaces.geojson" type="text/javascript" > </script>
<script src="https://rawgit.com/boehnert/GeoJson/master/HeatIndex.geojson" type="text/javascript" > </script> -->
<style>
#map {
width: 1800px;
height: 1000px;
}
.info {
padding: 6px 8px;
font: 14px/16px Arial, Helvetica, sans-serif;
background: white;
background: rgba(255,255,255,0.8);
box-shadow: 0 0 15px rgba(0,0,0,0.2);
border-radius: 5px;
}
.info h4 {
margin: 0 0 5px;
color: #777;
}
.info.legend {
background-color: white;
}
}
.legend i {
width: 18px;
height: 18px;
float: left;
margin-right: 8px;
background-color: white;
opacity: 0.9;
}
</style>
</head>
<body>
<div id="map" ></div>
<script>
var map = L.map('map').setView([23.4325, -101.1329], 6);
L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpandmbXliNDBjZWd2M2x6bDk3c2ZtOTkifQ._QA7i5Mpkd_m30IGElHziw', {
maxZoom: 18,
attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, ' +
'<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ' +
'Imagery © <a href="http://mapbox.com">Mapbox</a>',
id: 'mapbox.light'
}).addTo(map);
//access geojson for zip codes using jQuery method getJSON
$.getJSON("https://raw.githubusercontent.com/Pre60/myTest/master/MEX_adm2.json", function(data) {
var Mex_zipcodes = L.geoJson(data, {
style: style,
onEachFeature: onEachFeature
}).addTo(map);
var info = L.control();
info.onAdd = function (map) {
this._div = L.DomUtil.create('div', 'info');
this.update();
return this._div;
};
info.update = function (props) {
this._div.innerHTML = '<h4>Loss Ratio Municipio</h4>' + (props ?
'<b>' + props.NAME_2 + '</b><br />' + props.LOSS_RATIO + ' Loss Ratio x 100</sup>'
: 'Hover over the zipcode');
};
info.addTo(map);
function highlightFeature(e) {
var layer = e.target;
layer.setStyle({
weight: 3,
color: '#666',
dashArray: '',
fillOpacity: 0.7
});
if (!L.Browser.ie && !L.Browser.opera) {
layer.bringToFront();
}
info.update(layer.feature.properties);
} //hasta aqui function highlight
function resetHighlight(e) {
Mex_zipcodes.resetStyle(e.target);
info.update();
}
function zoomToFeature(e) {
map.fitBounds(e.target.getBounds());
}
function onEachFeature(feature, layer) {
layer.on({
mouseover: highlightFeature,
mouseout: resetHighlight,
click: zoomToFeature
});
};
function getColor(d) {
return d > 1.1 ? '#000004' :
d > 1.04 ? '#3B0F70' :
d > 0.98 ? '#471078' :
d > 0.92 ? '#6A1C81' :
d > 0.86 ? '#902A81' :
d > 0.8 ? '#AB337C' :
d > 0.74 ? '#BC3978' :
d > 0.68 ? '#CC3F71' :
d > 0.62 ? '#DB476A' :
d > 0.56 ? '#E44F64' :
d > 0.5 ? '#E75263' :
d > 0.44 ? '#F1605D' :
d > 0.38 ? '#F66C5C' :
d > 0.32 ? '#FD9A6A' :
d > 0.26 ? '#FEBF84' :
'#FED597';
}
function style(feature) {
return {
weight: 0.5,
opacity: 1,
color: 'white',
dashArray: '3',
fillOpacity: 0.7,
fillColor: getColor(feature.properties.LOSS_RATIO)};}
} );
//Add legend
var legend = L.control({position: 'bottomleft'});
legend.onAdd = function (map) {
var div = L.DomUtil.create('div', 'info legend'),
grades = [0.2, 0.26, 0.32, 0.38, 0.44, 0.5, 0.56, 0.62, 0.68, 0.74, 0.8, 0.86, 0.92, 0.98, 1.04, 1.1],
labels = [],
from, to;
for (var i = 0; i < grades.length; i++) {
from = grades[i];
to = grades[i + 1];
labels.push(
'<i style="background:' + getColor(from + 1) + '">[color]</i> ' +
from + (to ? '–' + to : '+'));
}
div.innerHTML = labels.join('<br>');
return div;
};
legend.addTo(map);
</script>
</body>
</html>