Subversion Repositories eFlore/Applications.moissonnage

Compare Revisions

Ignore whitespace Rev 42 → Rev 43

/trunk/widget/modules/carto/squelettes/scripts/carto.js
700,16 → 700,20
// Gestion des points
 
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, {
var point = new L.LatLng(feature.geometry.coordinates[0], feature.geometry.coordinates[1]);
feature.properties.typeSite = feature.properties.typeSite.toLowerCase();
coucheSites.ajouterPoint(point, feature.properties);
}
 
function creerMarqueur(point, properties) {
var iconePoint = new L.Icon({ iconUrl : pointImageUrl, iconSize : [16, 16] });
var iconeCommune = new L.Icon({ iconUrl : communeImageUrl, iconSize : [24, 32] });
var icone = (properties.typeSite == 'station') ? iconePoint : iconeCommune;
var marker = new L.Cluster(point, properties, {
icon : icone,
titre : feature.properties.nom
titre : properties.nom
});
marker.typeSite = feature.properties.typeSite.toLowerCase();
marker.source = feature.properties.source;
console.log(marker);
marker.on('click', surClicMarqueur);
marker.on('mouseover', function() {
afficherTooltip(marker.options.titre, map.latLngToContainerPoint(marker.getLatLng()));
717,7 → 721,7
marker.on('mouseout', function() {
$("#tooltip").css('display', 'none');
});
coucheSites.ajouterPoint(marker);
return marker;
}
 
function construireContenuHtmlLegendePoints() {
743,7 → 747,7
 
 
function surClicMarqueur(event) {
var nombreMarkers = event.target.recupererMarkers().length;
var nombreMarkers = event.target.obtenirNombrePoints();
if (nombreMarkers == 1 || map.getZoom() == map.getMaxZoom()) {
recupererObservations(event.target);
} else {
772,7 → 776,7
}
 
function recupererSourcesCluster(cluster) {
var markers = cluster.recupererMarkers();
var markers = cluster.recupererPoints();
var sourcesCluster = [];
for (var index = 0; index < markers.length; index ++) {
if (sourcesCluster.indexOf(markers[index].source) == -1) {
/trunk/widget/modules/carto/squelettes/scripts/cluster.js
2,28 → 2,29
 
L.Cluster = L.Marker.extend({
initialize: function(marker, options) {
initialize: function(marker, proprietes, options) {
L.Marker.prototype.initialize.call(this, marker, options);
this._markers = [this];
this._proprietes = [proprietes];
},
ajouterMarker: function(marker) {
this._markers.push(marker);
ajouterPoint: function(proprietes) {
this._proprietes.push(proprietes);
this.setIcon(new L.Icon({ iconUrl : clusterImageUrl, iconSize : [20, 20] }));
},
recupererMarkers: function() {
return this._markers;
recupererPoints: function() {
return this._proprietes;
},
obtenirNombreMarkers: function() {
return this._markers.length;
obtenirNombrePoints: function() {
return this._proprietes.length;
},
supprimerSource: function(sourceSupression) {
var index = 0;
while (index < this._markers.length) {
if (this._markers[index].source == sourceSupression) {
this._markers.splice(index, 1);
if (this._proprietes[index].source == sourceSupression) {
this._proprietes.splice(index, 1);
} else {
index ++;
}
30,7 → 31,7
}
if (this._markers.length == 0) {
if (this._map != null) {
this._map.getPanes().markerPane.removeChild(this._icon);
this._map.removeLayer(this);
}
delete this;
}
37,11 → 38,11
},
supprimer: function() {
while (this._markers.length > 0) {
this._markers.splice(0, 1);
while (this._proprietes.length > 0) {
this._proprietes.splice(0, 1);
}
if (this._map != null) {
this._map.getPanes().markerPane.removeChild(this._icon);
this._map.removeLayer(this);
}
delete this;
}
59,37 → 60,36
this._nombreClusters = 0;
},
 
ajouterPoint: function(layer) {
ajouterPoint: function(point, proprietes) {
if (this._resolution == 0) {
this._resolution = (2 * Math.PI * 6378137) / (256 * Math.pow(2, this._map.getZoom()));
}
var seuilCluster = this._distance * this._resolution;
if (typeof(layer._latlng) != 'undefined') {
var indexClusterPlusProche = this._chercherVoisinPlusProche(layer);
var ajoute = false;
if (indexClusterPlusProche != null) {
var distance = this._layers[indexClusterPlusProche].getLatLng().distanceTo(layer.getLatLng());
if (distance < seuilCluster) {
this._layers[indexClusterPlusProche].ajouterMarker(layer);
ajoute = true;
}
var indexClusterPlusProche = this._chercherVoisinPlusProche(point);
var ajoute = false;
if (indexClusterPlusProche != null) {
var distance = this._layers[indexClusterPlusProche].getLatLng().distanceTo(point);
if (distance < seuilCluster) {
this._layers[indexClusterPlusProche].ajouterPoint(point, proprietes);
ajoute = true;
}
if (!ajoute) {
this._layers[this._nombreClusters] = layer;
this._nombreClusters ++;
}
}
if (!ajoute) {
var cluster = creerMarqueur(point, proprietes);
this._layers[this._nombreClusters] = cluster;
this._nombreClusters ++;
}
},
_chercherVoisinPlusProche: function(layer) {
_chercherVoisinPlusProche: function(point) {
var distance = -1;
var plusProche = null;
for (var numeroLayer in this._layers) {
if (typeof(this._layers[numeroLayer]) != 'undefined') {
var centre = this._layers[numeroLayer].getLatLng();
if (distance == -1 || centre.distanceTo(layer.getLatLng()) < distance) {
var pointCluster = this._layers[numeroLayer].getLatLng();
if (distance == -1 || pointCluster.distanceTo(point) < distance) {
plusProche = numeroLayer;
distance = centre.distanceTo(layer.getLatLng());
distance = pointCluster.distanceTo(point);
}
}
}
100,7 → 100,7
for (var numeroLayer in this._layers) {
if (typeof(this._layers[numeroLayer]) != 'undefined') {
var layer = this._layers[numeroLayer];
if (layer.obtenirNombreMarkers() > 1) {
if (layer.obtenirNombrePoints() > 1) {
layer.setIcon(new L.Icon({ iconUrl : clusterImageUrl, iconSize : [20, 20] }))
}
layer.addTo(map);
109,7 → 109,7
},
supprimerPoint: function(layer) {
layer.supprimer();
this.removeLayer(layer);
}
});