Subversion Repositories eFlore/Applications.moissonnage

Rev

Rev 43 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 43 Rev 47
Line 1... Line 1...
1
 
1
 
Line 2... Line 2...
2
 
2
 
3
L.Cluster = L.Marker.extend({
3
L.Cluster = L.Marker.extend({
4
	
4
	
5
	initialize: function(marker, proprietes, options) {
5
	initialize: function(marker, options) {
Line 6... Line 6...
6
		L.Marker.prototype.initialize.call(this, marker, options);
6
		L.Marker.prototype.initialize.call(this, marker, options);
7
		this._proprietes = [proprietes];
7
		this._markers = [this];
8
	},
-
 
9
	
8
	},
Line 10... Line 9...
10
	ajouterPoint: function(proprietes) {
9
	
11
		this._proprietes.push(proprietes);
10
	ajouterMarker: function(marker) {
12
		this.setIcon(new L.Icon({ iconUrl : clusterImageUrl, iconSize : [20, 20] }));
11
		this._markers.push(marker);
Line 13... Line 12...
13
	},
12
	},
14
	
13
	
15
	recupererPoints: function() {
14
	recupererMarkers: function() {
Line 16... Line 15...
16
		return this._proprietes;
15
		return this._markers;
17
	},
16
	},
18
	
17
	
19
	obtenirNombrePoints: function() {
18
	obtenirNombreMarkers: function() {
20
		return this._proprietes.length;
19
		return this._markers.length;
21
	},
20
	},
22
	
21
	
23
	supprimerSource: function(sourceSupression) {
22
	supprimerSource: function(sourceSupression) {
24
		var index = 0;
23
		var index = 0;
25
		while (index < this._markers.length) {
24
		while (index < this._markers.length) {
26
			if (this._proprietes[index].source == sourceSupression) {
25
			if (this._markers[index].source == sourceSupression) {
27
				this._proprietes.splice(index, 1);
26
				this._markers.splice(index, 1);
-
 
27
			} else {
28
			} else {
28
				index ++;
29
				index ++;
29
			}
30
			}
30
		}
31
		}
31
		if (this._markers.length == 0) {
Line 32... Line 32...
32
		if (this._markers.length == 0) {
32
			if (this._map != null) {
33
			if (this._map != null) {
33
				this._map.removeLayer(this);
34
				this._map.removeLayer(this);
34
				//this._map.getPanes().markerPane.removeChild(this._icon);
35
			}
35
			}
36
			delete this;
36
			delete this;
37
		}
37
		}
-
 
38
	},
38
	},
39
	
39
	
40
	supprimer: function() {
40
	supprimer: function() {
41
		while (this._markers.length > 0) {
Line 41... Line 42...
41
		while (this._proprietes.length > 0) {
42
			this._markers.splice(0, 1);
Line 58... Line 59...
58
		this._distance = 10;
59
		this._distance = 10;
59
		this._resolution = 0;
60
		this._resolution = 0;
60
		this._nombreClusters = 0;
61
		this._nombreClusters = 0;
61
	},
62
	},
Line 62... Line 63...
62
 
63
 
63
	ajouterPoint: function(point, proprietes) {
64
	ajouterPoint: function(layer) {
64
		if (this._resolution == 0) {
65
		if (this._resolution == 0) {
65
			this._resolution = (2 * Math.PI * 6378137) / (256 * Math.pow(2, this._map.getZoom()));
66
			this._resolution = (2 * Math.PI * 6378137) / (256 * Math.pow(2, this._map.getZoom()));
66
		}
67
		}
-
 
68
		var seuilCluster = this._distance * this._resolution;
67
		var seuilCluster = this._distance * this._resolution;
69
		if (typeof(layer._latlng) != 'undefined') {
68
		var indexClusterPlusProche = this._chercherVoisinPlusProche(point);
70
			var indexClusterPlusProche = this._chercherVoisinPlusProche(layer);
69
		var ajoute = false;
71
			var ajoute = false;
70
		if (indexClusterPlusProche != null) {
72
			if (indexClusterPlusProche != null) {
71
			var distance = this._layers[indexClusterPlusProche].getLatLng().distanceTo(point);
73
				var distance = this._layers[indexClusterPlusProche].getLatLng().distanceTo(layer.getLatLng());
72
			if (distance < seuilCluster) {
74
				if (distance < seuilCluster) {
73
				this._layers[indexClusterPlusProche].ajouterPoint(point, proprietes);
75
					this._layers[indexClusterPlusProche].ajouterMarker(layer);
74
				ajoute = true;
76
					ajoute = true;
75
			}
77
				}
76
		}
78
			}
77
		if (!ajoute) {
-
 
78
			var cluster = creerMarqueur(point, proprietes);
79
			if (!ajoute) {
79
			this._layers[this._nombreClusters] = cluster;
80
				this._layers[this._nombreClusters] = layer;
80
			this._nombreClusters ++;
81
				this._nombreClusters ++;
-
 
82
			}
81
		}
83
		}
Line 82... Line 84...
82
	},
84
	},
83
	
85
	
84
	_chercherVoisinPlusProche: function(point) {
86
	_chercherVoisinPlusProche: function(layer) {
85
		var distance = -1;
87
		var distance = -1;
86
		var plusProche = null;
88
		var plusProche = null;
87
		for (var numeroLayer in this._layers) {
89
		for (var numeroLayer in this._layers) {
88
			if (typeof(this._layers[numeroLayer]) != 'undefined') {
90
			if (typeof(this._layers[numeroLayer]) != 'undefined') {
89
				var pointCluster = this._layers[numeroLayer].getLatLng();
91
				var centre = this._layers[numeroLayer].getLatLng();
90
				if (distance == -1 || pointCluster.distanceTo(point) < distance) {
92
				if (distance == -1 || centre.distanceTo(layer.getLatLng()) < distance) {
91
					plusProche = numeroLayer;
93
					plusProche = numeroLayer;
92
					distance = pointCluster.distanceTo(point);
94
					distance = centre.distanceTo(layer.getLatLng());
93
				}
95
				}
94
			}
96
			}
95
		}
97
		}
Line 96... Line 98...
96
		return plusProche;
98
		return plusProche;
97
	},
99
	},
98
	
100
	
99
	afficherClusters: function() {
101
	afficherClusters: function() {
100
		for (var numeroLayer in this._layers) {
102
		for (var numeroLayer in this._layers) {
101
			if (typeof(this._layers[numeroLayer]) != 'undefined') {
103
			if (typeof(this._layers[numeroLayer]) != 'undefined') {
102
				var layer = this._layers[numeroLayer];
104
				var layer = this._layers[numeroLayer];
103
				if (layer.obtenirNombrePoints() > 1) {
105
				if (layer.obtenirNombreMarkers() > 1) {
104
					layer.setIcon(new L.Icon({ iconUrl : clusterImageUrl, iconSize : [20, 20] }))
106
					layer.setIcon(new L.Icon({ iconUrl : clusterImageUrl, iconSize : [20, 20] }))
105
				}
107
				}
106
				layer.addTo(map);
108
				layer.addTo(map);
Line 107... Line 109...
107
			}
109
			}
108
		}
110
		}
109
	},
111
	},
Line 110... Line 112...
110
	
112
	
111
	supprimerPoint: function(layer) {
113
	supprimerPoint: function(layer) {