Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 1292 Rev 1958
Line 1... Line 1...
1
package org.tela_botanica.client.vues.observation;
1
package org.tela_botanica.client.vues.observation;
Line 2... Line 2...
2
 
2
 
3
import org.tela_botanica.client.interfaces.Rafraichissable;
-
 
4
import org.tela_botanica.client.modeles.objets.Configuration;
3
import org.tela_botanica.client.interfaces.Rafraichissable;
5
import org.tela_botanica.client.modeles.objets.EntiteGeographiqueObservation;
4
import org.tela_botanica.client.modeles.objets.EntiteGeographiqueObservation;
6
import org.tela_botanica.client.observation.ObservationMediateur;
5
import org.tela_botanica.client.observation.ObservationMediateur;
Line 7... Line -...
7
import org.tela_botanica.client.util.Util;
-
 
8
 
-
 
9
import com.google.gwt.maps.client.InfoWindow;
-
 
10
import com.google.gwt.maps.client.InfoWindowContent;
-
 
11
import com.google.gwt.maps.client.MapType;
-
 
12
import com.google.gwt.maps.client.MapWidget;
-
 
13
import com.google.gwt.maps.client.Maps;
-
 
14
import com.google.gwt.maps.client.control.LargeMapControl;
-
 
15
import com.google.gwt.maps.client.event.MapClickHandler;
-
 
16
import com.google.gwt.maps.client.event.MapZoomEndHandler;
-
 
17
import com.google.gwt.maps.client.event.MarkerClickHandler;
-
 
18
import com.google.gwt.maps.client.event.MarkerDragEndHandler;
-
 
19
import com.google.gwt.maps.client.event.MarkerDragStartHandler;
-
 
20
import com.google.gwt.maps.client.geom.LatLng;
-
 
21
import com.google.gwt.maps.client.overlay.Marker;
6
import org.tela_botanica.client.util.Util;
22
import com.google.gwt.maps.client.overlay.MarkerOptions;
7
 
23
import com.google.gwt.user.client.Timer;
8
import com.google.gwt.user.client.Timer;
24
import com.google.gwt.user.client.Window;
9
import com.google.gwt.user.client.Window;
25
import com.gwtext.client.core.EventCallback;
10
import com.gwtext.client.core.EventCallback;
Line 31... Line 16...
31
import com.gwtext.client.widgets.event.ContainerListenerAdapter;
16
import com.gwtext.client.widgets.event.ContainerListenerAdapter;
32
import com.gwtext.client.widgets.form.Label;
17
import com.gwtext.client.widgets.form.Label;
33
import com.gwtext.client.widgets.layout.FitLayout;
18
import com.gwtext.client.widgets.layout.FitLayout;
34
import com.gwtext.client.widgets.layout.RowLayout;
19
import com.gwtext.client.widgets.layout.RowLayout;
35
import com.gwtext.client.widgets.layout.RowLayoutData;
20
import com.gwtext.client.widgets.layout.RowLayoutData;
-
 
21
import com.google.maps.gwt.client.GoogleMap;
-
 
22
import com.google.maps.gwt.client.GoogleMap.ClickHandler;
-
 
23
import com.google.maps.gwt.client.GoogleMap.ZoomChangedHandler;
-
 
24
import com.google.maps.gwt.client.InfoWindow;
-
 
25
import com.google.maps.gwt.client.InfoWindowOptions;
-
 
26
import com.google.maps.gwt.client.LatLng;
-
 
27
import com.google.maps.gwt.client.MapOptions;
-
 
28
import com.google.maps.gwt.client.MapTypeId;
-
 
29
import com.google.maps.gwt.client.Marker;
-
 
30
import com.google.maps.gwt.client.MarkerOptions;
-
 
31
import com.google.maps.gwt.client.MouseEvent;
Line 36... Line 32...
36
 
32
 
