/trunk/widget/modules/carto/squelettes/scripts/leaflet.markercluster.js |
---|
File deleted |
\ No newline at end of file |
/trunk/widget/modules/carto/squelettes/scripts/cluster.js |
---|
File deleted |
\ No newline at end of file |
/trunk/widget/modules/carto/squelettes/scripts/carto.js |
---|
1,3 → 1,62 |
// Javascript Document |
// =================================================================================== |
// FONCTIONS ADDITIONNELLES POUR GERER LES URLS ET L'OUVERTRURE DE NOUVELLE FENETRE |
function convertirEnParametresUrl(objet) { |
var parametresUrl = ''; |
for (attribut in objet) { |
if (typeof(objet[attribut]) == 'function' || typeof(objet[attribut]) == 'undefined' || |
objet[attribut] == null || objet[attribut] == '*' || objet[attribut] == 0) |
continue; |
parametresUrl += (parametresUrl == '' ? '' : '&') + attribut + "=" + objet[attribut]; |
} |
return parametresUrl; |
}; |
function recupererParametreDansUrl(nomParametre, chaineRecherche) { |
var split = chaineRecherche.split('?'); |
chaineRecherche = split[split.length-1]; |
var valeurParametre = null; |
var listeParametres = chaineRecherche.split("&"); |
for (var index = 0; index < listeParametres.length; index ++) { |
var split = listeParametres[index].split("="); |
if (split[0] == nomParametre) { |
valeurParametre = split[1]; |
break; |
} |
} |
return valeurParametre; |
}; |
function estValeurDansTableau(tableau, valeur) { |
var index; |
for (index = 0; index < tableau.length && tableau[index] != valeur; index ++); |
return (tableau.length > 0 && index != tableau.length); |
} |
function ouvrirNouvelleFenetre(element, event) { |
window.open(element.href); |
return arreter(event); |
} |
function arreter(event) { |
if (event.stopPropagation) { |
event.stopPropagation(); |
} else if (window.event) { |
window.event.cancelBubble = true; |
} |
if (event.preventDefault) { |
event.preventDefault(); |
} |
event.returnValue = false; |
return false; |
} |
// ============================================================= |
var map = null, |
optionsCoucheOSM = { |
attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors,' |
8,12 → 67,12 |
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", |
coucheOSM = new L.TileLayer("http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", |
optionsCoucheOSM), |
coucheRelief = new L.TileLayer("http://c.tile3.opencyclemap.org/landscape/{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}", |
couchePlanGoogle = new L.TileLayer("http://mt1.google.com/vt/lyrs=m&x={x}&y={y}&z={z}", |
optionsCoucheGoogle), |
coucheSatelliteGoogle = new L.TileLayer("http://mt1.google.com/vt/lyrs=y&x={x}&y={y}&z={z}", |
optionsCoucheGoogle), |
optionsCarte = { |
center : new L.LatLng(46, 2), |
zoom : 6, |
26,15 → 85,19 |
coucheDepartement = null, |
infoBulle = null; |
var coucheSites = null, |
var coucheSites = new L.FeatureGroup(), |
points = new Array(), |
coucheSites = new L.FeatureGroup(), |
sources = new Object(), |
typeSite = 'maille', |
formeDonnees = '', |
popupMaille = null; |
overlays = []; |
var requeteChargementPoints = null, |
chargementMaillesEnCours = false, |
doitRafraichirCarte = true, |
chargementCommunesEnCours = false, |
timer = null, |
ancienneRequete = null, |
deplacement = true, |
url = ''; |
44,27 → 107,50 |
initialiserWidget(); |
}); |
$(window).resize(function() { |
dimensionnerCarte(); |
}); |
function initialiserWidget() { |
initialiserCarte(); |
chargerLimitesCommunales(); |
dimensionnerOverlay(); |
initialiserPanneauControle(); |
initialiserSources(); |
initialiserListeners(); |
chargerLocalisations(); |
chargerLimitesCommunales(); |
chargerMaillesVides(); |
programmerRafraichissementCarte(); |
} |
$(window).resize(function() { |
dimensionnerCarte(); |
if (infoBulle != null) { |
redimensionnerPopup(); |
} |
}); |
function dimensionnerOverlay() { |
var taille = '1.6'; |
var tailleMaxIcones = 20; |
var padding_icones = 8; |
$("#zone-titre h1").css('font-size', (taille)+'em'); |
$("#zone-titre").css('padding', padding_icones+"px "+padding_icones+"px "+Math.round(padding_icones/4)+"px"); |
$('#zone-titre').height(tailleMaxIcones*2); |
var left = ($(window).width()-$('#zone-titre').width())/2; |
$('#zone-titre').css('left',left); |
} |
function dimensionnerCarte() { |
$('#map').height($(window).height()); |
$('#map').width($(window).width()); |
} |
function initialiserCarte() { |
dimensionnerCarte(); |
map = L.map('map', optionsCarte); |
coucheSatellite.addTo(map); |
coucheRelief.addTo(map); |
coucheSites.addTo(map); |
coucheOSM.addTo(map); |
couchePlanGoogle.addTo(map); |
coucheSatelliteGoogle.addTo(map); |
var echelle = new L.Control.Scale({ |
maxWidth : 50, |
maxWidth : 32, |
metric : true, |
imperial : false, |
updateWhenIdle : true |
73,14 → 159,9 |
zoom = map.getZoom(); |
} |
function dimensionnerCarte() { |
$('#map').height($(window).height()); |
$('#map').width($(window).width()); |
} |
function initialiserListeners() { |
map.on('moveend', surChangementVueCarte); |
map.on('zoomend', surChangementVueCarte); |
map.on('moveend', surChangementVueSurCarte); |
map.on('zoomend', surChangementVueSurCarte); |
map.on('popupclose', function(e) { |
masquerInfoBulle(); |
programmerRafraichissementCarte(); |
89,9 → 170,9 |
function initialiserPanneauControle() { |
var baseMaps = { |
"Satellite" : coucheSatellite, |
"Relief" : coucheRelief, |
"Plan" : coucheOSM |
"OpenStreetMap" : coucheOSM, |
"Plan" : couchePlanGoogle, |
"Satellite" : coucheSatelliteGoogle |
}; |
var overlayMaps = {}; |
101,8 → 182,8 |
} |
L.control.layers(baseMaps, overlayMaps).addTo(map); |
coucheOSM.bringToFront(); |
map.removeLayer(coucheRelief); |
map.removeLayer(coucheOSM); |
couchePlanGoogle.bringToBack(); |
coucheSatelliteGoogle.bringToBack(); |
// garder par defaut la couche plan google comme selectionnee dans le panel |
var selecteursFonds = $('.leaflet-control-layers-base .leaflet-control-layers-selector'); |
132,111 → 213,62 |
}); |
} |
function changerSource(projetClique) { |
var indexProjetClique; |
for (var index = 0; index < overlays.length; index ++) { |
if (overlays[index].value == projetClique) { |
indexProjetClique = index; |
function determinerSourcesSelectionnees() { |
var sourcesSelectionnees = new Array(); |
for (source in sources) { |
if (sources[source] == true) { |
sourcesSelectionnees.push(source); |
} |
} |
masquerInfoBulle(); |
sources[projetClique] = overlays[indexProjetClique].checked; |
if (sources[projetClique] == true) { |
programmerRafraichissementCarte(projetClique); |
} else { |
if (requeteEnCours()) { |
stopperRequeteAjax(); |
} |
supprimerFeaturesSource(projetClique); |
} |
return sourcesSelectionnees; |
} |
function supprimerFeaturesSource(source) { |
if (coucheSites != null) { |
coucheSites.eachLayer(function(layer) { |
if (layer.typeSite == 'maille') { |
retirerStationsEtObservations(layer, source); |
} else { |
layer.supprimerSource(source, coucheSites); |
if (layer._map == 'null') { |
couheSites.removeLayer(layer); |
} |
} |
}); |
if (typeSite == 'maille') { |
var nombreMailles = calculerNombreMaillesVisibles(); |
if (nombreMailles == 0) { |
coucheSites.clearLayers(); |
masquerLegende(); |
typeSite = 'point'; |
} |
} |
function surChangementVueSurCarte() { |
if (doitRafraichirCarte == false) { |
doitRafraichirCarte = true; |
} else { |
supprimerTousLayers(); |
zoom = map.getZoom(); |
chargerMaillesVides(); |
} |
} |
function retirerStationsEtObservations(maille, sourceRetrait) { |
var sources = maille.properties.source; |
var nombreStations = 0; |
for (var index = 0; index < sources.length; index ++) { |
var source = sources[index]; |
if (source == sourceRetrait) { |
delete maille.properties.stations[source]; |
delete maille.properties.observations[source]; |
} else if (typeof(maille.properties.stations[source]) != 'undefined') { |
nombreStations += parseInt(maille.properties.stations[source]); |
} |
function chargerMaillesVides() { |
chargementMaillesEnCours = true; |
if (timer != null) { |
window.clearTimeout(timer); |
} |
if (requeteChargementPoints != null) { |
stopperRequeteAjax(); |
} |
if (nombreStations == 0) { |
coucheSites.removeLayer(maille); |
} else { |
colorerMaille(maille) |
genererInfobulle(maille); |
} |
timer = window.setTimeout(function() { |
var coordonneesBordure = calculerCoordonneesBordure(); |
var parametres = { |
"source" : "floradata", |
"bbox" : coordonneesBordure, |
"zoom" : map.getZoom() |
}; |
url = urlBase + "mailles?" + convertirEnParametresUrl(parametres); |
fonctionCallback = traiterDonneesStations; |
executerAJAX(); |
}, 400); |
} |
function calculerNombreMaillesVisibles() { |
var nombreMailles = 0; |
coucheSites.eachLayer(function(layer) { |
if($(layer._path).attr('fill-opacity') != '0') { |
nombreMailles ++; |
} |
}); |
return nombreMailles; |
} |
function estValeurDansTableau(tableau, valeur) { |
var index; |
for (index = 0; index < tableau.length && tableau[index] != valeur; index ++); |
return (tableau.length > 0 && index != tableau.length); |
} |
//************************************ |
// requetes stations |
function surChangementVueCarte() { |
programmerRafraichissementCarte(); |
} |
function programmerRafraichissementCarte(source) { |
$('#tooltip').css('display', 'none'); |
source = (source == null || source == 'null') ? null : source; |
if (timer != null) { |
window.clearTimeout(timer); |
} |
if (requeteChargementPoints != null) { |
stopperRequeteAjax(); |
} |
var nombreSourcesVisibles = 0; |
for (var index = 0; index < overlays.length; index ++) { |
if (overlays[index].checked) { |
nombreSourcesVisibles ++; |
if (!chargementMaillesEnCours) { |
if (timer != null) { |
window.clearTimeout(timer); |
} |
} |
if (source == null) { |
timer = window.setTimeout("chargerLocalisations()", 100); |
} else { |
timer = window.setTimeout("chargerSource('"+source+"')", 100); |
} |
if (requeteChargementPoints != null) { |
if (source == null) { |
stopperRequeteAjax(); |
} |
} |
timer = window.setTimeout("rafraichirDonnnees('"+source+"')", 250); |
} else { |
window.setTimeout("programmerRafraichissementCarte('"+source+"')", 400); |
} |
} |
function stopperRequeteAjax() { |
244,140 → 276,84 |
requeteChargementPoints = null; |
} |
function chargerLocalisations() { |
if (requeteEnCours()) { |
requeteChargementPoints.abort(); |
function rafraichirDonnnees(source) { |
source = (source == null || source == 'null') ? null : source; |
if (coucheDepartement == null || coucheDepartement.getStatus() == KML_READY) { |
if (source != null) { |
chargerLocalisations(source); |
} else { |
supprimerLocalisations(); |
for (source in sources) { |
if (sources[source] == true) { |
chargerLocalisations(source); |
} |
} |
} |
} else { |
window.setTimeout("rafraichirDonnnees('"+source+"')", 800); |
} |
afficherMessageChargement('stations'); |
if (!(ancienneRequete != null && ancienneRequete[1] == map.getZoom() |
&& map.getBounds().intersects(ancienneRequete[0]))) { |
supprimerFeatures(); |
deplacement = false; |
} |
var bboxRequete = calculerBboxRequete(); |
var parametres = { |
"bbox" : bboxRequete, |
"zoom" : map.getZoom(), |
"source" : recupererSourcesActivees(), |
"num_taxon" : numTaxon, |
"nn" : nn, |
"referentiel" : referentiel, |
"dept" : dept, |
"auteur" : auteur, |
"date_debut" : dateDebut, |
"date_fin" : dateFin, |
"nb_jours" : nbJours |
}; |
if (deplacement == true) { |
parametres.format = typeSite; |
} |
ancienneRequete = [map.getBounds(), map.getZoom()]; |
url = urlBase + "stations?" + convertirEnParametresUrl(parametres); |
fonctionCallback = traiterDonneesStations; |
executerAJAX(); |
} |
function supprimerFeatures() { |
if (coucheSites != null) { |
coucheSites.clearLayers(); |
coucheSites = null; |
} |
function supprimerTousLayers() { |
coucheSites.clearLayers(); |
points = []; |
formeDonnees = ''; |
} |
function recupererSourcesActivees(sourceAIgnorer) { |
sourceAIgnorer = typeof(sourceAIgnorer) == 'undefined' ? '' : sourceAIgnorer; |
var sourcesActivees = []; |
for (var index = 0; index < overlays.length; index ++) { |
if (overlays[index].checked == true && overlays[index].value != sourceAIgnorer) { |
sourcesActivees.push(overlays[index].value); |
function supprimerLocalisations(source) { |
source = (typeof(source) == 'undefined') ? null : source; |
if (source != null) { |
var sourceUrl = recupererParametreDansUrl('source', url); |
if (requeteChargementPoints != null && sourceUrl == source && source != null) { |
stopperRequeteAjax(); |
} |
coucheSites.eachLayer(function(layer) { |
supprimerLayer(layer, source); |
}); |
if (source != null) { |
supprimerPointsListe(source); |
} |
var sourcesSelectionnees = determinerSourcesSelectionnees(); |
if (sourcesSelectionnees.length == 1 && determinerNombreMarqueurs(sourcesSelectionnees[0]) > 0) { |
transformerMaillesEnPoints(sourcesSelectionnees[0]); |
} |
var sontPointsAffiches = (points.length>0 && determinerNombreMailles(false)==0); |
formeDonnees = sontPointsAffiches ? 'point' : 'maille'; |
} |
return sourcesActivees.join(','); |
} |
function chargerSource(sourceAjout) { |
if (requeteEnCours()) { |
requeteChargementPoints.abort(); |
} |
afficherMessageChargement('stations'); |
var bboxRequete = determinerCoordonneesBordure(); |
var parametres = { |
"bbox" : bboxRequete, |
"zoom" : map.getZoom(), |
"format" : typeSite, |
"source" : sourceAjout, |
"num_taxon" : numTaxon, |
"nn" : nn, |
"referentiel" : referentiel, |
"dept" : dept, |
"auteur" : auteur, |
"date_debut" : dateDebut, |
"date_fin" : dateFin, |
"nb_jours" : nbJours |
}; |
ancienneRequete = [map.getBounds(), map.getZoom()]; |
url = urlBase + "stations?" + convertirEnParametresUrl(parametres); |
fonctionCallback = traiterRetourChargementSource; |
executerAJAX(); |
function estLayerUtilisePourSource(layer, source) { |
return ( |
(layer.typeSite == 'MAILLE' && typeof(layer.nombrePoints[source]) != 'undefined') || |
(layer.typeSite != 'MAILLE' && layer.source == source) |
); |
} |
function calculerBboxRequete() { |
var bordure = map.getBounds(); |
var bboxRequete = ""; |
if (ancienneRequete != null && ancienneRequete[1] == map.getZoom() |
&& bordure.intersects(ancienneRequete[0])) { |
bboxRequete = calculerIntersectionRectangle(ancienneRequete[0], bordure); |
} else { |
bboxRequete = determinerCoordonneesBordure(); |
} |
return bboxRequete; |
} |
function calculerIntersectionRectangle(rectangle1, rectangle2) { |
var bbox1 = [rectangle2.getSouthWest().lng.toFixed(6), rectangle2.getSouthWest().lat.toFixed(6), |
rectangle2.getNorthEast().lng.toFixed(6), rectangle2.getNorthEast().lat.toFixed(6)]; |
var bbox2 = [rectangle2.getSouthWest().lng.toFixed(6), rectangle2.getSouthWest().lat.toFixed(6), |
rectangle2.getNorthEast().lng.toFixed(6), rectangle2.getNorthEast().lat.toFixed(6)]; |
if (rectangle2.getSouthWest().lng >= rectangle1.getSouthWest().lng |
&& rectangle2.getSouthWest().lng <= rectangle1.getNorthEast().lng) { |
bbox2[0] = bbox1[2] = rectangle1.getNorthEast().lng.toFixed(6); |
if (rectangle2.getSouthWest().lat >= rectangle1.getSouthWest().lat |
&& rectangle2.getSouthWest().lat <= rectangle1.getNorthEast().lat) { |
bbox1[1] = rectangle1.getNorthEast().lat.toFixed(6); |
function supprimerLayer(layer, source) { |
if (estLayerUtilisePourSource(layer, source)) { |
if (layer.typeSite == 'MAILLE') { |
supprimerSourceDansMaille(layer, source); |
} else { |
bbox1[3] = rectangle1.getSouthWest().lat.toFixed(6); |
coucheSites.removeLayer(layer); |
} |
} else { |
bbox2[0] = bbox1[2] = rectangle1.getSouthWest().lng.toFixed(6); |
if (rectangle2.getSouthWest().lat >= rectangle1.getSouthWest().lat |
&& rectangle2.getSouthWest().lat <= rectangle1.getNorthEast().lat) { |
bbox2[1] = rectangle1.getNorthEast().lat.toFixed(6); |
} else { |
bbox2[3] = rectangle1.getSouthWest().lat.toFixed(6); |
} |
} |
return bbox1.join(',')+'|'+bbox2.join(','); |
} |
function determinerCoordonneesBordure() { |
var ouest = map.getBounds().getSouthWest().lng.toFixed(6), |
sud = Math.max(map.getBounds().getSouthWest().lat, -85.051129).toFixed(6), |
est = map.getBounds().getNorthEast().lng.toFixed(6), |
nord = Math.min(map.getBounds().getNorthEast().lat, 85.051129).toFixed(6); |
// appliquer les limites possibles de la projection actuellement utilisee aux coordonnees |
// longitudes ouest et est de la bbox (permettra d'eviter de renvoyer des messages d'erreur) |
if (ouest < -180) { |
ouest += 360; |
} else if (ouest > 180) { |
ouest -= 360; |
function changerSource(projetClique) { |
var indexProjetClique; |
for (var index = 0; index < overlays.length; index ++) { |
if (overlays[index].value == projetClique) { |
indexProjetClique = index; |
} |
} |
if (est < -180) { |
est += 360; |
} else if (est > 180) { |
est -= 360; |
masquerInfoBulle(); |
sources[projetClique] = overlays[indexProjetClique].checked; |
if (sources[projetClique] == true) { |
programmerRafraichissementCarte(projetClique); |
} else { |
supprimerLocalisations(projetClique); |
} |
return [ouest, sud, est, nord].join(','); |
} |
function afficherMessageChargement(element) { |
393,8 → 369,11 |
$("#zone-chargement").children().remove(); |
} |
// execution d'une requete AJAX |
function executerAJAX() { |
if (requeteEnCours()) { |
masquerMessageChargement(); |
requeteChargementPoints.abort(); |
} |
requeteChargementPoints = $.getJSON(url).complete(function() { |
411,36 → 390,54 |
|| requeteChargementPoints.status == 0); |
} |
function convertirEnParametresUrl(objet) { |
var parametresUrl = ''; |
for (attribut in objet) { |
if (typeof(objet[attribut]) == 'function' || typeof(objet[attribut]) == 'undefined' || |
objet[attribut] == null || objet[attribut] == '*' || objet[attribut] == 0) |
continue; |
parametresUrl += (parametresUrl == '' ? '' : '&') + attribut + "=" + objet[attribut]; |
function chargerLocalisations(source) { |
if (requeteEnCours()) { |
window.setTimeout("chargerLocalisations('"+source+"')", 400); |
} else { |
afficherMessageChargement('stations'); |
// generer l'URL du script a interroger sur le serveur |
var coordonneesBordure = calculerCoordonneesBordure(); |
var parametres = { |
"source" : source, |
"num_taxon" : numTaxon, |
"referentiel" : referentiel, |
"dept" : dept, |
"nn" : nn, |
"auteur" : auteur, |
"date_debut" : dateDebut, |
"date_fin" : dateFin, |
"bbox" : coordonneesBordure, |
"nb_jours" : nbJours, |
"zoom" : map.getZoom() |
}; |
url = urlBase + "stations?" + convertirEnParametresUrl(parametres); |
fonctionCallback = traiterDonneesStations; |
executerAJAX(); |
} |
return parametresUrl; |
}; |
} |
function traiterDonneesStations() { |
masquerMessageChargement(); |
masquerLegende(); |
if (deplacement == true) { |
supprimerFeaturesHorsBbox(); |
function calculerCoordonneesBordure() { |
var bordure = map.getBounds(); |
var ouest = bordure.getSouthWest().lng.toFixed(6), |
sud = Math.max(bordure.getSouthWest().lat, -85.051129).toFixed(6), |
est = bordure.getNorthEast().lng.toFixed(6), |
nord = Math.min(bordure.getNorthEast().lat, 85.051129).toFixed(6); |
// appliquer les limites possibles de la projection actuellement utilisee aux coordonnees |
// longitudes ouest et est de la bbox (permettra d'eviter de renvoyer des messages d'erreur) |
if (ouest < -180) { |
ouest += 360; |
} else if (ouest > 180) { |
ouest -= 360; |
} |
deplacement = true; |
var texte = requeteChargementPoints.responseText; |
if (!estStatutRequeteOK()) { |
alert(texte); |
} else { |
var donneesJSON = eval("(function(){return " + texte + ";})()"); |
if (donneesJSON != null && donneesJSON.features.length > 0) { |
ajouterStationsSurCarte(donneesJSON); |
} |
if (est < -180) { |
est += 360; |
} else if (est > 180) { |
est -= 360; |
} |
return [ouest, sud, est, nord].join(','); |
} |
function traiterRetourChargementSource() { |
function traiterDonneesStations() { |
masquerMessageChargement(); |
var texte = requeteChargementPoints.responseText; |
if (!estStatutRequeteOK()) { |
447,78 → 444,82 |
alert(texte); |
} else { |
var donneesJSON = eval("(function(){return " + texte + ";})()"); |
if (donneesJSON != null && donneesJSON.features.length > 0) { |
var formatRetourDifferent = donneesJSON.stats.formeDonnees != typeSite; |
if (donneesJSON != null && typeof(donneesJSON.features) != 'undefined') { |
ajouterStationsSurCarte(donneesJSON); |
if (formatRetourDifferent) { |
var sourceAIgnorer = donneesJSON.stats.source[0]; |
var sourcesARecharger = recupererSourcesActivees(sourceAIgnorer); |
rechargerSources(sourcesARecharger); |
} |
} |
} |
} |
function supprimerFeaturesHorsBbox() { |
var bordure = map.getBounds(); |
var layersRestants = 0; |
if (coucheSites != null) { |
coucheSites.eachLayer(function(layer) { |
if (typeof(layer._latlng) != 'undefined') { |
if (bordure.contains(layer.getLatLng())) { |
layersRestants ++; |
} else { |
coucheSites.supprimerPoint(layer); |
} |
} else { |
if (bordure.intersects(layer.getBounds())) { |
layersRestants ++; |
} else { |
coucheSites.removeLayer(layer); |
} |
} |
}); |
function ajouterStationsSurCarte(data) { |
if (doitTransformerEnMaille(data.stats)) { |
if (points.length > 0 && data.stats.source != '') { |
combinerMaillesEtPoints(); |
} |
formeDonnees = 'maille'; |
} else { |
formeDonnees = data.stats.formeDonnees; |
} |
if (layersRestants == 0) { |
coucheSites = null; |
var sourceDonnees = data.stats.source; |
for (var index = 0; index < data.features.length; index ++) { |
ajouterStation(data.features[index]); |
} |
} |
function rechargerSources(sourcesARecharger) { |
var listeSourcesASupprimer = sourcesARecharger.split(','); |
for (var index = 0; index < listeSourcesASupprimer.length; index ++) { |
supprimerFeaturesSource(listeSourcesASupprimer[index]); |
if (formeDonnees == 'maille' && data.stats.sites > 0) { |
afficherLegende(); |
regenererInfobulleMailles(); |
} else { |
masquerLegende(); |
} |
chargerSource(sourcesARecharger); |
if (chargementMaillesEnCours) { |
chargementMaillesEnCours = false; |
programmerRafraichissementCarte(); |
} |
} |
function ajouterStationsSurCarte(donnees) { |
typeSite = donnees.stats.formeDonnees; |
if (coucheSites == null) { |
coucheSites = (typeSite == 'maille') ? new L.FeatureGroup() : new L.ClusterGroup(); |
map.addLayer(coucheSites); |
} |
for (var index = 0; index < donnees.features.length; index ++) { |
var feature = donnees.features[index]; |
if (typeSite == 'maille') { |
traiterMaille(feature); |
} else { |
ajouterPoint(feature); |
} |
} |
if (donnees.features.length > 0) { |
afficherLegende(); |
} |
if (typeSite == 'maille') { |
genererInfobulleMailles(); |
function ajouterStation(feature) { |
if (feature.properties.typeSite == 'MAILLE') { |
traiterMaille(feature); |
} else { |
coucheSites.afficherClusters(); |
ajouterPoint(feature); |
} |
} |
// ========================================= |
function doitTransformerEnMaille(statsFeatures) { |
var condition1 = (formeDonnees == 'point' && statsFeatures.formeDonnees =='maille'); |
var condition2 = (formeDonnees == 'maille' && statsFeatures.formeDonnees =='point' |
&& determinerNombreMailles(false) > 0); |
var condition3 = (statsFeatures.formeDonnees == 'point' && map.getZoom() <= ZOOM_MAXIMUM_MAILLAGE |
&& (points.length+statsFeatures.sites) > SEUIL_MAILLAGE); |
return (condition1 || condition2 || condition3); |
} |
// ==================================================================== |
// Gestion des mailles |
var optionsMaille = { |
color: '#FFFFFF', |
opacity : 0.7, |
weight: 1, |
fillOpacity : 0.6 |
}; |
function determinerNombreMailles(prendToutesMailles) { |
var nombreMailles = 0; |
coucheSites.eachLayer(function(layer) { |
if ('typeSite' in layer && layer.typeSite == 'MAILLE') { |
var nombrePoints = 0; |
for (var source in layer.nombrePoints) { |
nombrePoints = layer.nombrePoints[source]; |
} |
if (prendToutesMailles || nombrePoints>0) { |
nombreMailles ++; |
} |
} |
}); |
return nombreMailles; |
} |
function traiterMaille(feature) { |
var coordonnees = []; |
for (var i = 0; i < feature.geometry.coordinates.length; i++) { |
528,16 → 529,15 |
var maille = rechercherMailleExistante(coordonnees); |
if (maille) { |
mettreAJourMaille(maille, feature); |
} else { |
maille = ajouterMaille(feature, coordonnees); |
} else if (feature.properties.nombrePoints > 0) { |
ajouterMaille(feature); |
} |
colorerMaille(maille); |
} |
function rechercherMailleExistante(coordonnees) { |
var mailleTrouvee = null; |
coucheSites.eachLayer(function(layer) { |
if ('typeSite' in layer && layer.typeSite == 'maille') { |
if ('typeSite' in layer && layer.typeSite == 'MAILLE') { |
if (sontMaillesIdentiques(coordonnees, layer._latlngs)) { |
mailleTrouvee = layer; |
return; |
556,49 → 556,60 |
); |
} |
function ajouterMaille(feature, coordonnees) { |
function ajouterMaille(feature) { |
var coordonnees = []; |
for (var i = 0; i < feature.geometry.coordinates.length; i++) { |
var sommet = new L.LatLng(feature.geometry.coordinates[i][0], feature.geometry.coordinates[i][1]); |
coordonnees.push(sommet); |
} |
var maille = new L.Polygon(coordonnees); |
var optionsMaille = { |
color: '#FFFFFF', |
opacity : 0.7, |
weight: 1, |
fillOpacity : 0.6 |
}; |
maille.setStyle(optionsMaille); |
maille.typeSite = 'maille'; |
maille.properties = feature.properties; |
maille.typeSite = feature.properties.typeSite; |
maille.nombrePoints = new Object(); |
var nombreAAjouter = feature.properties.nombrePoints == null ? 0 : parseInt(feature.properties.nombrePoints); |
maille.nombrePoints[feature.properties.source] = nombreAAjouter; |
coucheSites.addLayer(maille); |
return maille; |
colorerMaille(maille); |
} |
function mettreAJourMaille(maille, feature) { |
var sources = feature.properties.source; |
for (var index = 0; index < sources.length; index ++) { |
var source = sources[index]; |
maille.properties.stations[source] = parseInt(feature.properties.stations[source]); |
maille.properties.observations[source] = parseInt(feature.properties.observations[source]); |
maille.properties.source.push(source); |
} |
var nombreAAjouter = feature.properties.nombrePoints == null ? 0 : parseInt(feature.properties.nombrePoints); |
/*if (typeof(maille.nombrePoints[feature.properties.source]) == 'undefined') { |
maille.nombrePoints[feature.properties.source] = nombreAAjouter; |
} else { |
maille.nombrePoints[feature.properties.source] += nombreAAjouter; |
}*/ |
maille.nombrePoints[feature.properties.source] = nombreAAjouter; |
colorerMaille(maille); |
} |
function regenererInfobulleMailles() { |
$('.leaflet-clickable').addClass('tooltip'); |
coucheSites.eachLayer(function(layer) { |
if (layer.typeSite == 'MAILLE') { |
genererInfobulle(layer); |
} |
}); |
} |
function colorerMaille(maille) { |
var nombreStations = 0; |
var sources = maille.properties.source; |
for (var index = 0; index < sources.length; index ++) { |
var source = sources[index]; |
if (typeof(maille.properties.stations[source]) != 'undefined') { |
nombreStations += parseInt(maille.properties.stations[source]); |
} |
var nombrePoints = 0; |
for (sourceMaille in maille.nombrePoints) { |
nombrePoints += maille.nombrePoints[sourceMaille]; |
} |
if (nombreStations > 0) { |
if (nombrePoints > 0) { |
maille.on('click', surClicMaille); |
maille.setStyle({fillColor : genererCouleur(nombreStations), fillOpacity: 0.45, opacity: 0.7}); |
maille.setStyle({fillColor : genererCouleur(nombrePoints), fillOpacity: 0.45, opacity: 0.7}); |
} else { |
maille.setStyle({fillOpacity: 0, opacity: 0}); |
maille.off('click'); |
maille.off('click', surClicMaille); |
} |
} |
function surClicMaille(event) { |
map.fitBounds(event.layer.getBounds()); |
} |
function genererCouleur(nombrePoints) { |
var couleur = {'bleu': 231, 'vert': 224, 'rouge': 64}, |
seuils = [1, 10, 50 ,100, 500, 1000, 2500], |
611,27 → 622,17 |
return 'rgb('+couleur.bleu+','+couleur.vert+','+couleur.rouge+')'; |
} |
function surClicMaille(event) { |
map.fitBounds(event.layer.getBounds()); |
} |
function afficherLegende() { |
if (legende == null) { |
legende = new L.Control({position : 'bottomright'}); |
legende.onAdd = function(map) { |
var contenuHtml = ''; |
if (typeSite == 'maille') { |
contenuHtml = construireContenuHtmlLegendeMailles(); |
} else { |
contenuHtml = construireContenuHtmlLegendePoints(); |
} |
return contenuHtml; |
return construireContenuHtmlLegende(); |
}; |
map.addControl(legende); |
} |
} |
function construireContenuHtmlLegendeMailles() { |
function construireContenuHtmlLegende() { |
var div = L.DomUtil.create('div', 'info'); |
div.innerHTML = '<h4>' + titreLegende + '</h4>'; |
var seuils = [1, 10, 50 ,100, 500, 1000, 2500]; |
639,8 → 640,8 |
for (var i = 0; i < seuils.length; i ++) { |
div.innerHTML += |
'<div class="legend">'+ |
'<span class="couleur-maille" style="background:' + genererCouleur(seuils[i] + 1) + '">'+ |
'</span>'+seuils[i]+ (i + 1 < seuils.length ? '–' + seuils[i + 1] : '+')+ |
'<span style="background:' + genererCouleur(seuils[i] + 1) + '"></span>'+ |
seuils[i]+ (i + 1 < seuils.length ? '–' + seuils[i + 1] : '+')+ |
'</div>'; |
} |
return div; |
653,41 → 654,29 |
} |
} |
function genererInfobulleMailles() { |
coucheSites.eachLayer(function(layer) { |
if (layer.typeSite == 'maille') { |
genererInfobulle(layer); |
} |
}); |
function supprimerSourceDansMaille(maille, sourceSuppression) { |
if (typeof(maille.nombrePoints[sourceSuppression]) != 'undefined') { |
maille.nombrePoints[sourceSuppression] = 0; |
colorerMaille(maille); |
genererInfobulle(maille); |
} |
} |
function genererInfobulle(maille) { |
var sources = maille.properties.source; |
var textes = new Array(); |
for (var index = 0; index < sources.length; index ++) { |
var source = sources[index]; |
if (typeof(maille.properties.stations[source]) != 'undefined') { |
textes.push(source+" : "+maille.properties.stations[source]+" stations, " |
+maille.properties.observations[source]+" observations"); |
var nombrePoints = 0, |
nombreSources = 0; |
contenuTexte = ''; |
for (sourceMaille in maille.nombrePoints) { |
nombrePoints = maille.nombrePoints[sourceMaille]; |
if (nombrePoints > 0) { |
contenuTexte += (contenuTexte.length==0 ?'' : '\n')+ |
sourceMaille+' : '+maille.nombrePoints[sourceMaille]; |
} |
nombreSources ++; |
} |
var contenu = textes.join('<br />'); |
maille.on('mouseover', function() { |
afficherTooltip(contenu, map.latLngToContainerPoint(maille.getBounds().getSouthWest())); |
}); |
maille.on('mouseout', function() { |
$("#tooltip").css('display', 'none'); |
}); |
} |
function afficherTooltip(texte, point) { |
$("#tooltip").html(texte); |
if ($("#tooltip").css('display') == 'none') { |
var x = point.x - 15; |
var y = point.y + (typeSite == 'maille' ? 1 : 10); |
$("#tooltip").css('display', 'block'); |
$("#tooltip").css('left', x + 'px'); |
$("#tooltip").css('top', y + 'px'); |
if (nombreSources > 0) { |
$(maille._path).addClass('tooltip'); |
$(maille._path).attr('title',contenuTexte); |
} |
} |
695,73 → 684,136 |
// ==================================================================== |
// Gestion des points |
// Gestion des marqueurs |
function ajouterPoint(feature) { |
var iconePoint = new L.Icon({ iconUrl : pointImageUrl, iconSize : [16, 16] }), |
iconeCommune = new L.Icon({ iconUrl : communeImageUrl, iconSize : [24, 32] }), |
icone = (feature.properties.typeSite == 'STATION') ? iconePoint : iconeCommune, |
point = new L.LatLng(feature.geometry.coordinates[0], feature.geometry.coordinates[1]); |
var marker = new L.Cluster(point, { |
icon : icone, |
titre : feature.properties.nom |
}); |
marker.typeSite = feature.properties.typeSite.toLowerCase(); |
point = new L.LatLng(feature.geometry.coordinates[0], feature.geometry.coordinates[1]), |
marker = new L.Marker(point, { |
icon : icone, |
title : feature.properties.nom |
}) |
marker.typeSite = feature.properties.typeSite; |
marker.source = feature.properties.source; |
marker.on('click', surClicMarqueur); |
marker.on('mouseover', function() { |
afficherTooltip(marker.options.titre, map.latLngToContainerPoint(marker.getLatLng())); |
points.push(marker); |
if (formeDonnees != 'maille') { |
coucheSites.addLayer(marker); |
} else { |
ajouterPointDansMaille(marker); |
} |
} |
function ajouterPointDansMaille(point) { |
var maille = null; |
coucheSites.eachLayer(function(layer) { |
if (layer.typeSite == 'MAILLE' && layer.getBounds().contains(point.getLatLng())) { |
maille = layer; |
return; |
} |
}); |
marker.on('mouseout', function() { |
$("#tooltip").css('display', 'none'); |
if (typeof(maille.nombrePoints[point.source]) == 'undefined') { |
maille.nombrePoints[point.source] = 1; |
} else { |
maille.nombrePoints[point.source] += 1; |
} |
colorerMaille(maille); |
} |
function combinerMaillesEtPoints() { |
enleverMarqueursCarte(); |
coucheSites.eachLayer(function(layer) { |
if (layer.typeSite == 'MAILLE') { |
var nombrePoints = compterNombrePointsDansMaille(layer); |
ajouterNombrePointsDansMaille(layer, nombrePoints); |
} |
}); |
coucheSites.ajouterPoint(marker); |
} |
function construireContenuHtmlLegendePoints() { |
var div = L.DomUtil.create('div', 'info'); |
div.innerHTML = |
'<h4>Stations</h4>'+ |
'<div class="legend"><table>'+ |
'<tr>'+ |
'<td class="image-station"><img src="'+communeImageUrl+'" width="24" height="32" /></td>'+ |
'<td class="label-station">Commune</td>'+ |
'</tr>'+ |
'<tr>'+ |
'<td class="image-station"><img src="'+pointImageUrl+'" /></td>'+ |
'<td class="label-station">Lieu précis</td>'+ |
'</tr>'+ |
'<tr>'+ |
'<td class="image-station"><img src="'+clusterImageUrl+'" width="20" height="20" /></td>'+ |
'<td class="label-station">Groupe de stations proches</td>'+ |
'</tr>'+ |
'</table></div>'; |
return div; |
function determinerNombreMarqueurs(source) { |
var nombrePoints = 0; |
for (var index = 0; index < points.length; index ++) { |
if (points[index].source == source) { |
nombrePoints += 1; |
} |
} |
return nombrePoints; |
} |
function enleverMarqueursCarte() { |
coucheSites.eachLayer(function(layer) { |
if (layer.typeSite != 'MAILLE') { |
coucheSites.removeLayer(layer); |
} |
}); |
} |
function surClicMarqueur(event) { |
var nombreMarkers = event.target.recupererMarkers().length; |
if (nombreMarkers == 1 || map.getZoom() == map.getMaxZoom()) { |
recupererObservations(event.target); |
} else { |
map.setView(event.target.getLatLng(), Math.min(map.getZoom()+2, map.getMaxZoom())); |
function compterNombrePointsDansMaille(maille) { |
var nombrePoints = {}; |
for (var index = 0; index < points.length; index ++) { |
if (maille.getBounds().contains(points[index].getLatLng())) { |
var source = points[index].source; |
if (typeof(nombrePoints[source]) == 'undefined') { |
nombrePoints[source] = 1; |
} else { |
nombrePoints[source] += 1; |
} |
} |
} |
return nombrePoints; |
} |
function recupererObservations(cluster) { |
pointClique = cluster; |
var latlng = cluster.getLatLng(); |
function ajouterNombrePointsDansMaille(maille, nombrePoints) { |
for (sourceDonnees in nombrePoints) { |
if (typeof(maille.nombrePoints[sourceDonnees]) == 'undefined') { |
maille.nombrePoints[sourceDonnees] = nombrePoints[sourceDonnees]; |
} else { |
maille.nombrePoints[sourceDonnees] += nombrePoints[sourceDonnees]; |
} |
} |
colorerMaille(maille); |
} |
function supprimerPointsListe(sourceDonnees) { |
var index = 0; |
while (index < points.length) { |
if (points[index].source == sourceDonnees) { |
points.splice(index, 1); |
} else { |
index ++; |
} |
} |
} |
function transformerMaillesEnPoints(sourceDonnees) { |
coucheSites.eachLayer(function(layer) { |
if (layer.typeSite == 'MAILLE' && typeof(layer.nombrePoints[sourceDonnees]) != 'undefined') { |
supprimerSourceDansMaille(layer, sourceDonnees); |
} |
}); |
for (var index = 0; index < points.length; index ++) { |
coucheSites.addLayer(points[index]); |
} |
} |
function surClicMarqueur(event) { |
var latitude = event.target.getLatLng().lat; |
var longitude = event.target.getLatLng().lng; |
pointClique = event.target; |
afficherMessageChargement('observations'); |
var parametres = { |
"source" : recupererSourcesCluster(cluster), |
"stations" : construireListeStationsCluster(cluster), |
"source" : pointClique.source, |
"num_taxon" : numTaxon, |
"nn" : nn, |
"referentiel" : referentiel, |
"auteur" : auteur, |
"nn" : nn, |
"type_site" : pointClique.typeSite, |
"date_debut" : dateDebut, |
"date_fin" : dateFin, |
"longitude" : longitude, |
"latitude" : latitude, |
"nb_jours" : nbJours |
}; |
url = urlBase + "observations?" + convertirEnParametresUrl(parametres); |
769,27 → 821,6 |
executerAJAX(); |
} |
function recupererSourcesCluster(cluster) { |
var markers = cluster.recupererMarkers(); |
var sourcesCluster = []; |
for (var index = 0; index < markers.length; index ++) { |
if (sourcesCluster.indexOf(markers[index].source) == -1) { |
sourcesCluster.push(markers[index].source); |
} |
} |
return sourcesCluster.join(','); |
} |
function construireListeStationsCluster(cluster) { |
var markers = cluster.recupererMarkers(); |
var listePoints = []; |
for (var index = 0; index < markers.length; index ++) { |
var latlng = markers[index].getLatLng(); |
listePoints.push(markers[index].source+":"+markers[index].typeSite+":"+latlng.lng+","+latlng.lat); |
} |
return listePoints.join('|'); |
} |
function traiterDonneesObservations() { |
masquerMessageChargement(); |
var texte = requeteChargementPoints.responseText; |
810,9 → 841,13 |
} |
} |
function viderListeObservations() { |
obsStation = new Array(); |
} |
// ==================================================================== |
// Gestion de l'infobulle |
819,26 → 854,18 |
var obsJSON = null, |
pointClique = null, |
obsStation = [], |
pagineur = {'limite':100, 'start':0, 'total':0, 'stationId':null, 'format':'tableau'}; |
typeAffichage = ""; |
function afficherInfoBulle() { |
var latitude = pointClique.getLatLng().lat; |
var longitude = pointClique.getLatLng().lng; |
infoBulle = new L.Popup({maxWidth : definirLargeurInfoBulle(), maxHeight : 380}); |
infoBulle = new L.Popup({maxWidth : definirLargeurInfoBulle(), maxHeight : 350}); |
infoBulle.setLatLng(new L.LatLng(latitude, longitude)); |
infoBulle.setContent($("#tpl-obs").html()); |
infoBulle.openOn(map); |
infoBulle.openOn(map); |
remplirContenuPopup(); |
$('#info-bulle').css('width', '99%'); |
$('#observations').css('height', '250px'); |
$('#observations').css('overflow', 'auto'); |
$('.leaflet-popup-scrolled').css('overflow', 'visible'); |
} |
function viderListeObservations() { |
obsStation = new Array(); |
} |
function definirLargeurInfoBulle() { |
var largeurViewPort = $(window).width(); |
var lageurInfoBulle = null; |
853,14 → 880,14 |
} |
function redimensionnerPopup() { |
$('.leaflet-popup-content*').css('width', definirLargeurInfoBulle()); |
$('#info-bulle').css('width', '99%'); |
$('.leaflet-popup-content*').css('width', definirLargeurInfoBulle()); |
$('#info-bulle').css('width', definirLargeurInfoBulle()); |
} |
function remplirContenuPopup() { |
ajouterTableauTriable("#obs-tableau"); |
ajouterTitre(); |
afficherTableau(); |
afficherOnglets(); |
afficherTexteStationId(); |
} |
873,18 → 900,23 |
function ajouterTitre() { |
var texteStationTitre = obsJSON.total + ' observation' + (obsJSON.total > 1 ? 's' : '') |
+ ' sur ' + (pointClique.typeSite=='station' ? 'la station : ' : 'la commune : ') |
+ ' pour ' + (pointClique.options.type=='STATION' ? 'la station : ' : 'la commune : ') |
+ pointClique.options.title; |
$('#obs-station-titre').text(texteStationTitre); |
} |
function afficherTableau() { |
construireListeObservations(); |
afficherPagination(); |
afficherObservationsDansHTML(); |
function selectionnerOnglet() { |
$("#obs-vue-" + typeAffichage).css("display", "block"); |
$('#obs-tableau-lignes').empty(); |
$('#obs-liste-lignes').empty(); |
if (typeAffichage=='liste') { |
$("#obs-vue-tableau").css("display", "none"); |
} else { |
$("#obs-vue-liste").css("display", "none"); |
} |
} |
function construireListeObservations() { |
function ajouterObservationsDansHTML() { |
if (obsStation.length==0) { |
// premiere execution de la fonction : faire une copie des objets JSON decrivant les observations |
for (var index = 0; index < obsJSON.observations.length; index ++) { |
891,37 → 923,43 |
obsStation.push(obsJSON.observations[index]); |
} |
} |
pagineur.total = obsStation.length; |
var obsPage = []; |
for (var index = 0; index < obsStation.length; index ++) { |
obsPage.push(obsStation[index]); |
} |
$("#tpl-obs-"+typeAffichage).tmpl(obsPage).appendTo("#obs-"+typeAffichage+"-lignes"); |
} |
function afficherPagination() { |
$(".navigation").pagination(pagineur.total, { |
items_per_page:pagineur.limite, |
callback:afficherObservationsDansHTML, |
next_text:'Suivant', |
prev_text:'Précédent', |
prev_show_always:false, |
num_edge_entries:1, |
num_display_entries:4, |
load_first_page:true |
function afficherOnglets() { |
var $tabs = $('#obs').tabs(); |
$('#obs').bind('tabsselect', function(event, ui) { |
if (ui.panel.id == 'obs-vue-tableau') { |
surClicAffichageTableau(); |
} else if (ui.panel.id == 'obs-vue-liste') { |
surClicAffichageListe(); |
} |
}); |
if (obsJSON.total > 4) { |
surClicAffichageTableau(); |
} else { |
$tabs.tabs('select', "#obs-vue-liste"); |
} |
} |
function afficherObservationsDansHTML(indexPage) { |
$("#obs-tableau-lignes").empty(); |
if (typeof(indexPage) == 'undefined') { |
indexPage = 0; |
} |
var depart = indexPage * pagineur.limite; |
var obsPage = []; |
for (var index = depart; index < depart + pagineur.limite; index ++) { |
obsPage.push(obsStation[index]); |
} |
$("#tpl-obs-tableau").tmpl(obsPage).appendTo("#obs-tableau-lignes"); |
mettreAJourTableauTriable(); |
function surClicAffichageTableau() { |
typeAffichage = 'tableau'; |
selectionnerOnglet(); |
ajouterObservationsDansHTML(); |
mettreAJourTableauTriable("#obs-tableau"); |
} |
function ajouterTableauTriable() { |
function surClicAffichageListe() { |
typeAffichage = 'liste'; |
selectionnerOnglet(); |
ajouterObservationsDansHTML(); |
} |
function ajouterTableauTriable(element) { |
$.tablesorter.addParser({ |
id: 'date_cel', |
is: function(s) { |
930,29 → 968,28 |
}, |
format: function(date) { |
// Transformation date jj/mm/aaaa en aaaa/mm/jj |
date = date.replace(/^\s*(\d{2})[\/-](\d{2})[\/-](\d{4})\s*$/, "$3-$2-$1"); |
date = date.replace(/^\s*(\d{2})[\/-](\d{2})[\/-](\d{4})\s*$/, "$3/$2/$1"); |
// Remplace la date par un nombre de millisecondes pour trier numériquement |
return $.tablesorter.formatFloat(new Date(date).getTime()); |
}, |
type: 'numeric' |
}); |
$("#obs-tableau").tablesorter({ |
$(element).tablesorter({ |
headers: { |
1: { |
sorter:'date_cel' |
sorter:'date_cel' |
} |
} |
}); |
} |
function mettreAJourTableauTriable() { |
$("#obs-tableau").trigger('update'); |
function mettreAJourTableauTriable(element) { |
$(element).trigger('update'); |
} |
function afficherTexteStationId() { |
var latitude = pointClique.getLatLng().lat.toFixed(5); |
var longitude = pointClique.getLatLng().lng.toFixed(5); |
var texteStationId = pointClique.typeSite.toUpperCase() + ':' |
+ latitude + '|' + longitude + ', SOURCE:' + pointClique.source; |
var latitude = pointClique.getLatLng().lat; |
var longitude = pointClique.getLatLng().lng; |
var texteStationId = pointClique.typeSite+':'+latitude+'|'+longitude+', SOURCE:'+pointClique.source; |
$('#obs-station-id').text(texteStationId); |
} |
/trunk/widget/modules/carto/squelettes/scripts/L.KML.js |
---|
166,10 → 166,10 |
options.color = "#" + value.substring(2, 8); |
} else if (key === 'width') { |
options.weight = value; |
} else if (key === 'Icon') { |
} /*else if (key === 'Icon') { |
ioptions = _parse(e); |
if (ioptions.href) { options.href = ioptions.href; } |
} else if (key === 'href') { |
}*/ else if (key === 'href') { |
options.href = value; |
} |
} |
272,9 → 272,9 |
} |
} |
/*if (name) { |
if (name) { |
layer.bindPopup("<h2>" + name + "</h2>" + descr); |
}*/ |
} |
return layer; |
}, |
/trunk/widget/modules/carto/squelettes/scripts/layer/Layer.Deferred.js |
---|
New file |
0,0 → 1,57 |
L.DeferredLayer = L.LayerGroup.extend({ |
options: { |
js: [], |
init: null |
}, |
_script_cache: {}, |
initialize: function(options) { |
L.Util.setOptions(this, options); |
L.LayerGroup.prototype.initialize.apply(this); |
this._loaded = false; |
}, |
onAdd: function(map) { |
L.LayerGroup.prototype.onAdd.apply(this, [map]); |
if (this._loaded) return; |
//console.info("Script cache", this._script_cache); |
var loaded = function() { |
//console.info("Loaded", this, this.options); |
this._loaded = true; |
var l = this.options.init(); |
if (l) |
this.addLayer(l); |
} |
this._loadScripts(this.options.js.reverse(), L.Util.bind(loaded, this)); |
}, |
_loadScripts: function(scripts, cb, args) { |
if (!scripts || scripts.length == 0) |
return cb(args); |
var _this = this, s = scripts.pop(), c; |
c = this._script_cache[s]; |
if (c === undefined) { |
c = {url: s, wait: []}; |
//console.info("Load ", s); |
var script = document.createElement('script'); |
script.src = s; |
script.type = 'text/javascript'; |
script.onload = function () { |
//console.info("Element(cb)", c.e.readyState); |
c.e.readyState = "completed"; |
var i = 0; |
for (i = 0; i < c.wait.length; i++) |
c.wait[i](); |
} |
c.e = script; |
document.getElementsByTagName('head')[0].appendChild(script); |
} |
function _cb() { _this._loadScripts(scripts, cb, args); } |
c.wait.push(_cb); |
//console.info("Element", c.e.readyState); |
if (c.e.readyState == "completed") |
_cb(); |
this._script_cache[s] = c; |
} |
}); |
/trunk/widget/modules/carto/squelettes/scripts/layer/Marker.Rotate.js |
---|
New file |
0,0 → 1,32 |
/* |
* Based on comments by @runanet and @coomsie |
* https://github.com/CloudMade/Leaflet/issues/386 |
* |
* Wrapping function is needed to preserve L.Marker.update function |
*/ |
(function () { |
var _old_update = L.Marker.prototype.update; |
L.Marker.include({ |
update: function() { |
this._icon.style[L.DomUtil.TRANSFORM] = ""; |
_old_update.apply(this, []); |
if (this.options.iconAngle) { |
var a = this.options.icon.options.iconAnchor; |
var s = this.options.icon.options.iconSize; |
a = L.point(s).divideBy(2)._subtract(L.point(a)); |
var transform = ''; |
transform += ' translate(' + -a.x + 'px, ' + -a.y + 'px)'; |
transform += ' rotate(' + this.options.iconAngle + 'deg)'; |
transform += ' translate(' + a.x + 'px, ' + a.y + 'px)'; |
this._icon.style[L.DomUtil.TRANSFORM] += transform; |
} |
}, |
setIconAngle: function (iconAngle) { |
this.options.iconAngle = iconAngle; |
if (this._map) this.update(); |
} |
}); |
}()); |
/trunk/widget/modules/carto/squelettes/scripts/layer/Icon.Canvas.js |
---|
New file |
0,0 → 1,27 |
L.Icon.Canvas = L.Icon.extend({ |
options: { |
iconSize: new L.Point(20, 20), // Have to be supplied |
/* |
iconAnchor: (Point) |
popupAnchor: (Point) |
*/ |
className: 'leaflet-canvas-icon' |
}, |
createIcon: function () { |
var e = document.createElement('canvas'); |
this._setIconStyles(e, 'icon'); |
var s = this.options.iconSize; |
e.width = s.x |
e.height = s.y; |
this.draw(e.getContext('2d'), s.x, s.y); |
return e; |
}, |
createShadow: function () { |
return null; |
}, |
draw: function(canvas, width, height) { |
} |
}); |
/trunk/widget/modules/carto/squelettes/scripts/layer/tile/Yandex.js |
---|
New file |
0,0 → 1,157 |
/* |
* L.TileLayer is used for standard xyz-numbered tile layers. |
*/ |
//(function (ymaps, L) { |
L.Yandex = L.Class.extend({ |
includes: L.Mixin.Events, |
options: { |
minZoom: 0, |
maxZoom: 18, |
attribution: '', |
opacity: 1, |
traffic: false |
}, |
// Possible types: map, satellite, hybrid, publicMap, publicMapHybrid |
initialize: function(type, options) { |
L.Util.setOptions(this, options); |
this._type = "yandex#" + (type || 'map'); |
}, |
onAdd: function(map, insertAtTheBottom) { |
this._map = map; |
this._insertAtTheBottom = insertAtTheBottom; |
// create a container div for tiles |
this._initContainer(); |
this._initMapObject(); |
// set up events |
map.on('viewreset', this._resetCallback, this); |
this._limitedUpdate = L.Util.limitExecByInterval(this._update, 150, this); |
map.on('move', this._update, this); |
map._controlCorners['bottomright'].style.marginBottom = "3em"; |
this._reset(); |
this._update(true); |
}, |
onRemove: function(map) { |
this._map._container.removeChild(this._container); |
this._map.off('viewreset', this._resetCallback, this); |
this._map.off('move', this._update, this); |
map._controlCorners['bottomright'].style.marginBottom = "0em"; |
}, |
getAttribution: function() { |
return this.options.attribution; |
}, |
setOpacity: function(opacity) { |
this.options.opacity = opacity; |
if (opacity < 1) { |
L.DomUtil.setOpacity(this._container, opacity); |
} |
}, |
setElementSize: function(e, size) { |
e.style.width = size.x + "px"; |
e.style.height = size.y + "px"; |
}, |
_initContainer: function() { |
var tilePane = this._map._container, |
first = tilePane.firstChild; |
if (!this._container) { |
this._container = L.DomUtil.create('div', 'leaflet-yandex-layer leaflet-top leaflet-left'); |
this._container.id = "_YMapContainer_" + L.Util.stamp(this); |
this._container.style.zIndex = "auto"; |
} |
if (this.options.overlay) { |
first = this._map._container.getElementsByClassName('leaflet-map-pane')[0]; |
first = first.nextSibling; |
// XXX: Bug with layer order |
if (L.Browser.opera) |
this._container.className += " leaflet-objects-pane"; |
} |
tilePane.insertBefore(this._container, first); |
this.setOpacity(this.options.opacity); |
this.setElementSize(this._container, this._map.getSize()); |
}, |
_initMapObject: function() { |
if (this._yandex) return; |
// Check that ymaps.Map is ready |
if (ymaps.Map === undefined) { |
console.debug("L.Yandex: Waiting on ymaps.load('package.map')"); |
return ymaps.load(["package.map"], this._initMapObject, this); |
} |
// If traffic layer is requested check if control.TrafficControl is ready |
if (this.options.traffic) |
if (ymaps.control === undefined || |
ymaps.control.TrafficControl === undefined) { |
console.debug("L.Yandex: loading traffic and controls"); |
return ymaps.load(["package.traffic", "package.controls"], |
this._initMapObject, this); |
} |
var map = new ymaps.Map(this._container, {center: [0,0], zoom: 0, behaviors: []}); |
if (this.options.traffic) |
map.controls.add(new ymaps.control.TrafficControl({shown: true})); |
if (this._type == "yandex#null") { |
this._type = new ymaps.MapType("null", []); |
map.container.getElement().style.background = "transparent"; |
} |
map.setType(this._type) |
this._yandex = map; |
this._update(true); |
}, |
_resetCallback: function(e) { |
this._reset(e.hard); |
}, |
_reset: function(clearOldContainer) { |
this._initContainer(); |
}, |
_update: function(force) { |
if (!this._yandex) return; |
this._resize(force); |
var center = this._map.getCenter(); |
var _center = [center.lat, center.lng]; |
var zoom = this._map.getZoom(); |
if (force || this._yandex.getZoom() != zoom) |
this._yandex.setZoom(zoom); |
this._yandex.panTo(_center, {duration: 0, delay: 0}); |
}, |
_resize: function(force) { |
var size = this._map.getSize(), style = this._container.style; |
if (style.width == size.x + "px" && |
style.height == size.y + "px") |
if (force != true) return; |
this.setElementSize(this._container, size); |
var b = this._map.getBounds(), sw = b.getSouthWest(), ne = b.getNorthEast(); |
this._yandex.container.fitToViewport(); |
} |
}); |
//})(ymaps, L) |
/trunk/widget/modules/carto/squelettes/scripts/layer/tile/Google.js |
---|
New file |
0,0 → 1,176 |
/* |
* Google layer using Google Maps API |
*/ |
//(function (google, L) { |
L.Google = L.Class.extend({ |
includes: L.Mixin.Events, |
options: { |
minZoom: 0, |
maxZoom: 18, |
tileSize: 256, |
subdomains: 'abc', |
errorTileUrl: '', |
attribution: '', |
opacity: 1, |
continuousWorld: false, |
noWrap: false |
}, |
// Possible types: SATELLITE, ROADMAP, HYBRID, TERRAIN |
initialize: function(type, options) { |
L.Util.setOptions(this, options); |
this._ready = google.maps.Map != undefined; |
if (!this._ready) L.Google.asyncWait.push(this); |
this._type = type || 'SATELLITE'; |
}, |
onAdd: function(map, insertAtTheBottom) { |
this._map = map; |
this._insertAtTheBottom = insertAtTheBottom; |
// create a container div for tiles |
this._initContainer(); |
this._initMapObject(); |
// set up events |
map.on('viewreset', this._resetCallback, this); |
this._limitedUpdate = L.Util.limitExecByInterval(this._update, 150, this); |
map.on('move', this._update, this); |
//map.on('moveend', this._update, this); |
map._controlCorners['bottomright'].style.marginBottom = "1em"; |
this._reset(); |
this._update(); |
}, |
onRemove: function(map) { |
this._map._container.removeChild(this._container); |
//this._container = null; |
this._map.off('viewreset', this._resetCallback, this); |
this._map.off('move', this._update, this); |
map._controlCorners['bottomright'].style.marginBottom = "0em"; |
//this._map.off('moveend', this._update, this); |
}, |
getAttribution: function() { |
return this.options.attribution; |
}, |
setOpacity: function(opacity) { |
this.options.opacity = opacity; |
if (opacity < 1) { |
L.DomUtil.setOpacity(this._container, opacity); |
} |
}, |
setElementSize: function(e, size) { |
e.style.width = size.x + "px"; |
e.style.height = size.y + "px"; |
}, |
_initContainer: function() { |
var tilePane = this._map._container, |
first = tilePane.firstChild; |
if (!this._container) { |
this._container = L.DomUtil.create('div', 'leaflet-google-layer leaflet-top leaflet-left'); |
this._container.id = "_GMapContainer_" + L.Util.stamp(this); |
this._container.style.zIndex = "auto"; |
} |
if (true) { |
tilePane.insertBefore(this._container, first); |
this.setOpacity(this.options.opacity); |
this.setElementSize(this._container, this._map.getSize()); |
} |
}, |
_initMapObject: function() { |
if (!this._ready) return; |
this._google_center = new google.maps.LatLng(0, 0); |
var map = new google.maps.Map(this._container, { |
center: this._google_center, |
zoom: 0, |
tilt: 0, |
mapTypeId: google.maps.MapTypeId[this._type], |
disableDefaultUI: true, |
keyboardShortcuts: false, |
draggable: false, |
disableDoubleClickZoom: true, |
scrollwheel: false, |
streetViewControl: false |
}); |
var _this = this; |
this._reposition = google.maps.event.addListenerOnce(map, "center_changed", |
function() { _this.onReposition(); }); |
map.backgroundColor = '#ff0000'; |
this._google = map; |
}, |
_resetCallback: function(e) { |
this._reset(e.hard); |
}, |
_reset: function(clearOldContainer) { |
this._initContainer(); |
}, |
_update: function() { |
if (!this._google) return; |
this._resize(); |
var bounds = this._map.getBounds(); |
var ne = bounds.getNorthEast(); |
var sw = bounds.getSouthWest(); |
var google_bounds = new google.maps.LatLngBounds( |
new google.maps.LatLng(sw.lat, sw.lng), |
new google.maps.LatLng(ne.lat, ne.lng) |
); |
var center = this._map.getCenter(); |
var _center = new google.maps.LatLng(center.lat, center.lng); |
this._google.setCenter(_center); |
this._google.setZoom(this._map.getZoom()); |
//this._google.fitBounds(google_bounds); |
}, |
_resize: function() { |
var size = this._map.getSize(); |
if (this._container.style.width == size.x && |
this._container.style.height == size.y) |
return; |
this.setElementSize(this._container, size); |
this.onReposition(); |
}, |
onReposition: function() { |
if (!this._google) return; |
google.maps.event.trigger(this._google, "resize"); |
} |
}); |
L.Google.asyncWait = []; |
L.Google.asyncInitialize = function() { |
var i; |
for (i = 0; i < L.Google.asyncWait.length; i++) { |
var o = L.Google.asyncWait[i]; |
o._ready = true; |
if (o._container) { |
o._initMapObject(); |
o._update(); |
} |
} |
L.Google.asyncWait = []; |
} |
//})(window.google, L) |
/trunk/widget/modules/carto/squelettes/scripts/layer/tile/Bing.js |
---|
New file |
0,0 → 1,117 |
L.BingLayer = L.TileLayer.extend({ |
options: { |
subdomains: [0, 1, 2, 3], |
type: 'Aerial', |
attribution: 'Bing', |
culture: '' |
}, |
initialize: function(key, options) { |
L.Util.setOptions(this, options); |
this._key = key; |
this._url = null; |
this.meta = {}; |
this.loadMetadata(); |
}, |
tile2quad: function(x, y, z) { |
var quad = ''; |
for (var i = z; i > 0; i--) { |
var digit = 0; |
var mask = 1 << (i - 1); |
if ((x & mask) != 0) digit += 1; |
if ((y & mask) != 0) digit += 2; |
quad = quad + digit; |
} |
return quad; |
}, |
getTileUrl: function(p, z) { |
var z = this._getZoomForUrl(); |
var subdomains = this.options.subdomains, |
s = this.options.subdomains[Math.abs((p.x + p.y) % subdomains.length)]; |
return this._url.replace('{subdomain}', s) |
.replace('{quadkey}', this.tile2quad(p.x, p.y, z)) |
.replace('{culture}', this.options.culture); |
}, |
loadMetadata: function() { |
var _this = this; |
var cbid = '_bing_metadata_' + L.Util.stamp(this); |
window[cbid] = function (meta) { |
_this.meta = meta; |
window[cbid] = undefined; |
var e = document.getElementById(cbid); |
e.parentNode.removeChild(e); |
if (meta.errorDetails) { |
alert("Got metadata" + meta.errorDetails); |
return; |
} |
_this.initMetadata(); |
}; |
var url = "http://dev.virtualearth.net/REST/v1/Imagery/Metadata/" + this.options.type + "?include=ImageryProviders&jsonp=" + cbid + "&key=" + this._key; |
var script = document.createElement("script"); |
script.type = "text/javascript"; |
script.src = url; |
script.id = cbid; |
document.getElementsByTagName("head")[0].appendChild(script); |
}, |
initMetadata: function() { |
var r = this.meta.resourceSets[0].resources[0]; |
this.options.subdomains = r.imageUrlSubdomains; |
this._url = r.imageUrl; |
this._providers = []; |
for (var i = 0; i < r.imageryProviders.length; i++) { |
var p = r.imageryProviders[i]; |
for (var j = 0; j < p.coverageAreas.length; j++) { |
var c = p.coverageAreas[j]; |
var coverage = {zoomMin: c.zoomMin, zoomMax: c.zoomMax, active: false}; |
var bounds = new L.LatLngBounds( |
new L.LatLng(c.bbox[0]+0.01, c.bbox[1]+0.01), |
new L.LatLng(c.bbox[2]-0.01, c.bbox[3]-0.01) |
); |
coverage.bounds = bounds; |
coverage.attrib = p.attribution; |
this._providers.push(coverage); |
} |
} |
this._update(); |
}, |
_update: function() { |
if (this._url == null || !this._map) return; |
this._update_attribution(); |
L.TileLayer.prototype._update.apply(this, []); |
}, |
_update_attribution: function() { |
var bounds = this._map.getBounds(); |
var zoom = this._map.getZoom(); |
for (var i = 0; i < this._providers.length; i++) { |
var p = this._providers[i]; |
if ((zoom <= p.zoomMax && zoom >= p.zoomMin) && |
bounds.intersects(p.bounds)) { |
if (!p.active) |
this._map.attributionControl.addAttribution(p.attrib); |
p.active = true; |
} else { |
if (p.active) |
this._map.attributionControl.removeAttribution(p.attrib); |
p.active = false; |
} |
} |
}, |
onRemove: function(map) { |
for (var i = 0; i < this._providers.length; i++) { |
var p = this._providers[i]; |
if (p.active) { |
this._map.attributionControl.removeAttribution(p.attrib); |
p.active = false; |
} |
} |
L.TileLayer.prototype.onRemove.apply(this, [map]); |
} |
}); |
/trunk/widget/modules/carto/squelettes/scripts/layer/Marker.Text.js |
---|
New file |
0,0 → 1,51 |
L.Icon.Text = L.Icon.extend({ |
initialize: function (text, options) { |
this._text = text; |
L.Icon.prototype.initialize.apply(this, [options]); |
}, |
createIcon: function() { |
var el = document.createElement('div'); |
el.appendChild(document.createTextNode(this._text)); |
this._setIconStyles(el, 'icon'); |
el.style.textShadow = "2px 2px 2px #fff"; |
return el; |
}, |
createShadow: function() { return null; } |
}); |
L.Marker.Text = L.Marker.extend({ |
initialize: function (latlng, text, options) { |
L.Marker.prototype.initialize.apply(this, [latlng, options]); |
this._fakeicon = new L.Icon.Text(text); |
}, |
_initIcon: function() { |
L.Marker.prototype._initIcon.apply(this); |
var i = this._icon, s = this._shadow, obj = this.options.icon |
this._icon = this._shadow = null; |
this.options.icon = this._fakeicon; |
L.Marker.prototype._initIcon.apply(this); |
this.options.icon = obj; |
if (s) { |
s.parentNode.removeChild(s); |
this._icon.appendChild(s); |
} |
i.parentNode.removeChild(i); |
this._icon.appendChild(i); |
var w = this._icon.clientWidth, h = this._icon.clientHeight; |
this._icon.style.marginLeft = -w / 2 + "px"; |
//this._icon.style.backgroundColor = "red"; |
var off = new L.Point(w/2, 0); |
if (L.Browser.webkit) off.y = -h; |
L.DomUtil.setPosition(i, off); |
if (s) L.DomUtil.setPosition(s, off); |
} |
}); |
/trunk/widget/modules/carto/squelettes/scripts/layer/vector/GPX.Speed.js |
---|
New file |
0,0 → 1,80 |
//#include "GPX.js" |
(function() { |
function d2h(d) { |
var hex = '0123456789ABCDEF'; |
var r = ''; |
d = Math.floor(d); |
while (d != 0) { |
r = hex[d % 16] + r; |
d = Math.floor(d / 16); |
} |
while (r.length < 2) r = '0' + r; |
return r; |
} |
function gradient(color) { |
// First arc (0, PI) in HSV colorspace |
function f2h(d) { return d2h(256 * d); } |
if (color < 0) |
return "#FF0000"; |
else if (color < 1.0/3) |
return "#FF" + f2h(3 * color) + "00"; |
else if (color < 2.0/3) |
return "#" + f2h(2 - 3 * color) + "FF00"; |
else if (color < 1) |
return "#00FF" + f2h(3 * color - 2); |
else |
return "#00FFFF"; |
}; |
function gpx2time(s) { |
// 2011-09-24T12:07:53Z |
if (s.length != 10 + 1 + 8 + 1) |
return new Date(); |
return new Date(s); |
}; |
L.GPX.include({ |
options: { |
maxSpeed: 110, |
chunks: 200 |
}, |
speedSplitEnable: function(options) { |
L.Util.setOptions(this, options); |
return this.on('addline', this.speed_split, this); |
}, |
speedSplitDisable: function() { |
return this.off('addline', this.speed_split, this); |
}, |
speed_split: function(e) { |
var l = e.line.pop(), ll = l.getLatLngs(); |
var chunk = Math.floor(ll.length / this.options.chunks); |
if (chunk < 3) chunk = 3; |
var p = null; |
for (var i = 0; i < ll.length; i += chunk) { |
var d = 0, t = null; |
if (i + chunk > ll.length) |
chunk = ll.length - i; |
for (var j = 0; j < chunk; j++) { |
if (p) d += p.distanceTo(ll[i+j]); |
p = ll[i + j]; |
if (!t) t = gpx2time(p.meta.time); |
} |
p = ll[i + chunk - 1]; |
t = (gpx2time(p.meta.time) - t) / (3600 * 1000); |
var speed = 0.001 * d / t; |
//console.info('Dist: ' + d + "; Speed: " + speed); |
var color = gradient(speed / this.options.maxSpeed); |
var l = new L.Polyline(ll.slice(i, i+chunk+1), {color: color, weight: 2, opacity: 1}); |
l.bindPopup('Dist: ' + d.toFixed() + "m; Speed: " + speed.toFixed(2) + " km/h"); |
e.line.push(l); |
} |
} |
}); |
})(); |
/trunk/widget/modules/carto/squelettes/scripts/layer/vector/GPX.js |
---|
New file |
0,0 → 1,115 |
/*global L: true */ |
L.GPX = L.FeatureGroup.extend({ |
initialize: function(gpx, options) { |
L.Util.setOptions(this, options); |
this._gpx = gpx; |
this._layers = {}; |
if (gpx) { |
this.addGPX(gpx, options, this.options.async); |
} |
}, |
loadXML: function(url, cb, options, async) { |
if (async == undefined) async = this.options.async; |
if (options == undefined) options = this.options; |
var req = new window.XMLHttpRequest(); |
req.open('GET', url, async); |
try { |
req.overrideMimeType('text/xml'); // unsupported by IE |
} catch(e) {} |
req.onreadystatechange = function() { |
if (req.readyState != 4) return; |
if(req.status == 200) cb(req.responseXML, options); |
}; |
req.send(null); |
}, |
addGPX: function(url, options, async) { |
var _this = this; |
var cb = function(gpx, options) { _this._addGPX(gpx, options) }; |
this.loadXML(url, cb, options, async); |
}, |
_addGPX: function(gpx, options) { |
var layers = this.parseGPX(gpx, options); |
if (!layers) return; |
this.addLayer(layers); |
this.fire("loaded"); |
}, |
parseGPX: function(xml, options) { |
var j, i, el, layers = []; |
var named = false, tags = [['rte','rtept'], ['trkseg','trkpt']]; |
for (j = 0; j < tags.length; j++) { |
el = xml.getElementsByTagName(tags[j][0]); |
for (i = 0; i < el.length; i++) { |
var l = this.parse_trkseg(el[i], xml, options, tags[j][1]); |
for (var k = 0; k < l.length; k++) { |
if (this.parse_name(el[i], l[k])) named = true; |
layers.push(l[k]); |
} |
} |
} |
el = xml.getElementsByTagName('wpt'); |
for (i = 0; i < el.length; i++) { |
var l = this.parse_wpt(el[i], xml, options); |
if (!l) continue; |
if (this.parse_name(el[i], l)) named = true; |
layers.push(l); |
} |
if (!layers.length) return; |
var layer = layers[0]; |
if (layers.length > 1) |
layer = new L.FeatureGroup(layers); |
//if (!named) this.parse_name(xml, layer); |
return layer; |
}, |
parse_name: function(xml, layer) { |
var i, el, name, descr=""; |
el = xml.getElementsByTagName('name'); |
if (el.length) name = el[0].childNodes[0].nodeValue; |
el = xml.getElementsByTagName('desc'); |
for (i = 0; i < el.length; i++) { |
for (var j = 0; j < el[i].childNodes.length; j++) |
descr = descr + el[i].childNodes[j].nodeValue; |
} |
if (!name) return; |
var txt = "<h2>" + name + "</h2>" + descr; |
if (layer && layer._popup === undefined) layer.bindPopup(txt); |
return txt; |
}, |
parse_trkseg: function(line, xml, options, tag) { |
var el = line.getElementsByTagName(tag); |
if (!el.length) return []; |
var coords = []; |
for (var i = 0; i < el.length; i++) { |
var ll = new L.LatLng(el[i].getAttribute('lat'), |
el[i].getAttribute('lon')); |
ll.meta = {}; |
for (var j in el[i].childNodes) { |
var e = el[i].childNodes[j]; |
if (!e.tagName) continue; |
ll.meta[e.tagName] = e.textContent; |
} |
coords.push(ll); |
} |
var l = [new L.Polyline(coords, options)]; |
this.fire('addline', {line:l}) |
return l; |
}, |
parse_wpt: function(e, xml, options) { |
var m = new L.Marker(new L.LatLng(e.getAttribute('lat'), |
e.getAttribute('lon')), options); |
this.fire('addpoint', {point:m}); |
return m; |
} |
}); |
/trunk/widget/modules/carto/squelettes/scripts/layer/vector/OSM.js |
---|
New file |
0,0 → 1,172 |
/*global L: true */ |
L.OSM = L.FeatureGroup.extend({ |
options: { |
async: true, |
forceAll: false |
}, |
initialize: function(url, options) { |
L.Util.setOptions(this, options); |
this._url = url; |
this._layers = {}; |
if (url) { |
this.addXML(url, options, this.options.async); |
} |
}, |
loadXML: function(url, cb, options, async) { |
if (async == undefined) async = this.options.async; |
if (options == undefined) options = this.options; |
var req = new window.XMLHttpRequest(); |
req.open('GET', url, async); |
req.overrideMimeType('text/xml'); |
req.onreadystatechange = function() { |
if (req.readyState != 4) return; |
if(req.status == 200) cb(req.responseXML, options); |
}; |
req.send(null); |
}, |
addXML: function(url, options, async) { |
var _this = this; |
var cb = function(xml, options) { _this._addXML(xml, options) }; |
this.loadXML(url, cb, options, async); |
}, |
_addXML: function(xml, options) { |
var layers = this.parseOSM(xml, options); |
if (!layers) return; |
this.addLayer(layers); |
this.fire("loaded"); |
}, |
parseOSM: function(xml, options) { |
var i, el, ll, layers = []; |
var nodes = {}; |
var ways = {}; |
var named = false; |
el = xml.getElementsByTagName('node'); |
for (i = 0; i < el.length; i++) { |
var l = this.parse_node(el[i], xml, options); |
if (l == undefined) continue; |
nodes[l.osmid] = l; |
if (!this.options.forceAll && !l.tags.length) continue; |
var m = this.named_node(l, options); |
if (!ll) ll = m.getLatLng(); |
if (this.parse_name(m, l, "Node")) named = true; |
layers.push(m); |
} |
el = xml.getElementsByTagName('way'); |
for (i = 0; i < el.length; i++) { |
if (i > 10) break; |
var l = this.parse_way(el[i], nodes, options); |
if (!l) continue; |
if (!ll) ll = l.getLatLngs()[0]; |
if (this.parse_name(l, l, "Way")) named = true; |
layers.push(l); |
ways[l.osmid] = l; |
} |
el = xml.getElementsByTagName('relation'); |
for (i = 0; i < el.length; i++) { |
if (i > 10) break; |
var l = this.parse_relation(el[i], ways, options); |
if (!l) continue; |
if (!ll) ll = l.getLatLngs()[0]; |
if (this.parse_name(l, l, "Relation")) named = true; |
layers.push(l); |
} |
if (!layers.length) return; |
var layer = layers[0]; |
if (layers.length > 1) |
layer = new L.FeatureGroup(layers); |
if (!named) this.parse_name(xml, layer); |
layer.focusPoint = ll; |
return layer; |
}, |
parse_name: function(layer, obj, obj_name) { |
console.info("parse name"); |
console.info(this.options); |
if (!this.options.forceAll) |
if (!obj.tags || !obj.tags.length) return; |
var i, txt = "<table>"; |
for (i = 0; i < obj.tags.length; i++) { |
var t = obj.tags[i]; |
txt += "<tr><td>" + t.k + "</td><td>=</td><td>" + t.v + "</td></tr>"; |
} |
txt += "</table>" |
txt = "<h2>" + obj_name + " " + obj.osmid + "</h2>" + txt; |
if (layer) layer.bindPopup(txt); |
return txt; |
}, |
parse_tags: function(line) { |
var tags = [], el = line.getElementsByTagName('tag'); |
for (var i = 0; i < el.length; i++) |
tags.push({k: el[i].getAttribute('k'), v: el[i].getAttribute('v')}) |
return tags; |
}, |
parse_node: function(e) { |
var n = { osmid: e.getAttribute('id') |
, lat:e.getAttribute('lat') |
, lon:e.getAttribute('lon') |
} |
n.ll = new L.LatLng(n.lat, n.lon); |
n.tags = this.parse_tags(e); |
return n; |
}, |
parse_way: function(line, nodes, options) { |
var el = line.getElementsByTagName('nd'); |
if (!el.length) return; |
var coords = [], tags = []; |
for (var i = 0; i < el.length; i++) { |
var ref = el[i].getAttribute('ref'), n = nodes[ref]; |
if (!n) return; |
coords.push(n.ll); |
} |
var layer = new L.Polyline(coords, options); |
layer.tags = this.parse_tags(line); |
layer.osmid = line.getAttribute('id') |
return layer; |
}, |
parse_relation: function(line, ways, options) { |
var el = line.getElementsByTagName('member'); |
if (!el.length) return; |
var rt, coords = [], tags = this.parse_tags(line); |
for (var i = 0; i < tags.length; i++) |
if (tags[i].k == "type") rt = tags[i].v; |
if (rt != "multipolygon" && rt != "boundary" && rt != "waterway") |
return; |
for (var i = 0; i < el.length; i++) { |
var mt = el[i].getAttribute("type"), ref = el[i].getAttribute("ref"); |
if (mt != "way") continue; |
var w = ways[ref]; |
console.info("Way: " + ref + " " + w); |
if (!w) return; |
coords.push(w); |
} |
console.info("Coords: " + coords.length); |
if (!coords.length) return; |
var layer = new L.MultiPolyline(coords, options); |
layer.tags = this.parse_tags(line); |
layer.osmid = line.getAttribute('id') |
return layer; |
}, |
named_node: function(node, options) { |
var marker = new L.Marker(new L.LatLng(node.lat, node.lon), options); |
return marker; |
} |
}); |
/trunk/widget/modules/carto/squelettes/scripts/layer/vector/KML.js |
---|
New file |
0,0 → 1,337 |
/*global L: true */ |
L.KML = L.FeatureGroup.extend({ |
options: { |
async: true |
}, |
initialize: function(kml, options) { |
L.Util.setOptions(this, options); |
this._kml = kml; |
this._layers = {}; |
if (kml) { |
this.addKML(kml, options, this.options.async); |
} |
}, |
loadXML: function(url, cb, options, async) { |
if (async == undefined) async = this.options.async; |
if (options == undefined) options = this.options; |
var req = new window.XMLHttpRequest(); |
req.open('GET', url, async); |
try { |
req.overrideMimeType('text/xml'); // unsupported by IE |
} catch(e) {} |
req.onreadystatechange = function() { |
if (req.readyState != 4) return; |
if(req.status == 200) cb(req.responseXML, options); |
}; |
req.send(null); |
}, |
addKML: function(url, options, async) { |
var _this = this; |
var cb = function(gpx, options) { _this._addKML(gpx, options) }; |
this.loadXML(url, cb, options, async); |
}, |
_addKML: function(xml, options) { |
var layers = L.KML.parseKML(xml); |
if (!layers || !layers.length) return; |
for (var i = 0; i < layers.length; i++) |
{ |
this.fire('addlayer', { |
layer: layers[i] |
}); |
this.addLayer(layers[i]); |
} |
this.latLngs = L.KML.getLatLngs(xml); |
this.fire("loaded"); |
}, |
latLngs: [] |
}); |
L.Util.extend(L.KML, { |
parseKML: function (xml) { |
var style = this.parseStyle(xml); |
var el = xml.getElementsByTagName("Folder"); |
var layers = [], l; |
for (var i = 0; i < el.length; i++) { |
if (!this._check_folder(el[i])) { continue; } |
l = this.parseFolder(el[i], style); |
if (l) { layers.push(l); } |
} |
el = xml.getElementsByTagName('Placemark'); |
for (var j = 0; j < el.length; j++) { |
if (!this._check_folder(el[j])) { continue; } |
l = this.parsePlacemark(el[j], xml, style); |
if (l) { layers.push(l); } |
} |
return layers; |
}, |
// Return false if e's first parent Folder is not [folder] |
// - returns true if no parent Folders |
_check_folder: function (e, folder) { |
e = e.parentElement; |
while (e && e.tagName !== "Folder") |
{ |
e = e.parentElement; |
} |
return !e || e === folder; |
}, |
parseStyle: function (xml) { |
var style = {}; |
var sl = xml.getElementsByTagName("Style"); |
//for (var i = 0; i < sl.length; i++) { |
var attributes = {color: true, width: true, Icon: true, href: true, |
hotSpot: true}; |
function _parse(xml) { |
var options = {}; |
for (var i = 0; i < xml.childNodes.length; i++) { |
var e = xml.childNodes[i]; |
var key = e.tagName; |
if (!attributes[key]) { continue; } |
if (key === 'hotSpot') |
{ |
for (var j = 0; j < e.attributes.length; j++) { |
options[e.attributes[j].name] = e.attributes[j].nodeValue; |
} |
} else { |
var value = e.childNodes[0].nodeValue; |
if (key === 'color') { |
options.opacity = parseInt(value.substring(0, 2), 16) / 255.0; |
options.color = "#" + value.substring(2, 8); |
} else if (key === 'width') { |
options.weight = value; |
} else if (key === 'Icon') { |
ioptions = _parse(e); |
if (ioptions.href) { options.href = ioptions.href; } |
} else if (key === 'href') { |
options.href = value; |
} |
} |
} |
return options; |
} |
for (var i = 0; i < sl.length; i++) { |
var e = sl[i], el; |
var options = {}, poptions = {}, ioptions = {}; |
el = e.getElementsByTagName("LineStyle"); |
if (el && el[0]) { options = _parse(el[0]); } |
el = e.getElementsByTagName("PolyStyle"); |
if (el && el[0]) { poptions = _parse(el[0]); } |
if (poptions.color) { options.fillColor = poptions.color; } |
if (poptions.opacity) { options.fillOpacity = poptions.opacity; } |
el = e.getElementsByTagName("IconStyle"); |
if (el && el[0]) { ioptions = _parse(el[0]); } |
if (ioptions.href) { |
// save anchor info until the image is loaded |
options.icon = new L.KMLIcon({ |
iconUrl: ioptions.href, |
shadowUrl: null, |
iconAnchorRef: {x: ioptions.x, y: ioptions.y}, |
iconAnchorType: {x: ioptions.xunits, y: ioptions.yunits} |
}); |
} |
style['#' + e.getAttribute('id')] = options; |
} |
return style; |
}, |
parseFolder: function (xml, style) { |
var el, layers = [], l; |
el = xml.getElementsByTagName('Folder'); |
for (var i = 0; i < el.length; i++) { |
if (!this._check_folder(el[i], xml)) { continue; } |
l = this.parseFolder(el[i], style); |
if (l) { layers.push(l); } |
} |
el = xml.getElementsByTagName('Placemark'); |
for (var j = 0; j < el.length; j++) { |
if (!this._check_folder(el[j], xml)) { continue; } |
l = this.parsePlacemark(el[j], xml, style); |
if (l) { layers.push(l); } |
} |
if (!layers.length) { return; } |
if (layers.length === 1) { return layers[0]; } |
return new L.FeatureGroup(layers); |
}, |
parsePlacemark: function (place, xml, style) { |
var i, j, el, options = {}; |
el = place.getElementsByTagName('styleUrl'); |
for (i = 0; i < el.length; i++) { |
var url = el[i].childNodes[0].nodeValue; |
for (var a in style[url]) |
{ |
// for jshint |
if (true) |
{ |
options[a] = style[url][a]; |
} |
} |
} |
var layers = []; |
var parse = ['LineString', 'Polygon', 'Point']; |
for (j in parse) { |
// for jshint |
if (true) |
{ |
var tag = parse[j]; |
el = place.getElementsByTagName(tag); |
for (i = 0; i < el.length; i++) { |
var l = this["parse" + tag](el[i], xml, options); |
if (l) { layers.push(l); } |
} |
} |
} |
if (!layers.length) { |
return; |
} |
var layer = layers[0]; |
if (layers.length > 1) { |
layer = new L.FeatureGroup(layers); |
} |
var name, descr = ""; |
el = place.getElementsByTagName('name'); |
if (el.length) { |
name = el[0].childNodes[0].nodeValue; |
} |
el = place.getElementsByTagName('description'); |
for (i = 0; i < el.length; i++) { |
for (j = 0; j < el[i].childNodes.length; j++) { |
descr = descr + el[i].childNodes[j].nodeValue; |
} |
} |
if (name) { |
layer.bindPopup("<h2>" + name + "</h2>" + descr); |
} |
return layer; |
}, |
parseCoords: function (xml) { |
var el = xml.getElementsByTagName('coordinates'); |
return this._read_coords(el[0]); |
}, |
parseLineString: function (line, xml, options) { |
var coords = this.parseCoords(line); |
if (!coords.length) { return; } |
return new L.Polyline(coords, options); |
}, |
parsePoint: function (line, xml, options) { |
var el = line.getElementsByTagName('coordinates'); |
if (!el.length) { |
return; |
} |
var ll = el[0].childNodes[0].nodeValue.split(','); |
return new L.KMLMarker(new L.LatLng(ll[1], ll[0]), options); |
}, |
parsePolygon: function (line, xml, options) { |
var el, polys = [], inner = [], i, coords; |
el = line.getElementsByTagName('outerBoundaryIs'); |
for (i = 0; i < el.length; i++) { |
coords = this.parseCoords(el[i]); |
if (coords) { |
polys.push(coords); |
} |
} |
el = line.getElementsByTagName('innerBoundaryIs'); |
for (i = 0; i < el.length; i++) { |
coords = this.parseCoords(el[i]); |
if (coords) { |
inner.push(coords); |
} |
} |
if (!polys.length) { |
return; |
} |
if (options.fillColor) { |
options.fill = true; |
} |
if (polys.length === 1) { |
return new L.Polygon(polys.concat(inner), options); |
} |
return new L.MultiPolygon(polys, options); |
}, |
getLatLngs: function (xml) { |
var el = xml.getElementsByTagName('coordinates'); |
var coords = []; |
for (var j = 0; j < el.length; j++) { |
// text might span many childnodes |
coords = coords.concat(this._read_coords(el[j])); |
} |
return coords; |
}, |
_read_coords: function (el) { |
var text = "", coords = [], i; |
for (i = 0; i < el.childNodes.length; i++) { |
text = text + el.childNodes[i].nodeValue; |
} |
text = text.split(/[\s\n]+/); |
for (i = 0; i < text.length; i++) { |
var ll = text[i].split(','); |
if (ll.length < 2) { |
continue; |
} |
coords.push(new L.LatLng(ll[1], ll[0])); |
} |
return coords; |
} |
}); |
L.KMLIcon = L.Icon.extend({ |
createIcon: function () { |
var img = this._createIcon('icon'); |
img.onload = function () { |
var i = new Image(); |
i.src = this.src; |
this.style.width = i.width + 'px'; |
this.style.height = i.height + 'px'; |
if (this.anchorType.x === 'UNITS_FRACTION' || this.anchorType.x === 'fraction') { |
img.style.marginLeft = (-this.anchor.x * i.width) + 'px'; |
} |
if (this.anchorType.y === 'UNITS_FRACTION' || this.anchorType.x === 'fraction') { |
img.style.marginTop = (-(1 - this.anchor.y) * i.height) + 'px'; |
} |
this.style.display = ""; |
}; |
return img; |
}, |
_setIconStyles: function (img, name) { |
L.Icon.prototype._setIconStyles.apply(this, [img, name]) |
// save anchor information to the image |
img.anchor = this.options.iconAnchorRef; |
img.anchorType = this.options.iconAnchorType; |
} |
}); |
L.KMLMarker = L.Marker.extend({ |
options: { |
icon: new L.KMLIcon.Default() |
} |
}); |
/trunk/widget/modules/carto/squelettes/scripts/layer/OpenStreetBugs.js |
---|
New file |
0,0 → 1,497 |
L.OpenStreetBugs = L.FeatureGroup.extend({ |
options : { |
serverURL : "http://openstreetbugs.schokokeks.org/api/0.1/", |
readonly : false, |
setCookie : true, |
username : "NoName", |
cookieLifetime : 1000, |
cookiePath : null, |
permalinkZoom : 14, |
permalinkUrl: null, |
opacity : 0.7, |
showOpen: true, |
showClosed: true, |
iconOpen: "http://openstreetbugs.schokokeks.org/client/open_bug_marker.png", |
iconClosed:"http://openstreetbugs.schokokeks.org/client/closed_bug_marker.png", |
iconActive: undefined, |
editArea: 0.01, |
popupOptions: {autoPan: false}, |
dblClick: true |
}, |
initialize : function(options) |
{ |
var tmp = L.Util.extend({}, this.options.popupOptions, (options || {}).popupOptions) |
L.Util.setOptions(this, options) |
this.options.popupOptions = tmp; |
putAJAXMarker.layers.push(this); |
this.bugs = {}; |
this._layers = {}; |
var username = this.get_cookie("osbUsername"); |
if (username) |
this.options.username = username; |
L.OpenStreetBugs.setCSS(); |
}, |
onAdd : function(map) |
{ |
L.FeatureGroup.prototype.onAdd.apply(this, [map]); |
this._map.on("moveend", this.loadBugs, this); |
this.loadBugs(); |
if (!this.options.readonly) { |
if (this.options.dblClick) { |
map.doubleClickZoom.disable(); |
map.on('dblclick', this.addBug, this); |
} |
else { |
map.on('click', this.addBug, this); |
} |
} |
this.fire('add'); |
}, |
onRemove : function(map) |
{ |
this._map.off("moveend", this.loadBugs, this); |
this._iterateLayers(map.removeLayer, map); |
delete this._map; |
if (!this.options.readonly) { |
if (this.options.dblClick) { |
map.doubleClickZoom.enable(); |
map.off('dblclick', this.addBug, this); |
} |
else { |
map.off('click', this.addBug, this); |
} |
} |
this.fire('remove'); |
}, |
set_cookie : function(name, value) |
{ |
var expires = (new Date((new Date()).getTime() + 604800000)).toGMTString(); // one week from now |
document.cookie = name+"="+escape(value)+";"; |
}, |
get_cookie : function(name) |
{ |
var cookies = (document.cookie || '').split(/;\s*/); |
for(var i=0; i<cookies.length; i++) |
{ |
var cookie = cookies[i].split("="); |
if(cookie[0] == name) |
return unescape(cookie[1]); |
} |
return null; |
}, |
loadBugs : function() |
{ |
//if(!this.getVisibility()) |
// return true; |
var bounds = this._map.getBounds(); |
if(!bounds) return false; |
var sw = bounds.getSouthWest(), ne = bounds.getNorthEast(); |
function round(number, digits) { |
var factor = Math.pow(10, digits); |
return Math.round(number*factor)/factor; |
} |
this.apiRequest("getBugs" |
+ "?t="+round(ne.lat, 5) |
+ "&r="+round(ne.lng, 5) |
+ "&b="+round(sw.lat, 5) |
+ "&l="+round(sw.lng, 5)); |
}, |
apiRequest : function(url, reload) |
{ |
var script = document.createElement("script"); |
script.type = "text/javascript"; |
script.src = this.options.serverURL + url + "&nocache="+(new Date()).getTime(); |
var _this = this; |
script.onload = function(e) { |
document.body.removeChild(this); |
if (reload) _this.loadBugs(); |
}; |
document.body.appendChild(script); |
}, |
createMarker: function(id, force) |
{ |
var bug = putAJAXMarker.bugs[id]; |
if(this.bugs[id]) |
{ |
if (force || this.bugs[id].osb.closed != bug[2]) |
this.removeLayer(this.bugs[id]); |
else |
return; |
} |
var closed = bug[2]; |
if (closed && !this.options.showClosed) return; |
if (!closed && !this.options.showOpen) return; |
var icon_url = null; |
var class_popup = ' osb'; |
if (bug[2]) { |
icon_url = this.options.iconClosed; |
class_popup += ' osbClosed'; |
} |
else if (bug[1].length == 1) { |
icon_url = this.options.iconOpen; |
class_popup += ' osbOpen'; |
} |
else { |
if (this.options.iconActive) { |
icon_url = this.options.iconActive; |
class_popup += ' osbActive'; |
} |
else { |
icon_url = this.options.iconOpen; |
class_popup += ' osbOpen'; |
} |
} |
var feature = new L.Marker(bug[0], {icon:new this.osbIcon({iconUrl: icon_url})}); |
feature.osb = {id: id, closed: closed}; |
this.addLayer(feature); |
this.bugs[id] = feature; |
this.setPopupContent(id); |
feature._popup.options.className += class_popup; |
if (this.options.bugid && (parseInt(this.options.bugid) == id)) |
feature.openPopup(); |
//this.events.triggerEvent("markerAdded"); |
}, |
osbIcon : L.Icon.extend({ |
options: { |
iconUrl: 'http://openstreetbugs.schokokeks.org/client/open_bug_marker.png', |
iconSize: new L.Point(22, 22), |
shadowSize: new L.Point(0, 0), |
iconAnchor: new L.Point(11, 11), |
popupAnchor: new L.Point(0, -11) |
} |
}), |
setPopupContent: function(id) { |
if(this.bugs[id]._popup_content) |
return; |
var el1,el2,el3; |
var layer = this; |
var rawbug = putAJAXMarker.bugs[id]; |
var isclosed = rawbug[2]; |
var newContent = L.DomUtil.create('div', 'osb-popup'); |
var h1 = L.DomUtil.create('h1', null, newContent); |
if (rawbug[2]) |
h1.textContent = L.i18n("Fixed Error"); |
else if (rawbug[1].length == 1) |
h1.textContent = L.i18n("Unresolved Error"); |
else |
h1.textContent = L.i18n("Active Error"); |
var divinfo = L.DomUtil.create('div', 'osb-info', newContent); |
var table = L.DomUtil.create('table', 'osb-table', divinfo); |
for(var i=0; i<rawbug[1].length; i++) |
{ |
var tr = L.DomUtil.create('tr', "osb-tr-info", table); |
tr.setAttribute("valign","top") |
var td = L.DomUtil.create('td', "osb-td-nickname", tr); |
td.textContent = rawbug[5][i] + ':'; |
var td = L.DomUtil.create('td', "osb-td-datetime", tr); |
td.textContent = rawbug[6][i]; |
var td = L.DomUtil.create('td', "osb-td-comment", L.DomUtil.create('tr', "osb-tr-comment", table)); |
td.setAttribute("colspan","2"); |
td.setAttribute("charoff","2"); |
td.textContent = rawbug[4][i]; |
} |
function create_link(ul, text) { |
var a = L.DomUtil.create('a', null, |
L.DomUtil.create('li', null, ul)); |
a.href = '#'; |
a.textContent = L.i18n(text); |
return a; |
}; |
var ul = L.DomUtil.create('ul', null, newContent); |
var _this = this; |
var bug = this.bugs[id]; |
function showComment(title, add_comment) { |
h1.textContent_old = h1.textContent; |
h1.textContent = L.i18n(title); |
var form = _this.createCommentForm(); |
form.osbid.value = id; |
form.cancel.onclick = function (e) { |
h1.textContent = h1.textContent_old; |
newContent.removeChild(form); |
newContent.appendChild(ul); |
} |
form.ok.onclick = function(e) { |
bug.closePopup(); |
if (!add_comment) |
_this.closeBug(form); |
else |
_this.submitComment(form); |
return false; |
}; |
newContent.appendChild(form); |
newContent.removeChild(ul); |
return false; |
}; |
if (!isclosed && !this.options.readonly) { |
var a; |
a = create_link(ul, "Add comment"); |
a.onclick = function(e) { return showComment("Add comment", true); } |
a = create_link(ul, "Mark as Fixed"); |
a.onclick = function(e) { return showComment("Close bug", false); } |
} |
var a = create_link(ul, "JOSM"); |
a.onclick = function() { _this.remoteEdit(rawbug[0]); }; |
var a = create_link(ul, "Link"); |
var vars = {lat:rawbug[0].lat, lon:rawbug[0].lng, zoom:this.options.permalinkZoom, bugid:id} |
if (this.options.permalinkUrl) |
a.href = L.Util.template(this.options.permalinkUrl, vars) |
else |
a.href = location.protocol + '//' + location.host + location.pathname + |
L.Util.getParamString(vars) |
bug._popup_content = newContent; |
bug.bindPopup(newContent, this.options.popupOptions); |
bug._popup.options.maxWidth=410; |
bug._popup.options.minWidth=410; |
bug.on('mouseover', bug.openTempPopup, bug); |
}, |
submitComment: function(form) { |
if (!form.osbcomment.value) return; |
var nickname = form.osbnickname.value || this.options.username; |
this.apiRequest("editPOIexec" |
+ "?id="+encodeURIComponent(form.osbid.value) |
+ "&text="+encodeURIComponent(form.osbcomment.value + " [" + nickname + "]") |
+ "&format=js", true |
); |
this.set_cookie("osbUsername",nickname); |
this.options.username=nickname; |
}, |
closeBug: function(form) { |
var id = form.osbid.value; |
this.submitComment(form); |
this.apiRequest("closePOIexec" |
+ "?id="+encodeURIComponent(id) |
+ "&format=js", true |
); |
}, |
createCommentForm: function(elt) { |
var form = L.DomUtil.create("form", 'osb-add-comment', elt); |
var content = ''; |
content += '<input name="osbid" type="hidden"/>'; |
content += '<input name="osblat" type="hidden"/>'; |
content += '<input name="osblon" type="hidden"/>'; |
content += '<div><span class="osb-inputlabel">'+L.i18n('Nickname')+':</span><input type="text" name="osbnickname"></div>'; |
content += '<div><span class="osb-inputlabel">'+L.i18n('Comment')+':</span><input type="text" name="osbcomment"></div>'; |
content += '<div class="osb-formfooter"><input type="submit" name="ok"/><input type="button" name="cancel"/></div>'; |
form.innerHTML = content; |
form.ok.value = L.i18n('OK'); |
form.cancel.value = L.i18n('Cancel'); |
form.osbnickname.value = this.options.username; |
return form; |
}, |
addBug: function(e) { |
var newContent = L.DomUtil.create('div', 'osb-popup'); |
newContent.innerHTML += '<h1>'+L.i18n("New bug")+'</h1>'; |
newContent.innerHTML += '<div class="osbCreateInfo">'+L.i18n("Find your bug?")+'<br />'+L.i18n("Contact details and someone will fix it.")+'</div>'; |
var popup = new L.Popup(); |
var _this = this; |
var form = this.createCommentForm(newContent); |
form.osblat.value = e.latlng.lat; |
form.osblon.value = e.latlng.lng; |
form.ok.value = L.i18n("Add comment"); |
form.onsubmit = function(e) { |
_this._map.closePopup(popup); |
_this.createBug(form); |
return false; |
}; |
form.cancel.onclick = function(e) { _this._map.closePopup(popup); } |
popup.setLatLng(e.latlng); |
popup.setContent(newContent); |
popup.options.maxWidth=410; |
popup.options.minWidth=410; |
popup.options.className += ' osb osbCreate' |
this._map.openPopup(popup); |
}, |
createBug: function(form) { |
if (!form.osbcomment.value) return; |
var nickname = form.osbnickname.value || this.options.username; |
this.apiRequest("addPOIexec" |
+ "?lat="+encodeURIComponent(form.osblat.value) |
+ "&lon="+encodeURIComponent(form.osblon.value) |
+ "&text="+encodeURIComponent(form.osbcomment.value + " [" + nickname + "]") |
+ "&format=js", true |
); |
this.set_cookie("osbUsername",nickname); |
this.options.username=nickname; |
}, |
remoteEdit: function(x) { |
var ydelta = this.options.editArea || 0.01; |
var xdelta = ydelta * 2; |
var p = [ 'left=' + (x.lng - xdelta), 'bottom=' + (x.lat - ydelta) |
, 'right=' + (x.lng + xdelta), 'top=' + (x.lat + ydelta)]; |
var url = 'http://localhost:8111/load_and_zoom?' + p.join('&'); |
var frame = L.DomUtil.create('iframe', null); |
frame.style.display = 'none'; |
frame.src = url; |
document.body.appendChild(frame); |
frame.onload = function(e) { document.body.removeChild(frame); }; |
return false; |
} |
}) |
L.OpenStreetBugs.setCSS = function() { |
if(L.OpenStreetBugs.setCSS.done) |
return; |
else |
L.OpenStreetBugs.setCSS.done = true; |
// See http://www.hunlock.com/blogs/Totally_Pwn_CSS_with_Javascript |
var idx = 0; |
var addRule = function(selector, rules) { |
var s = document.styleSheets[0]; |
var rule; |
if(s.addRule) // M$IE |
rule = s.addRule(selector, rules, idx); |
else |
rule = s.insertRule(selector + " { " + rules + " }", idx); |
s.style = L.Util.extend(s.style || {}, rules); |
idx++; |
}; |
addRule(".osb-popup dl", 'margin:0; padding:0;'); |
addRule(".osb-popup dt", 'margin:0; padding:0; font-weight:bold; float:left; clear:left;'); |
addRule(".osb-popup dt:after", 'content: ": ";'); |
addRule("* html .osb-popup dt", 'margin-right:1ex;'); |
addRule(".osb-popup dd", 'margin:0; padding:0;'); |
addRule(".osb-popup ul.buttons", 'list-style-type:none; padding:0; margin:0;'); |
addRule(".osb-popup ul.buttons li", 'display:inline; margin:0; padding:0;'); |
addRule(".osb-popup h3", 'font-size:1.2em; margin:.2em 0 .7em 0;'); |
}; |
function putAJAXMarker(id, lon, lat, text, closed) |
{ |
var comments = text.split(/<hr \/>/); |
var comments_only = [] |
var nickname = []; |
var datetime = []; |
var info = null; |
var isplit = 0; |
for(var i=0; i<comments.length; i++) { |
info = null; |
isplit = 0; |
comments[i] = comments[i].replace(/"/g, "\"").replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&"); |
isplit = comments[i].lastIndexOf("["); |
if (isplit > 0) { |
comments_only[i] = comments[i].substr(0,isplit-1); |
info = comments[i].substr(isplit+1); |
nickname[i] = info.substr(0,info.lastIndexOf(",")); |
datetime[i] = info.substr(info.lastIndexOf(",")+2); |
datetime[i] = datetime[i].substr(0,datetime[i].lastIndexOf("]")); |
} |
else { |
comments_only[i] = comments[i]; |
} |
} |
var old = putAJAXMarker.bugs[id]; |
putAJAXMarker.bugs[id] = [ |
new L.LatLng(lat, lon), |
comments, |
closed, |
text, |
comments_only, |
nickname, |
datetime |
]; |
var force = (old && old[3]) != text; |
for(var i=0; i<putAJAXMarker.layers.length; i++) |
putAJAXMarker.layers[i].createMarker(id, force); |
} |
function osbResponse(error) |
{ |
if(error) |
alert("Error: "+error); |
return; |
for(var i=0; i<putAJAXMarker.layers.length; i++) |
putAJAXMarker.layers[i].loadBugs(); |
} |
putAJAXMarker.layers = [ ]; |
putAJAXMarker.bugs = { }; |
L.Marker.include({ |
openTempPopup: function() { |
this.openPopup(); |
this.off('click', this.openPopup, this); |
function onclick() { |
this.off('mouseout', onout, this); |
this.off('click', onclick, this); |
this.on('click', this.openPopup, this) |
} |
function onout() { |
onclick.call(this); |
this.closePopup(); |
}; |
this.on("mouseout", onout, this); |
this.on("click", onclick, this); |
} |
}); |
L.i18n = function(s) { return (L.i18n.lang[L.i18n.current] || {})[s] || s; } |
L.i18n.current = 'ru'; |
L.i18n.lang = {}; |
L.i18n.extend = function(lang, args) { |
L.i18n.lang[lang] = L.Util.extend(L.i18n.lang[lang] || {}, args) |
}; |
L.i18n.extend('ru', { |
"Fixed Error":"Ошибка исправлена", |
"Unresolved Error":"Неисправленная ошибка", |
"Active Error":"Ошибка уточняется", |
"Description":"Описание", |
"Comment":"Описание", |
"Add comment":"Дополнить", |
"Mark as Fixed":"Исправлено", |
"Link":"Ссылка", |
"Cancel":"Отмена", |
"New bug":"Я нашел ошибку", |
"Find your bug?":"Нашли ошибку?", |
"Contact details and someone will fix it.":"Напишите подробнее и кто-нибудь её исправит." |
}); |
/trunk/widget/modules/carto/squelettes/scripts/. |
---|
Property changes: |
Deleted: svn:ignore |
-carto_old.js |