150,9 → 150,11 |
if ((structures[index].longitude != null && structures[index].longitude != "") |
&& (structures[index].latitude != null && structures[index].latitude != "")) { |
var existeMarqueur = rechercherExistenceMarqueur(structures[index].longitude, structures[index].latitude); |
if (!existeMarqueur) { |
if (existeMarqueur == null) { |
creerMarqueur(structures[index]); |
nombreStructuresAffichees ++; |
} else { |
ajouterStructureAMarqueur(existeMarqueur, structures[index]); |
} |
} |
} |
162,10 → 164,10 |
} |
|
function rechercherExistenceMarqueur(longitude, latitude) { |
var existeMarqueur = false; |
var existeMarqueur = null; |
coucheStructures.eachLayer(function(layer) { |
if (layer.getLatLng().lat == latitude && layer.getLatLng().lng == longitude) { |
existeMarqueur = true; |
existeMarqueur = layer; |
} |
}); |
return existeMarqueur; |
174,34 → 176,33 |
function creerMarqueur(structure) { |
var latlng = new L.LatLng(structure.latitude, structure.longitude); |
var marqueur = new L.Marker(latlng, { |
title : structure.nom |
title : structure.nom, |
structures : [structure] |
}); |
marqueur.on('click', surClickMarqueur); |
coucheStructures.addLayer(marqueur); |
} |
|
function ajouterStructureAMarqueur(marqueur, structure) { |
marqueur.options.structures.push(structure); |
// changer la propriété title du marqueur ne fonctionne pas |
// en dehors du constructeur (mais cette méthode est-elle pérenne ?) |
marqueur._icon.title += "\n"+structure.nom; |
console.log(marqueur._icon); |
} |
|
function surClickMarqueur(event) { |
var latlng = event.target.getLatLng(); |
var collections = new Array(); |
var structure = null; |
for (var index = 0; index < structures.length; index ++) { |
if (structures[index].latitude == latlng.lat && structures[index].longitude == latlng.lng) { |
collections = collections.concat(structures[index].collections); |
structure = structures[index]; |
afficherCollections(structure, collections); |
break; |
} |
} |
var structures = event.target.options.structures; |
afficherCollections(structures, latlng); |
} |
|
function afficherCollections(structure, collections) { |
function afficherCollections(structures, latlng) { |
masquerInfoBulle(); |
infoBulle = new L.Popup({maxWidth : 0.25*$(window).width(), maxHeight : 0.35*$(window).height()}); |
var latlng = new L.LatLng(structure.latitude, structure.longitude); |
infoBulle.setLatLng(latlng); |
infoBulle.openOn(map); |
remplirContenuPopup(structure, collections); |
remplirContenuPopup(structures); |
$("a").css("color", "#598000"); |
map.setView(latlng, map.getZoom()); |
} |
213,16 → 214,25 |
infoBulle = null; |
} |
|
function remplirContenuPopup(structure, collections) { |
function remplirContenuPopup(structures) { |
$("#structure").empty(); |
var structureAjout = { |
"id" : structure.id, |
"nom" : structure.nom, |
"ville" : structure.ville, |
"code_postal" : structure.code_postal, |
"collections" : collections |
}; |
$("#tpl-structure").tmpl(structureAjout).appendTo($("#structure")); |
var entetePopup = { |
"ville" : structures[0].ville, |
"code_postal" : structures[0].code_postal |
} |
$("#tpl-structure-entete").tmpl(entetePopup).appendTo($("#structure")); |
|
$.each(structures, function(index, structure) { |
var structureAjout = { |
"id" : structure.id, |
"nom" : structure.nom, |
"ville" : structure.ville, |
"code_postal" : structure.code_postal, |
"collections" : structure.collections |
}; |
$("#tpl-structure").tmpl(structureAjout).appendTo($("#structure")); |
}); |
|
infoBulle.setContent($("#structure").html()); |
} |
|