Line 37... Line 33...
37
public class CartographieObservationVue extends Panel implements Rafraichissable {
33
public class CartographieObservationVue extends Panel implements Rafraichissable {
Line 38... Line 34...
38
 
34
 
Line 39... Line 35...
39
	private String id = "cartographie_observation";
35
	private String id = "cartographie_observation";
40
	
36
	
-
 
37
	private ObservationMediateur oMediateur = null;
Line 41... Line 38...
41
	private ObservationMediateur oMediateur = null;
38
	
42
	
39
	Panel panneauCarto = null;
Line 43... Line 40...
43
	Panel panneauCarto = null;
40
	GoogleMap map = null;
44
	private MapWidget map;
41
	Marker nmk = null;
45
	
42
	
46
	private boolean carteAjoutee = false;
43
	private boolean carteAjoutee = false;
Line 56... Line 53...
56
	Label panneauExplication = new Label(
53
	Label panneauExplication = new Label(
57
			"Précisez le lieu de votre observation et cliquez sur OK. Les coordonnées sont données en degrés décimaux, comptés positivement vers le Nord pour la latitude, et vers l'Est pour la longitude");
54
			"Précisez le lieu de votre observation et cliquez sur OK. Les coordonnées sont données en degrés décimaux, comptés positivement vers le Nord pour la latitude, et vers l'Est pour la longitude");
Line 58... Line 55...
58
 
55
 
Line 59... Line -...
59
	private InfoWindow info;
-
 
60
 
-
 
61
	private boolean listenerInitialise = false;
56
	private InfoWindow info;
Line 62... Line 57...
62
 
57
 
Line 63... Line 58...
63
	public CartographieObservationVue(ObservationMediateur om) {
58
	public CartographieObservationVue(ObservationMediateur om) {
Line 71... Line 66...
71
		panneauCarto = new Panel();
66
		panneauCarto = new Panel();
72
		panneauCarto.setLayout(new FitLayout());
67
		panneauCarto.setLayout(new FitLayout());
Line 73... Line 68...
73
 
68
 
Line 74... Line -...
74
		setLayout(new RowLayout());
-
 
-
 
69
		setLayout(new RowLayout());
75
		
70
		
76
 
71
		panneauCarto.setAutoHeight(true);
77
		add(panneauExplication, new RowLayoutData(12));
72
		add(panneauExplication, new RowLayoutData(12));
78
		add(panneauCarto, new RowLayoutData());
-
 
79
		
-
 
80
		if(!carteAjoutee) {
-
 
81
			
-
 
82
			Maps.loadMapsApi(Configuration.getCleGoogleMaps(), "2", false, new Runnable() {
-
 
83
				@Override
-
 
84
				public void run() {
-
 
85
					initialiserCarte(false);
-
 
86
				}
-
 
87
			});
-
 
88
		}
73
		add(panneauCarto, new RowLayoutData());
Line 89... Line 74...
89
				
74
								
90
		addListener(new ContainerListenerAdapter() {
75
		addListener(new ContainerListenerAdapter() {
91
			
-
 
92
			@Override
-
 
93
			public void onAfterLayout(Container c) {
-
 
94
				
-
 
95
				if(carteAjoutee) {
-
 
96
					panneauCarto.setHeight("100%");
-
 
97
					if((panneauCarto.getHeight() - 20) > map.getSize().getHeight()) {
-
 
98
						map.setSize(map.getSize().getWidth()+"px", (panneauCarto.getHeight() - 20)+"px");
76
			
99
					}
-
 
100
					panneauCarto.doLayout();
77
			@Override
101
					panneauCarto.expand();
78
			public void onAfterLayout(Container c) {
102
				}
-
 
103
			}
-
 
104
		});
79
				initialiserCarte(false);
Line 105... Line 80...
105
		
80
			}
106
		panneauCarto.setAutoHeight(true);
81
		});
107
	}
82
	}
Line 108... Line 83...
108
	
83
	
Line 109... Line 84...
109
	public void setTailleCarte(int hauteur, int largeur) {
84
	public void setTailleCarte(int hauteur, int largeur) {
Line 120... Line 95...
120
			}
95
			}
121
		}
96
		}
122
	}
97
	}
Line 123... Line 98...
123
	
98
	
