-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnappes.html
More file actions
183 lines (145 loc) · 3.9 KB
/
Copy pathnappes.html
File metadata and controls
183 lines (145 loc) · 3.9 KB
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
182
183
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.3.0/dist/leaflet.css" />
<link rel="stylesheet" href="src/leaflet-search.css" />
<link rel="stylesheet" href="style.css" />
<style>
#map {
width: 600px;
height: 400px;
background-color: white;
}
.info {
padding: 6px 8px;
font: 14px/16px Arial, Helvetica, sans-serif;
color: black;
background: white;
background: rgba(255,255,255,0.8);
box-shadow: 0 0 15px rgba(0,0,0,0.2);
border-radius: 5px;
position: relative;
right: 280px;
}
.info h4 {
margin: 0 0 5px;
color: #777;
}
.legend {
position: relative;
left :2px;
}
.legend i {
width: 12px;
height: 12px;
float: left;
margin-right: 8px;
opacity: 1;
}
</style>
</head>
<body>
<div id='map'></div>
<script src="src/leaflet.js"></script>
<script src="src/leaflet-search.js"></script>
<script src="js/napperep.js"></script>
<script>
//sample data values define in us-states.js
var data = napperep;
var map = L.map('map').setView([28.4937, -9.283], 5);
var tiles = L.tileLayer('http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png').addTo(map);
function getColor(d) {
return d > 20
? "#73dffff"
: d > 15
? "#73dfff"
: d > 10
? "#73dfff"
: d > 5
? "#73dfff"
: d > 2
? "#73dfff"
: "#73dfff";
}
function Monstyle(feature) {
return {
weight: 1,
opacity: 1,
color: 'black',
dashArray: '',
fillOpacity: 1,
fillColor: getColor(feature.properties.pib)
};
}
function highlightFeature(e) {
var layer = e.target;
layer.setStyle({
weight: 5,
color: '#666',
dashArray: '',
fillOpacity: 0.7
});
if (!L.Browser.ie && !L.Browser.opera && !L.Browser.edge) {
layer.bringToFront();
}
info.update(layer.feature.properties);
}
function resetHighlight(e) {
geojson.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
});
}
var info = L.control();
info.onAdd = function (map) {
this._div = L.DomUtil.create('div', 'info'); // create a div with a class "info"
this.update();
return this._div;
};
// method that we will use to update the control based on feature properties passed
info.update = function (props) {
this._div.innerHTML = '<h4>Nappes du Maroc</h4>' + (props ?
'Nom : <b>' + props.NomNappe+ '</b> <br />Code : ' + props.CodeNappe+ '</b> <br />ID : ' + props.FID_Napes+' </sup>'
: 'Merci de mettre le cursuer sur la nappe');
};
info.addTo(map);
var geojson = L.geoJson(data, {
style: Monstyle,
onEachFeature: onEachFeature,
}).addTo(map);
map.addLayer(geojson);
var searchControl = new L.Control.Search({
layer: geojson,
propertyName: 'Région',
marker: false,
moveToLocation: function(latlng, title, map) {
//map.fitBounds( latlng.layer.getBounds() );
var zoom = map.getBoundsZoom(latlng.layer.getBounds());
map.setView(latlng, zoom); // access the zoom
}
});
searchControl.on('search:locationfound', function(e) {
//console.log('search:locationfound', );
//map.removeLayer(this._markerSearch)
e.layer.setStyle({fillColor: '#3f0', color: '#0f0'});
if(e.layer._popup)
e.layer.openPopup();
}).on('search:collapsed', function(e) {
geojson.eachLayer(function(layer) { //restore feature color
geojson.resetStyle(layer);
});
});
map.addControl( searchControl ); //inizialize search control
</script>
</body>
</html>