2,29 → 2,28 |
|
L.Cluster = L.Marker.extend({ |
|
initialize: function(marker, proprietes, options) { |
initialize: function(marker, options) { |
L.Marker.prototype.initialize.call(this, marker, options); |
this._proprietes = [proprietes]; |
this._markers = [this]; |
}, |
|
ajouterPoint: function(proprietes) { |
this._proprietes.push(proprietes); |
this.setIcon(new L.Icon({ iconUrl : clusterImageUrl, iconSize : [20, 20] })); |
ajouterMarker: function(marker) { |
this._markers.push(marker); |
}, |
|
recupererPoints: function() { |
return this._proprietes; |
recupererMarkers: function() { |
return this._markers; |
}, |
|
obtenirNombrePoints: function() { |
return this._proprietes.length; |
obtenirNombreMarkers: function() { |
return this._markers.length; |
}, |
|
supprimerSource: function(sourceSupression) { |
var index = 0; |
while (index < this._markers.length) { |
if (this._proprietes[index].source == sourceSupression) { |
this._proprietes.splice(index, 1); |
if (this._markers[index].source == sourceSupression) { |
this._markers.splice(index, 1); |
} else { |
index ++; |
} |
32,6 → 31,7 |
if (this._markers.length == 0) { |
if (this._map != null) { |
this._map.removeLayer(this); |
//this._map.getPanes().markerPane.removeChild(this._icon); |
} |
delete this; |
} |
38,11 → 38,12 |
}, |
|
supprimer: function() { |
while (this._proprietes.length > 0) { |
this._proprietes.splice(0, 1); |
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; |
} |
60,36 → 61,37 |
this._nombreClusters = 0; |
}, |
|
ajouterPoint: function(point, proprietes) { |
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; |
var indexClusterPlusProche = this._chercherVoisinPlusProche(point); |
if (typeof(layer._latlng) != 'undefined') { |
var indexClusterPlusProche = this._chercherVoisinPlusProche(layer); |
var ajoute = false; |
if (indexClusterPlusProche != null) { |
var distance = this._layers[indexClusterPlusProche].getLatLng().distanceTo(point); |
var distance = this._layers[indexClusterPlusProche].getLatLng().distanceTo(layer.getLatLng()); |
if (distance < seuilCluster) { |
this._layers[indexClusterPlusProche].ajouterPoint(point, proprietes); |
this._layers[indexClusterPlusProche].ajouterMarker(layer); |
ajoute = true; |
} |
} |
if (!ajoute) { |
var cluster = creerMarqueur(point, proprietes); |
this._layers[this._nombreClusters] = cluster; |
this._layers[this._nombreClusters] = layer; |
this._nombreClusters ++; |
} |
} |
}, |
|
_chercherVoisinPlusProche: function(point) { |
_chercherVoisinPlusProche: function(layer) { |
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) { |
var centre = this._layers[numeroLayer].getLatLng(); |
if (distance == -1 || centre.distanceTo(layer.getLatLng()) < distance) { |
plusProche = numeroLayer; |
distance = pointCluster.distanceTo(point); |
distance = centre.distanceTo(layer.getLatLng()); |
} |
} |
} |
100,7 → 102,7 |
for (var numeroLayer in this._layers) { |
if (typeof(this._layers[numeroLayer]) != 'undefined') { |
var layer = this._layers[numeroLayer]; |
if (layer.obtenirNombrePoints() > 1) { |
if (layer.obtenirNombreMarkers() > 1) { |
layer.setIcon(new L.Icon({ iconUrl : clusterImageUrl, iconSize : [20, 20] })) |
} |
layer.addTo(map); |
109,7 → 111,7 |
}, |
|
supprimerPoint: function(layer) { |
this.removeLayer(layer); |
layer.supprimer(); |
} |
|
}); |