1646 |
alex |
1 |
var map = null,
|
|
|
2 |
optionsCoucheOSM = {
|
|
|
3 |
attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors,'
|
|
|
4 |
+ ' <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>',
|
|
|
5 |
maxZoom: 18
|
|
|
6 |
},
|
|
|
7 |
optionsCoucheGoogle = {
|
|
|
8 |
attribution: 'Map data ©'+new Date().getFullYear()+' <a href="http://maps.google.com">Google</a>',
|
|
|
9 |
maxZoom: 18
|
|
|
10 |
},
|
1809 |
mathias |
11 |
coucheOSM = new L.TileLayer("http://osm.tela-botanica.org/tuiles/osmfr/{z}/{x}/{y}.png",
|
|
|
12 |
optionsCoucheOSM),
|
1646 |
alex |
13 |
coucheSatellite = new L.TileLayer("http://mt1.google.com/vt/lyrs=y@218131653&hl=fr&src=app&x={x}&y={y}&z={z}",
|
|
|
14 |
optionsCoucheGoogle),
|
|
|
15 |
optionsCarte = {
|
|
|
16 |
center : new L.LatLng(46, 2),
|
|
|
17 |
zoom : 6,
|
1797 |
aurelien |
18 |
layers : [coucheOSM]
|
1646 |
alex |
19 |
};
|
|
|
20 |
|
|
|
21 |
var xmlHttpRequest = null,
|
|
|
22 |
nombreCollections = 0,
|
|
|
23 |
collections = new Array(),
|
|
|
24 |
structures = new Array(),
|
|
|
25 |
coucheStructures = new L.FeatureGroup(),
|
|
|
26 |
infoBulle = null,
|
|
|
27 |
chargementEnCours = false;
|
|
|
28 |
|
|
|
29 |
|
|
|
30 |
$(document).ready(function() {
|
1701 |
raphael |
31 |
dimensionnerCarte();
|
|
|
32 |
initialiserCarte();
|
|
|
33 |
initialiserPanneauControle();
|
|
|
34 |
|
|
|
35 |
// obtenirNombreCollections
|
1778 |
mathias |
36 |
// $.getJSON(urlWebService + "CoelRecherche/Nombre/*/*/*/*/*/*/*/" + departement + "/*/", {async:false}).complete(function() { recupererValeurNombreCollections(); });
|
1701 |
raphael |
37 |
$.ajax({
|
|
|
38 |
dataType: "json",
|
1778 |
mathias |
39 |
url: urlWebService + "CoelRecherche/Nombre/*/*/*/*/*/*/*/" + departement + "/*/",
|
1788 |
aurelien |
40 |
data: { formatRetour: "text/plain", pays: pays},
|
1701 |
raphael |
41 |
async: false
|
|
|
42 |
}).complete(function(msg) {
|
|
|
43 |
if (! estStatutRequeteOK(msg.status)) {
|
|
|
44 |
alert(msg.responseText);
|
|
|
45 |
return;
|
|
|
46 |
}
|
|
|
47 |
nombreCollections = parseInt(msg.responseText);
|
|
|
48 |
});
|
|
|
49 |
|
|
|
50 |
chargerStructures();
|
1646 |
alex |
51 |
});
|
|
|
52 |
|
|
|
53 |
$(window).resize(function() {
|
|
|
54 |
dimensionnerCarte();
|
|
|
55 |
});
|
|
|
56 |
|
|
|
57 |
function dimensionnerCarte() {
|
|
|
58 |
$("#map").width($(window).width());
|
|
|
59 |
$("#map").height($(window).height());
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
function initialiserCarte() {
|
|
|
63 |
map = L.map('map', optionsCarte);
|
1797 |
aurelien |
64 |
coucheOSM.addTo(map);
|
1646 |
alex |
65 |
coucheStructures.addTo(map);
|
|
|
66 |
map.on('zoomend', function() {
|
|
|
67 |
// controle sur le niveau de zoom uniquement a la fin du placement des structures sur la carte
|
|
|
68 |
if (chargementEnCours) {
|
|
|
69 |
chargementEnCours = false;
|
|
|
70 |
verifierZoom();
|
|
|
71 |
}
|
|
|
72 |
});
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
function initialiserPanneauControle() {
|
|
|
76 |
var baseMaps = {
|
|
|
77 |
"Plan" : coucheOSM,
|
|
|
78 |
"Satellite" : coucheSatellite
|
|
|
79 |
};
|
|
|
80 |
var overlayMaps = {
|
|
|
81 |
"Structures" : coucheStructures
|
|
|
82 |
};
|
|
|
83 |
L.control.layers(baseMaps, overlayMaps).addTo(map);
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
|
|
|
87 |
function recupererValeurNombreCollections() {
|
|
|
88 |
}
|
|
|
89 |
|
|
|
90 |
function chargerStructures() {
|
|
|
91 |
if (requeteEnCours()) {
|
|
|
92 |
window.setTimeout('chargerStructures()', 400);
|
1703 |
raphael |
93 |
return;
|
1646 |
alex |
94 |
}
|
1703 |
raphael |
95 |
|
|
|
96 |
chargementEnCours = true;
|
|
|
97 |
$.ajax({
|
|
|
98 |
dataType: "json",
|
1778 |
mathias |
99 |
url: urlWebService + "CoelRecherche/ParDefaut/*/*/*/*/*/*/*/" + departement + "/*/",
|
1788 |
aurelien |
100 |
data: { limit: nombreCollections, pays: pays},
|
1703 |
raphael |
101 |
async: true
|
|
|
102 |
}).complete(function(msg) {
|
|
|
103 |
if (!estStatutRequeteOK(msg.status)) {
|
|
|
104 |
alert(msg.responseText);
|
|
|
105 |
return;
|
|
|
106 |
}
|
|
|
107 |
collections = eval("(function(){return " + msg.responseText + ";})()");
|
|
|
108 |
ordonnerCollectionsParStructures();
|
|
|
109 |
chargerLocalisations();
|
|
|
110 |
});
|
1646 |
alex |
111 |
}
|
|
|
112 |
|
|
|
113 |
function requeteEnCours() {
|
|
|
114 |
return (xmlHttpRequest != null && xmlHttpRequest.readyState != 4);
|
|
|
115 |
}
|
|
|
116 |
|
1701 |
raphael |
117 |
function estStatutRequeteOK(x_status) {
|
|
|
118 |
return (x_status == 200 || x_status == 304 || x_status == 0);
|
1646 |
alex |
119 |
}
|
|
|
120 |
|
|
|
121 |
function ordonnerCollectionsParStructures() {
|
|
|
122 |
for (var index = 0; index < collections.length; index ++) {
|
|
|
123 |
var indexStructure = 0;
|
|
|
124 |
while (indexStructure < structures.length && structures[indexStructure].id != collections[index].cs_id_structure) {
|
|
|
125 |
indexStructure ++;
|
|
|
126 |
}
|
|
|
127 |
if (indexStructure == structures.length) {
|
|
|
128 |
var structure = {
|
|
|
129 |
"id" : collections[index].cs_id_structure,
|
|
|
130 |
"nom" : collections[index].cs_nom,
|
|
|
131 |
"ville" : collections[index].cs_ville,
|
|
|
132 |
"code_postal" : collections[index].cs_code_postal,
|
|
|
133 |
"longitude" : collections[index].cs_longitude,
|
|
|
134 |
"latitude" : collections[index].cs_latitude,
|
|
|
135 |
"collections" : new Array()
|
|
|
136 |
};
|
|
|
137 |
structures.push(structure);
|
|
|
138 |
}
|
|
|
139 |
var collection = {
|
|
|
140 |
"id" : collections[index].cc_id_collection,
|
|
|
141 |
"nom" : collections[index].cc_nom
|
|
|
142 |
};
|
|
|
143 |
structures[indexStructure].collections.push(collection);
|
|
|
144 |
}
|
|
|
145 |
}
|
|
|
146 |
|
|
|
147 |
function chargerLocalisations() {
|
|
|
148 |
var nombreStructuresAffichees = 0;
|
|
|
149 |
for (var index = 0; index < structures.length; index ++) {
|
|
|
150 |
if ((structures[index].longitude != null && structures[index].longitude != "")
|
|
|
151 |
&& (structures[index].latitude != null && structures[index].latitude != "")) {
|
|
|
152 |
var existeMarqueur = rechercherExistenceMarqueur(structures[index].longitude, structures[index].latitude);
|
|
|
153 |
if (!existeMarqueur) {
|
|
|
154 |
creerMarqueur(structures[index]);
|
|
|
155 |
nombreStructuresAffichees ++;
|
|
|
156 |
}
|
|
|
157 |
}
|
|
|
158 |
}
|
|
|
159 |
if (nombreStructuresAffichees > 0) {
|
|
|
160 |
map.fitBounds(coucheStructures.getBounds());
|
|
|
161 |
}
|
|
|
162 |
}
|
|
|
163 |
|
|
|
164 |
function rechercherExistenceMarqueur(longitude, latitude) {
|
|
|
165 |
var existeMarqueur = false;
|
|
|
166 |
coucheStructures.eachLayer(function(layer) {
|
|
|
167 |
if (layer.getLatLng().lat == latitude && layer.getLatLng().lng == longitude) {
|
|
|
168 |
existeMarqueur = true;
|
|
|
169 |
}
|
|
|
170 |
});
|
|
|
171 |
return existeMarqueur;
|
|
|
172 |
}
|
|
|
173 |
|
|
|
174 |
function creerMarqueur(structure) {
|
|
|
175 |
var latlng = new L.LatLng(structure.latitude, structure.longitude);
|
|
|
176 |
var marqueur = new L.Marker(latlng, {
|
|
|
177 |
title : structure.nom
|
|
|
178 |
});
|
|
|
179 |
marqueur.on('click', surClickMarqueur);
|
|
|
180 |
coucheStructures.addLayer(marqueur);
|
1664 |
raphael |
181 |
|
1646 |
alex |
182 |
}
|
|
|
183 |
|
|
|
184 |
function surClickMarqueur(event) {
|
|
|
185 |
var latlng = event.target.getLatLng();
|
|
|
186 |
var collections = new Array();
|
|
|
187 |
var structure = null;
|
|
|
188 |
for (var index = 0; index < structures.length; index ++) {
|
|
|
189 |
if (structures[index].latitude == latlng.lat && structures[index].longitude == latlng.lng) {
|
|
|
190 |
collections = collections.concat(structures[index].collections);
|
1664 |
raphael |
191 |
structure = structures[index];
|
|
|
192 |
afficherCollections(structure, collections);
|
|
|
193 |
break;
|
1646 |
alex |
194 |
}
|
|
|
195 |
}
|
|
|
196 |
}
|
|
|
197 |
|
|
|
198 |
function afficherCollections(structure, collections) {
|
|
|
199 |
masquerInfoBulle();
|
|
|
200 |
infoBulle = new L.Popup({maxWidth : 0.25*$(window).width(), maxHeight : 0.35*$(window).height()});
|
|
|
201 |
var latlng = new L.LatLng(structure.latitude, structure.longitude);
|
|
|
202 |
infoBulle.setLatLng(latlng);
|
|
|
203 |
infoBulle.openOn(map);
|
|
|
204 |
remplirContenuPopup(structure, collections);
|
|
|
205 |
$("a").css("color", "#598000");
|
|
|
206 |
map.setView(latlng, map.getZoom());
|
|
|
207 |
}
|
|
|
208 |
|
|
|
209 |
function masquerInfoBulle() {
|
|
|
210 |
if (infoBulle != null && map.hasLayer(infoBulle)) {
|
|
|
211 |
map.removeLayer(infoBulle);
|
|
|
212 |
}
|
|
|
213 |
infoBulle = null;
|
|
|
214 |
}
|
|
|
215 |
|
|
|
216 |
function remplirContenuPopup(structure, collections) {
|
|
|
217 |
$("#structure").empty();
|
|
|
218 |
var structureAjout = {
|
|
|
219 |
"id" : structure.id,
|
|
|
220 |
"nom" : structure.nom,
|
|
|
221 |
"ville" : structure.ville,
|
|
|
222 |
"code_postal" : structure.code_postal,
|
|
|
223 |
"collections" : collections
|
|
|
224 |
};
|
|
|
225 |
$("#tpl-structure").tmpl(structureAjout).appendTo($("#structure"));
|
|
|
226 |
infoBulle.setContent($("#structure").html());
|
|
|
227 |
}
|
|
|
228 |
|
|
|
229 |
function verifierZoom() {
|
|
|
230 |
if(map.getZoom() > 13) {
|
|
|
231 |
map.setZoom(13);
|
|
|
232 |
}
|
|
|
233 |
}
|