124
	public void obtenirInfosCommunes(LatLng coord) {
99
	public void obtenirInfosCommunes(LatLng coord) {
125
		oMediateur.obtenirInformationCoord(this, coord);
100
		oMediateur.obtenirInformationCoord(this, coord.lat(), coord.lng());
Line 126... Line 101...
126
	}
101
	}
127
 
-
 
-
 
102
 
128
	public void mettreAJourInfos(final LatLng pointNouvelleCommune, String infosComplementaires, int zoom) {
103
	public void mettreAJourInfos(final LatLng pointNouvelleCommune, String infosComplementaires, int zoom) {
129
 
104
		GoogleMap mapNulle = null;
130
		if (!carteAjoutee) {
105
		if(nmk != null) {
131
			initialiserCarte(true);
-
 
132
		}
106
			nmk.setMap(mapNulle);
133
 
-
 
134
		pointCommune = pointNouvelleCommune;
107
		}
135
		map.clearOverlays();
108
		pointCommune = pointNouvelleCommune;
136
		Marker nmk = fabriquerMarqueur(pointCommune, infosComplementaires);
109
		nmk = fabriquerMarqueur(pointCommune, infosComplementaires);
137
		map.addOverlay(nmk);
110
		nmk.setMap(map);
138
		afficherInfoMarker(nmk);
111
		afficherInfoMarker(nmk);
Line 139... Line 112...
139
		recentrerCarte();
112
		recentrerCarte();
Line -... Line 113...
-
 
113
	}
-
 
114
 
140
	}
