New file |
0,0 → 1,233 |
var map = null, |
optionsCoucheOSM = { |
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>', |
maxZoom: 18 |
}, |
optionsCoucheGoogle = { |
attribution: 'Map data ©'+new Date().getFullYear()+' <a href="http://maps.google.com">Google</a>', |
maxZoom: 18 |
}, |
coucheOSM = new L.TileLayer("http://a.tile.openstreetmap.org/{z}/{x}/{y}.png", |
optionsCoucheOSM), |
coucheSatellite = new L.TileLayer("http://mt1.google.com/vt/lyrs=y@218131653&hl=fr&src=app&x={x}&y={y}&z={z}", |
optionsCoucheGoogle), |
optionsCarte = { |
center : new L.LatLng(46, 2), |
zoom : 6, |
layers : [coucheSatellite] |
}; |
|
var xmlHttpRequest = null, |
nombreCollections = 0, |
collections = new Array(), |
structures = new Array(), |
coucheStructures = new L.FeatureGroup(), |
infoBulle = null, |
chargementEnCours = false; |
|
|
$(document).ready(function() { |
dimensionnerCarte(); |
initialiserCarte(); |
initialiserPanneauControle(); |
|
// obtenirNombreCollections |
// $.getJSON(urlWebService + "CoelRecherche/Nombre/*/*/*/*/*/*/" + departement + "/*/*/", {async:false}).complete(function() { recupererValeurNombreCollections(); }); |
$.ajax({ |
dataType: "json", |
url: urlWebService + "CoelRecherche/Nombre/*/*/*/*/*/*/" + departement + "/*/*/", |
data: { formatRetour: "text/plain", pays: pays, regions: regions }, |
async: false |
}).complete(function(msg) { |
if (! estStatutRequeteOK(msg.status)) { |
alert(msg.responseText); |
return; |
} |
nombreCollections = parseInt(msg.responseText); |
}); |
|
chargerStructures(); |
}); |
|
$(window).resize(function() { |
dimensionnerCarte(); |
}); |
|
function dimensionnerCarte() { |
$("#map").width($(window).width()); |
$("#map").height($(window).height()); |
} |
|
function initialiserCarte() { |
map = L.map('map', optionsCarte); |
coucheSatellite.addTo(map); |
coucheStructures.addTo(map); |
map.on('zoomend', function() { |
// controle sur le niveau de zoom uniquement a la fin du placement des structures sur la carte |
if (chargementEnCours) { |
chargementEnCours = false; |
verifierZoom(); |
} |
}); |
} |
|
function initialiserPanneauControle() { |
var baseMaps = { |
"Plan" : coucheOSM, |
"Satellite" : coucheSatellite |
}; |
var overlayMaps = { |
"Structures" : coucheStructures |
}; |
L.control.layers(baseMaps, overlayMaps).addTo(map); |
} |
|
|
function recupererValeurNombreCollections() { |
} |
|
function chargerStructures() { |
if (requeteEnCours()) { |
window.setTimeout('chargerStructures()', 400); |
return; |
} |
|
chargementEnCours = true; |
$.ajax({ |
dataType: "json", |
url: urlWebService + "CoelRecherche/ParDefaut/*/*/*/*/*/*/" + departement + "/*/*/", |
data: { limit: nombreCollections, pays: pays, regions: regions }, |
async: true |
}).complete(function(msg) { |
if (!estStatutRequeteOK(msg.status)) { |
alert(msg.responseText); |
return; |
} |
collections = eval("(function(){return " + msg.responseText + ";})()"); |
ordonnerCollectionsParStructures(); |
chargerLocalisations(); |
}); |
} |
|
function requeteEnCours() { |
return (xmlHttpRequest != null && xmlHttpRequest.readyState != 4); |
} |
|
function estStatutRequeteOK(x_status) { |
return (x_status == 200 || x_status == 304 || x_status == 0); |
} |
|
function ordonnerCollectionsParStructures() { |
for (var index = 0; index < collections.length; index ++) { |
var indexStructure = 0; |
while (indexStructure < structures.length && structures[indexStructure].id != collections[index].cs_id_structure) { |
indexStructure ++; |
} |
if (indexStructure == structures.length) { |
var structure = { |
"id" : collections[index].cs_id_structure, |
"nom" : collections[index].cs_nom, |
"ville" : collections[index].cs_ville, |
"code_postal" : collections[index].cs_code_postal, |
"longitude" : collections[index].cs_longitude, |
"latitude" : collections[index].cs_latitude, |
"collections" : new Array() |
}; |
structures.push(structure); |
} |
var collection = { |
"id" : collections[index].cc_id_collection, |
"nom" : collections[index].cc_nom |
}; |
structures[indexStructure].collections.push(collection); |
} |
} |
|
function chargerLocalisations() { |
var nombreStructuresAffichees = 0; |
for (var index = 0; index < structures.length; index ++) { |
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) { |
creerMarqueur(structures[index]); |
nombreStructuresAffichees ++; |
} |
} |
} |
if (nombreStructuresAffichees > 0) { |
map.fitBounds(coucheStructures.getBounds()); |
} |
} |
|
function rechercherExistenceMarqueur(longitude, latitude) { |
var existeMarqueur = false; |
coucheStructures.eachLayer(function(layer) { |
if (layer.getLatLng().lat == latitude && layer.getLatLng().lng == longitude) { |
existeMarqueur = true; |
} |
}); |
return existeMarqueur; |
} |
|
function creerMarqueur(structure) { |
var latlng = new L.LatLng(structure.latitude, structure.longitude); |
var marqueur = new L.Marker(latlng, { |
title : structure.nom |
}); |
marqueur.on('click', surClickMarqueur); |
coucheStructures.addLayer(marqueur); |
|
} |
|
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; |
} |
} |
} |
|
function afficherCollections(structure, collections) { |
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); |
$("a").css("color", "#598000"); |
map.setView(latlng, map.getZoom()); |
} |
|
function masquerInfoBulle() { |
if (infoBulle != null && map.hasLayer(infoBulle)) { |
map.removeLayer(infoBulle); |
} |
infoBulle = null; |
} |
|
function remplirContenuPopup(structure, collections) { |
$("#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")); |
infoBulle.setContent($("#structure").html()); |
} |
|
function verifierZoom() { |
if(map.getZoom() > 13) { |
map.setZoom(13); |
} |
} |
Property changes: |
Added: svn:mime-type |
+text/plain |
\ No newline at end of property |