Subversion Repositories eFlore/Applications.moissonnage

Rev

Rev 42 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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