115
	private void initialiserCarte(boolean commune) {
141
 
116
		
Line 142... Line 117...
142
	public void initialiserCarte(boolean commune) {
117
		panneauCarto.clear();
-
 
118
		
143
		
119
		centreFrance = LatLng.create(47.0504, 2.2347);
-
 
120
		pointCommune = centreFrance;
-
 
121
		
-
 
122
		MapOptions options  = MapOptions.create();
-
 
123
	    options.setCenter(centreFrance);   
-
 
124
	    options.setZoom(6) ;
-
 
125
	    options.setMapTypeId(MapTypeId.HYBRID);
-
 
126
	    options.setDraggable(true);
-
 
127
	    options.setMapTypeControl(true);
-
 
128
	    options.setScaleControl(true) ;
144
		centreFrance = LatLng.newInstance(47.0504, 2.2347);
129
	    options.setScrollwheel(true) ;
145
		pointCommune = centreFrance;
130
	    
-
 
131
		map = GoogleMap.create(panneauCarto.getElement(), options ) ;
-
 
132
				
-
 
133
		InfoWindowOptions infopts = InfoWindowOptions.create();
-
 
134
		info = InfoWindow.create();
-
 
135
		info.setOptions(infopts);
-
 
136
		info.addCloseClickListener(new InfoWindow.CloseClickHandler() {			
-
 
137
			@Override
146
		
138
			public void handle() {
147
		map = new MapWidget(pointCommune, niveauZoom);
139
				infoOuverte = false;
148
		panneauCarto.add(map);
140
			}
149
		panneauCarto.doLayout();
141
		});
150
		info = map.getInfoWindow();
-
 
151
		if(!commune) {
-
 
152
			fabriquerMarqueurIndication();
-
 
153
		}
-
 
154
		
-
 
155
		map.setZoomLevel(6);
-
 
156
		map.checkResizeAndCenter();
-
 
157
		map.setUIToDefault();
-
 
158
		map.addControl(new LargeMapControl());
142
		
159
		map.setCurrentMapType(MapType.getHybridMap());
-
 
160
		carteAjoutee = true;
143
		if(!commune) {
161
		panneauCarto.doLayout();
144
			fabriquerMarqueurIndication();
162
		
-
 
163
		map.addMapClickHandler(new MapClickHandler() {
145
		}
164
 
146
				
165
			@Override
-
 
166
			public void onClick(MapClickEvent event) {
147
		map.addClickListener(new ClickHandler() {		
Line 167... Line 148...
167
				//TODO : quoi faire du double clic ?
148
			@Override
168
				obtenirInfosCommunes(event.getLatLng());
-
 
169
			}
149
			public void handle(MouseEvent event) {
170
			
150
				obtenirInfosCommunes(event.getLatLng());
171
		});
151
			}
172
		
152
		});
173
		map.addMapZoomEndHandler(new MapZoomEndHandler() {
-
 
174
 
153
		
-
 
154
		map.addZoomChangedListener(new ZoomChangedHandler() {
-
 
155
			@Override
-
 
156
			public void handle() {
-
 
157
				niveauZoom = (int)map.getZoom();
-
 
158
			}
-
 
159
		});
175
			@Override
160
		
Line 176... Line 161...
176
			public void onZoomEnd(MapZoomEndEvent event) {
161
		panneauCarto.doLayout();
-
 
162
		panneauCarto.expand();   
-
 
163
		panneauCarto.setHeight("100%");
-
 
164
		panneauCarto.setWidth("100%");
-
 
165
		expand();
177
				niveauZoom = event.getNewZoomLevel();
166
	}
178
			}
167
	
179
			
168
	public void fabriquerMarqueurIndication() {
180
		});
169
		GoogleMap mapNulle = null;
181
	}
170
		if(nmk != null) {
182
	
171
			nmk.setMap(mapNulle);
183
	public void fabriquerMarqueurIndication() {
172
		}
-
 
173
		nmk = fabriquerMarqueur(pointCommune,"");
-
 
174
		nmk.setMap(map);
184
		Marker marker = fabriquerMarqueur(pointCommune,"");
175
		info.setContent("<div id=\"info_contenu\">"+
Line 185... Line 176...
185
		map.addOverlay(marker);		
176
				"Déplacez ce marqueur pour localiser votre observation (commune et coordonnées)<br />"
186
		info.open(marker, new InfoWindowContent("<div id=\"info_contenu\">"+
177
				+"longitude="
187
				"Déplacez ce marqueur pour localiser votre observation (commune et coordonnées)<br />"
178
				+ nmk.getPosition().lng() + "<br />latitude="
Line 200... Line 191...
200
	}
191
	}
Line 201... Line 192...
201
	
192
	
Line 202... Line 193...
202
	private void ajouterListenerBouton(final String idBouton) {
193
	private void ajouterListenerBouton(final String idBouton) {
203
		
-
 
204
		final ExtElement bouton = Ext.get(idBouton);
194
		
205
		
195
		final ExtElement bouton = Ext.get(idBouton);
206
		if(bouton == null) {
196
		if(bouton == null) {
207
			Timer t = new Timer() {
197
			Timer t = new Timer() {
208
				@Override
198
				@Override
209
				public void run() {
199
				public void run() {
210
					ajouterListenerBouton(idBouton);
-
 
211
				}
200
					ajouterListenerBouton(idBouton);
212
				
201
				}
213
			};
202
			};
-
 
203
			t.schedule(500);
-
 
204
			return;
-
 
205
		} else {
-
 
206
			bouton.addListener("click", new EventCallback() {
-
 
207
				@Override
-
 
208
				public void execute(EventObject e) {
-
 
209
					EntiteGeographiqueObservation infosCommune = new EntiteGeographiqueObservation(codeCommune,valeurCommune,null,null);
-
 
210
					infosCommune.setLat(pointCommune.lat()+"");
-
 
211
					infosCommune.setLon(pointCommune.lng()+"");
-
 
212
					oMediateur.rafraichirSaisieCommuneObservation(infosCommune);
-
 
213
				}
-
 
214
			});	
214
			t.schedule(500);
215
			
215
			return;
-
 
216
		}
-
 
217
		
-
 
218
		bouton.addListener("click", new EventCallback() {
-
 
219
			@Override
-
 
220
			public void execute(EventObject e) {
-
 
221
				EntiteGeographiqueObservation infosCommune = new EntiteGeographiqueObservation(codeCommune,valeurCommune,null,null);
-
 
222
				infosCommune.setLat(pointCommune.getLatitude()+"");
-
 
223
				infosCommune.setLon(pointCommune.getLongitude()+"");
-
 
224
				oMediateur.rafraichirSaisieCommuneObservation(infosCommune);
-
 
225
			}
-
 
226
		});	
-
 
227
		
216
			bouton.focus();
Line 228... Line 217...
228
		bouton.focus();
217
		}
229
	}
218
	}
230
 
219
 
Line 252... Line 241...
252
				lon = Double.parseDouble(infos.getLon());
241
				lon = Double.parseDouble(infos.getLon());
253
			} catch (NumberFormatException nbe) {
242
			} catch (NumberFormatException nbe) {
Line 254... Line 243...
254
				
243
				
Line 255... Line 244...
255
			}
244
			}
Line 256... Line 245...
256
			
245
			
257
			LatLng coord = LatLng.newInstance(lat, lon);
246
			LatLng coord = LatLng.create(lat, lon);
258
			
247
			
Line 266... Line 255...
266
		masquerChargement(false);
255
		masquerChargement(false);
267
	}
