Subversion Repositories eFlore/Applications.moissonnage

Compare Revisions

Ignore whitespace Rev 46 → Rev 47

/trunk/widget/modules/carto/squelettes/scripts/cluster.js
1,115 → 1,117
 
 
L.Cluster = L.Marker.extend({
initialize: function(marker, proprietes, options) {
L.Marker.prototype.initialize.call(this, marker, options);
this._proprietes = [proprietes];
},
ajouterPoint: function(proprietes) {
this._proprietes.push(proprietes);
this.setIcon(new L.Icon({ iconUrl : clusterImageUrl, iconSize : [20, 20] }));
},
recupererPoints: function() {
return this._proprietes;
},
obtenirNombrePoints: function() {
return this._proprietes.length;
},
supprimerSource: function(sourceSupression) {
var index = 0;
while (index < this._markers.length) {
if (this._proprietes[index].source == sourceSupression) {
this._proprietes.splice(index, 1);
} else {
index ++;
}
}
if (this._markers.length == 0) {
if (this._map != null) {
this._map.removeLayer(this);
}
delete this;
}
},
supprimer: function() {
while (this._proprietes.length > 0) {
this._proprietes.splice(0, 1);
}
if (this._map != null) {
this._map.removeLayer(this);
}
delete this;
}
});
 
 
 
L.ClusterGroup = L.FeatureGroup.extend({
initialize: function(layers) {
L.FeatureGroup.prototype.initialize.call(this, layers);
this._distance = 10;
this._resolution = 0;
this._nombreClusters = 0;
},
 
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;
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) {
var cluster = creerMarqueur(point, proprietes);
this._layers[this._nombreClusters] = cluster;
this._nombreClusters ++;
}
},
_chercherVoisinPlusProche: function(point) {
var distance = -1;
var plusProche = null;
for (var numeroLayer in this._layers) {
if (typeof(this._layers[numeroLayer]) != 'undefined') {
var pointCluster = this._layers[numeroLayer].getLatLng();
if (distance == -1 || pointCluster.distanceTo(point) < distance) {
plusProche = numeroLayer;
distance = pointCluster.distanceTo(point);
}
}
}
return plusProche;
},
afficherClusters: function() {
for (var numeroLayer in this._layers) {
if (typeof(this._layers[numeroLayer]) != 'undefined') {
var layer = this._layers[numeroLayer];
if (layer.obtenirNombrePoints() > 1) {
layer.setIcon(new L.Icon({ iconUrl : clusterImageUrl, iconSize : [20, 20] }))
}
layer.addTo(map);
}
}
},
supprimerPoint: function(layer) {
this.removeLayer(layer);
}
 
 
L.Cluster = L.Marker.extend({
initialize: function(marker, options) {
L.Marker.prototype.initialize.call(this, marker, options);
this._markers = [this];
},
ajouterMarker: function(marker) {
this._markers.push(marker);
},
recupererMarkers: function() {
return this._markers;
},
obtenirNombreMarkers: function() {
return this._markers.length;
},
supprimerSource: function(sourceSupression) {
var index = 0;
while (index < this._markers.length) {
if (this._markers[index].source == sourceSupression) {
this._markers.splice(index, 1);
} else {
index ++;
}
}
if (this._markers.length == 0) {
if (this._map != null) {
this._map.removeLayer(this);
//this._map.getPanes().markerPane.removeChild(this._icon);
}
delete this;
}
},
supprimer: function() {
while (this._markers.length > 0) {
this._markers.splice(0, 1);
}
if (this._map != null) {
this._map.removeLayer(this);
//this._map.getPanes().markerPane.removeChild(this._icon);
}
delete this;
}
});
 
 
 
L.ClusterGroup = L.FeatureGroup.extend({
initialize: function(layers) {
L.FeatureGroup.prototype.initialize.call(this, layers);
this._distance = 10;
this._resolution = 0;
this._nombreClusters = 0;
},
 
ajouterPoint: function(layer) {
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;
}
}
if (!ajoute) {
this._layers[this._nombreClusters] = layer;
this._nombreClusters ++;
}
}
},
_chercherVoisinPlusProche: function(layer) {
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) {
plusProche = numeroLayer;
distance = centre.distanceTo(layer.getLatLng());
}
}
}
return plusProche;
},
afficherClusters: function() {
for (var numeroLayer in this._layers) {
if (typeof(this._layers[numeroLayer]) != 'undefined') {
var layer = this._layers[numeroLayer];
if (layer.obtenirNombreMarkers() > 1) {
layer.setIcon(new L.Icon({ iconUrl : clusterImageUrl, iconSize : [20, 20] }))
}
layer.addTo(map);
}
}
},
supprimerPoint: function(layer) {
layer.supprimer();
}
});