Subversion Repositories eFlore/Applications.coel

Rev

Rev 1809 | Rev 1825 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1809 Rev 1822
Line 148... Line 148...
148
	var nombreStructuresAffichees = 0;
148
	var nombreStructuresAffichees = 0;
149
	for (var index = 0; index < structures.length; index ++) {
149
	for (var index = 0; index < structures.length; index ++) {
150
		if ((structures[index].longitude != null && structures[index].longitude != "")
150
		if ((structures[index].longitude != null && structures[index].longitude != "")
151
			&& (structures[index].latitude != null && structures[index].latitude != "")) {
151
			&& (structures[index].latitude != null && structures[index].latitude != "")) {
152
			var existeMarqueur = rechercherExistenceMarqueur(structures[index].longitude, structures[index].latitude);
152
			var existeMarqueur = rechercherExistenceMarqueur(structures[index].longitude, structures[index].latitude);
153
			if (!existeMarqueur) {
153
			if (existeMarqueur == null) {
154
				creerMarqueur(structures[index]);
154
				creerMarqueur(structures[index]);
155
				nombreStructuresAffichees ++;
155
				nombreStructuresAffichees ++;
-
 
156
			} else {
-
 
157
				ajouterStructureAMarqueur(existeMarqueur, structures[index]);
156
			}
158
			}
157
		}
159
		}
158
	}
160
	}
159
	if (nombreStructuresAffichees > 0) {
161
	if (nombreStructuresAffichees > 0) {
160
		map.fitBounds(coucheStructures.getBounds());
162
		map.fitBounds(coucheStructures.getBounds());
161
	}
163
	}
162
}
164
}
Line 163... Line 165...
163
 
165
 
164
function rechercherExistenceMarqueur(longitude, latitude) {
166
function rechercherExistenceMarqueur(longitude, latitude) {
165
	var existeMarqueur = false;
167
	var existeMarqueur = null;
166
	coucheStructures.eachLayer(function(layer) {
168
	coucheStructures.eachLayer(function(layer) {
167
		if (layer.getLatLng().lat == latitude && layer.getLatLng().lng == longitude) {
169
		if (layer.getLatLng().lat == latitude && layer.getLatLng().lng == longitude) {
168
			existeMarqueur = true;
170
			existeMarqueur = layer;
169
		}
171
		}
170
	});
172
	});
171
	return existeMarqueur;
173
	return existeMarqueur;
Line 172... Line 174...
172
}
174
}
173
 
175
 
174
function creerMarqueur(structure) {
176
function creerMarqueur(structure) {
175
	var latlng = new L.LatLng(structure.latitude, structure.longitude);
177
	var latlng = new L.LatLng(structure.latitude, structure.longitude);
-
 
178
	var marqueur = new L.Marker(latlng, {
176
	var marqueur = new L.Marker(latlng, {
179
		title : structure.nom,
177
		title : structure.nom
180
		structures : [structure]
178
	});
181
	});
-
 
182
	marqueur.on('click', surClickMarqueur);
Line -... Line 183...
-
 
183
	coucheStructures.addLayer(marqueur);
-
 
184
}
-
 
185
 
-
 
186
function ajouterStructureAMarqueur(marqueur, structure) {
-
 
187
	marqueur.options.structures.push(structure);
-
 
188
	// changer la propriété title du marqueur ne fonctionne pas
179
	marqueur.on('click', surClickMarqueur);
189
	// en dehors du constructeur (mais cette méthode est-elle pérenne ?)
Line 180... Line 190...
180
	coucheStructures.addLayer(marqueur);
190
	marqueur._icon.title += "\n"+structure.nom;
181
 
191
	console.log(marqueur._icon);
182
}
-
 
183
 
-
 
184
function surClickMarqueur(event) {
-
 
185
	var latlng = event.target.getLatLng();
-
 
186
	var collections = new Array();
-
 
187
	var structure = null;
192
}
188
	for (var index = 0; index < structures.length; index ++) {
193
 
189
		if (structures[index].latitude == latlng.lat && structures[index].longitude == latlng.lng) {
-
 
190
			collections = collections.concat(structures[index].collections);
-
 
191
			structure = structures[index];
-
 
192
			afficherCollections(structure, collections);
194
function surClickMarqueur(event) {
Line 193... Line 195...
193
			break;
195
	var latlng = event.target.getLatLng();
194
		}
196
	var structures = event.target.options.structures;
195
	}
197
	afficherCollections(structures, latlng);
196
}
-
 
197
 
198
}
198
function afficherCollections(structure, collections) {
199
 
199
	masquerInfoBulle();
200
function afficherCollections(structures, latlng) {
200
	infoBulle = new L.Popup({maxWidth : 0.25*$(window).width(), maxHeight : 0.35*$(window).height()});
201
	masquerInfoBulle();
201
	var latlng = new L.LatLng(structure.latitude, structure.longitude);
202
	infoBulle = new L.Popup({maxWidth : 0.25*$(window).width(), maxHeight : 0.35*$(window).height()});
202
	infoBulle.setLatLng(latlng);
203
	infoBulle.setLatLng(latlng);
Line 203... Line 204...
203
	infoBulle.openOn(map);
204
	infoBulle.openOn(map);
Line 211... Line 212...
211
		map.removeLayer(infoBulle);
212
		map.removeLayer(infoBulle);
212
	}
213
	}
213
	infoBulle = null;
214
	infoBulle = null;
214
}
215
}
Line 215... Line 216...
215
 
216
 
216
function remplirContenuPopup(structure, collections) {
217
function remplirContenuPopup(structures) {
-
 
218
	$("#structure").empty();
-
 
219
	var entetePopup = {
-
 
220
		"ville" : structures[0].ville,
-
 
221
		"code_postal" : structures[0].code_postal
-
 
222
	}
-
 
223
	$("#tpl-structure-entete").tmpl(entetePopup).appendTo($("#structure"));
-
 
224
	
217
	$("#structure").empty();
225
	$.each(structures, function(index, structure) {
218
	var structureAjout = {
226
		var structureAjout = {
219
		"id"    : structure.id,
227
			"id"    : structure.id,
220
		"nom"   : structure.nom,
228
			"nom"   : structure.nom,
221
		"ville" : structure.ville,
229
			"ville" : structure.ville,
222
		"code_postal" : structure.code_postal,
230
			"code_postal" : structure.code_postal,
223
		"collections" : collections
231
			"collections" : structure.collections
224
	};
232
		};
-
 
233
		$("#tpl-structure").tmpl(structureAjout).appendTo($("#structure"));
-
 
234
	});
225
	$("#tpl-structure").tmpl(structureAjout).appendTo($("#structure"));
235
	
226
	infoBulle.setContent($("#structure").html());
236
	infoBulle.setContent($("#structure").html());
Line 227... Line 237...
227
}
237
}
228
 
238