256
	}
Line 268... Line 257...
268
	
257
	
269
	public Marker fabriquerMarqueur(LatLng pointMarqueur, final String texte) {
258
	public Marker fabriquerMarqueur(LatLng pointMarqueur, final String texte) {
270
		// ajout de marqueurs déplacables, qui affichent une bulle d'information
259
		// ajout de marqueurs déplacables, qui affichent une bulle d'information
271
		MarkerOptions options = MarkerOptions.newInstance();
260
		MarkerOptions options = MarkerOptions.create();
-
 
261
		options.setDraggable(true);
272
		options.setDraggable(true);
262
		options.setPosition(pointMarqueur);
Line 273... Line 263...
273
		final Marker marker = new Marker(pointMarqueur, options);
263
		final Marker marker = Marker.create(options);
-
 
264
		
274
		
265
		marker.addDragEndListener(new Marker.DragEndHandler() {
275
		marker.addMarkerDragEndHandler(new MarkerDragEndHandler() {
266
			
276
			@Override
-
 
277
			public void onDragEnd(MarkerDragEndEvent event) {
267
			@Override
278
				masquerChargement(true);
268
			public void handle(MouseEvent event) {
279
				obtenirInfosCommunes(marker.getLatLng());
-
 
280
			}
269
				obtenirInfosCommunes(event.getLatLng());
281
 
270
			}
282
		});
271
		});
-
 
272
		
283
 
273
		marker.addDragStartListener(new Marker.DragStartHandler() {
284
		marker.addMarkerDragStartHandler(new MarkerDragStartHandler() {
274
			
285
			@Override
275
			@Override
286
			public void onDragStart(MarkerDragStartEvent event) {
276
			public void handle(MouseEvent event) {
287
				info.setVisible(false);
277
				info.close();
288
			}
-
 
289
		});
-
 
Line -... Line 278...
-
 
278
			}
-
 
279
		});
290
		
280
 
291
		marker.addMarkerClickHandler(new MarkerClickHandler() {
281
		marker.addClickListener(new Marker.ClickHandler() {
292
 
282
			
293
			@Override
283
			@Override
-
 
284
			public void handle(MouseEvent event) {
294
			public void onClick(MarkerClickEvent event) {
285
				if(infoOuverte) {
295
				if(info.isVisible()) {
286
					info.close();
-
 
287
					infoOuverte = false;
296
					info.close();
288
				} else {
297
				} else {
289
					afficherInfoMarker(marker);
298
					afficherInfoMarker(marker);
290
					infoOuverte = true;
299
				}
-
 
300
			}	
291
				}
301
		});
292
			}
Line 302... Line 293...
302
		
293
		});
303
		return marker;
-
 
304
	}
294
		return marker;
305
 
-
 
306
	public void recentrerCarte() {
295
	}
307
		
296
 
-
 
297
	public void recentrerCarte() {
-
 
298
		if(this.getWidth() > 12 && this.getHeight() > 24) {		
308
		if(this.getWidth() > 12 && this.getHeight() > 24) {
299
			panneauCarto.setSize((this.getWidth() - 12)+"px" , (this.getHeight() - 12)+"px");
309
			map.setSize((this.getWidth() - 12)+"px" , (this.getHeight() - 24)+"px");
300
		}
-
 
301
		panneauCarto.doLayout();
310
			panneauCarto.setSize((this.getWidth() - 12)+"px" , (this.getHeight() - 12)+"px");
302
		panneauCarto.expand();   
Line 311... Line 303...
311
		}
303
		panneauCarto.setHeight("100%");
312
		map.setCenter(pointCommune, niveauZoom);
304
		panneauCarto.setWidth("100%");
313
		map.checkResizeAndCenter();
305
		expand();
Line 314... Line 306...
314
	}
306
	}
315
 
-
 
316
	public boolean isCarteAjoutee() {
307
 
Line 317... Line 308...
317
		return carteAjoutee;
308
	public boolean isCarteAjoutee() {
Line 318... Line 309...
318
	}
309
		return carteAjoutee;
319
	
310
	}
320
	public void afficherInfoMarker(Marker marker) {
311
	
321
		
312
	public void afficherInfoMarker(Marker marker) {		
322
		final String htmlBoutonOk = "<br /><button id=\"okMap\" class=\"x-btn-text\" type=\"button\">OK</button>";
313
		final String htmlBoutonOk = "<br /><button id=\"okMap\" class=\"x-btn-text\" type=\"button\">OK</button>";
323
 
314
 
324
		String contenuMarker = "";
315
		String contenuMarker = "";
325
		
316
		
326
		if(valeurCommune == null || valeurCommune.trim().equals("")) {
317
		if(valeurCommune == null || valeurCommune.trim().equals("")) {
327
			if(marker.getLatLng().getLongitude() == 0 && marker.getLatLng().getLatitude() == 0) {
318
			if(marker.getPosition().lng() == 0 && marker.getPosition().lat() == 0) {
328
				LatLng point = centreFrance;
319
				LatLng point = centreFrance;
329
				marker.setLatLng(point);
320
				marker.setPosition(point);
330
				niveauZoom = 6;
321
				niveauZoom = 6;
331
			}
322
			}
332
			contenuMarker = "<div id=\"info_contenu\">"+
323
			contenuMarker = "<div id=\"info_contenu\">"+
333
			"Aucune commune française trouvée à cet emplacement <br />"
324
			"Aucune commune française trouvée à cet emplacement <br />"
334
			+"Déplacez ce marqueur pour localiser votre observation (commune et coordonnées)<br />"
325
			+"Déplacez ce marqueur pour localiser votre observation (commune et coordonnées)<br />"
335
			+"longitude="
326
			+"longitude="
336
			+ marker.getLatLng().getLongitude() + "<br />latitude="
327
			+ marker.getPosition().lng() + "<br />latitude="
Line 337... Line 328...
337
			+ marker.getLatLng().getLatitude() + "</div>";
328
			+ marker.getPosition().lat() + "</div>";
338
		} else {
329
		} else {
-
 
330
			contenuMarker = ""
-
 
331
			+valeurCommune+" ("+codeCommune+")<br />"
-
 
332
			+"longitude="
-
 
333
			+ marker.getPosition().lng() + "<br />latitude="
339
			contenuMarker = ""
334
			+ marker.getPosition().lat() ;
-
 
335
		}
-
 
336
		
Line 340... Line 337...
340
			+valeurCommune+" ("+codeCommune+")<br />"
337
		info.setContent(contenuMarker+ htmlBoutonOk);
341
			+"longitude="
-
 
342
			+ marker.getLatLng().getLongitude() + "<br />latitude="
-
 
343
			+ marker.getLatLng().getLatitude() ;
-
 
344
		}
-
 
345
		
-
 
346
		info.open(marker, new InfoWindowContent(""
338
		info.open(map, marker);	
Line -... Line 339...
-
 
339
		
-
 
340
		info.addDomReadyListenerOnce(new InfoWindow.DomReadyHandler() {	
-
 
341
			@Override
-
 
342
			public void handle() {
347
				+ contenuMarker
343
				ajouterListenerBouton("okMap");