Subversion Repositories eFlore/Applications.cel

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
247 aurelien 1
package org.tela_botanica.client.vues.observation;
2
 
3
import org.tela_botanica.client.interfaces.Rafraichissable;
4
import org.tela_botanica.client.modeles.EntiteGeographiqueObservation;
5
import org.tela_botanica.client.observation.ObservationMediateur;
6
 
7
import com.google.gwt.maps.client.InfoWindow;
8
import com.google.gwt.maps.client.InfoWindowContent;
9
import com.google.gwt.maps.client.MapType;
10
import com.google.gwt.maps.client.MapWidget;
11
import com.google.gwt.maps.client.control.LargeMapControl;
12
import com.google.gwt.maps.client.event.MarkerClickHandler;
13
import com.google.gwt.maps.client.event.MarkerDragEndHandler;
14
import com.google.gwt.maps.client.event.MarkerDragStartHandler;
15
import com.google.gwt.maps.client.event.MarkerDragEndHandler.MarkerDragEndEvent;
16
import com.google.gwt.maps.client.event.MarkerDragStartHandler.MarkerDragStartEvent;
17
import com.google.gwt.maps.client.geom.LatLng;
18
import com.google.gwt.maps.client.overlay.Marker;
19
import com.google.gwt.maps.client.overlay.MarkerOptions;
20
import com.google.gwt.user.client.Window;
21
import com.google.gwt.user.client.ui.HTML;
22
import com.gwtext.client.core.EventCallback;
23
import com.gwtext.client.core.EventObject;
24
import com.gwtext.client.core.Ext;
25
import com.gwtext.client.core.ExtElement;
26
import com.gwtext.client.core.RegionPosition;
27
import com.gwtext.client.widgets.Component;
28
import com.gwtext.client.widgets.Container;
29
import com.gwtext.client.widgets.Panel;
30
import com.gwtext.client.widgets.event.ContainerListener;
31
import com.gwtext.client.widgets.event.ContainerListenerAdapter;
32
import com.gwtext.client.widgets.form.Label;
33
import com.gwtext.client.widgets.layout.BorderLayout;
34
import com.gwtext.client.widgets.layout.BorderLayoutData;
35
import com.gwtext.client.widgets.layout.FitLayout;
36
import com.gwtext.client.widgets.layout.RowLayout;
37
import com.gwtext.client.widgets.layout.RowLayoutData;
38
import com.gwtext.client.widgets.map.LatLonPoint;
39
 
40
public class CartographieObservationVue extends Panel implements Rafraichissable {
41
 
42
	private String id = "cartographie_observation";
43
 
44
	private ObservationMediateur oMediateur = null;
45
 
46
	Panel panneauCarto = null;
47
	private MapWidget map;
48
 
49
	private boolean carteAjoutee = false;
50
	private boolean requeteEnCours = false;
51
 
52
	String valeurCommune = "Bourges";
53
	LatLng centreFrance = LatLng.newInstance(47.0504, 2.2347);
54
	LatLng pointCommune = centreFrance;
55
	String codeCommune = "";
56
 
57
	int niveauZoom = 9;
58
 
59
	Label panneauExplication = new Label(
60
			"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");
61
 
62
	private InfoWindow info;
63
 
64
	public CartographieObservationVue(ObservationMediateur om) {
65
		oMediateur = om;
66
 
67
		setTitle("Carto");
68
		setAutoWidth(true);
69
		setPaddings(10);
70
 
71
		panneauCarto = new Panel();
72
		panneauCarto.setLayout(new FitLayout());
73
 
74
		setLayout(new RowLayout());
75
 
76
		//initialiserCarte();
77
 
78
		add(panneauExplication, new RowLayoutData(12));
79
		add(panneauCarto, new RowLayoutData());
80
 
81
		addListener(new ContainerListenerAdapter() {
82
			public void onAfterLayout(Container c) {
83
 
84
				if(!carteAjoutee) {
85
					initialiserCarte();
86
				}
87
				recentrerCarte();
88
			}
89
		});
90
 
91
		panneauCarto.setAutoHeight(true);
92
	}
93
 
94
	public void masquerChargement(boolean masquer) {
95
		if (masquer) {
96
			ExtElement masked = Ext.get(id);
97
 
98
			if (masked != null) {
99
				masked.mask("Chargement");
100
			}
101
		} else {
102
			ExtElement masked = Ext.get(id);
103
 
104
			if (masked != null) {
105
				masked.unmask();
106
			}
107
		}
108
	}
109
 
110
	public void obtenirInfosCommunes(LatLng coord) {
111
		oMediateur.obtenirInformationCoord(this, coord);
112
	}
113
 
114
	public void mettreAJourInfos(final LatLng pointNouvelleCommune, String infosComplementaires, int zoom) {
115
 
116
		if (!carteAjoutee) {
117
			initialiserCarte();
118
		}
119
 
120
		pointCommune = pointNouvelleCommune;
121
		map.clearOverlays();
122
		Marker nmk = fabriquerMarqueur(pointCommune, infosComplementaires);
123
		map.addOverlay(nmk);
124
		afficherInfoMarker(nmk);
125
		recentrerCarte();
126
	}
127
 
128
	public void initialiserCarte() {
129
 
130
		map = new MapWidget(pointCommune, niveauZoom);
131
		panneauCarto.add(map);
132
		panneauCarto.doLayout();
133
		info = map.getInfoWindow();
134
		map.checkResizeAndCenter();
135
		map.setUIToDefault();
136
		map.addControl(new LargeMapControl());
137
		map.setCurrentMapType(MapType.getHybridMap());
138
		carteAjoutee = true;
139
		panneauCarto.doLayout();
140
	}
141
 
142
	public void AfficherMessageAucuneInfos() {
143
		mettreAJourInfos(centreFrance,"", niveauZoom);
144
		Window.alert("Aucune information pour le nom donné");
145
	}
146
 
147
	public int getNiveauZoom() {
148
		return niveauZoom;
149
	}
150
 
151
	private void ajouterListenerBouton(String idBouton) {
152
		ExtElement bouton = Ext.get(idBouton);
153
 
154
		bouton.addListener("click", new EventCallback() {
155
 
156
			public void execute(EventObject e) {
157
				EntiteGeographiqueObservation infosCommune = new EntiteGeographiqueObservation(codeCommune,valeurCommune,null);
158
				infosCommune.setLat(pointCommune.getLatitude()+"");
159
				infosCommune.setLon(pointCommune.getLongitude()+"");
160
				oMediateur.rafraichirSaisieCommuneObservation(infosCommune);
161
			}
162
 
163
		});
164
	}
165
 
166
	public void rafraichir(Object nouvelleDonnees,
167
			boolean repandreRaffraichissement) {
168
		if (nouvelleDonnees instanceof String) {
169
 
170
			if(isVisible()) {
171
				Window.alert((String)nouvelleDonnees);
172
			}
173
		}
174
 
175
		if (nouvelleDonnees instanceof Object[]) {
176
 
177
			Object[] infos = (Object[]) nouvelleDonnees;
178
			LatLng coord = LatLng.newInstance((Double) infos[0],
179
					(Double) infos[1]);
180
 
181
			valeurCommune = (String)infos[3];
182
			codeCommune = (String)infos[2];
183
 
184
			mettreAJourInfos(coord, "", niveauZoom);
185
		}
186
 
187
		masquerChargement(false);
188
	}
189
 
190
	public Marker fabriquerMarqueur(LatLng pointMarqueur, final String texte) {
191
		// ajout de marqueurs déplacables, qui affichent une bulle d'information
192
		MarkerOptions options = MarkerOptions.newInstance();
193
		options.setDraggable(true);
194
		final Marker marker = new Marker(pointMarqueur, options);
195
 
196
		marker.addMarkerDragEndHandler(new MarkerDragEndHandler() {
197
			public void onDragEnd(MarkerDragEndEvent event) {
198
				afficherInfoMarker(marker);
199
			}
200
 
201
		});
202
 
203
		marker.addMarkerDragStartHandler(new MarkerDragStartHandler() {
204
			public void onDragStart(MarkerDragStartEvent event) {
205
				info.setVisible(false);
206
			}
207
		});
208
 
209
		marker.addMarkerClickHandler(new MarkerClickHandler() {
210
 
211
			public void onClick(MarkerClickEvent event) {
212
				if(info.isVisible()) {
213
					info.close();
214
				} else {
215
					afficherInfoMarker(marker);
216
				}
217
			}
218
		});
219
 
220
		return marker;
221
	}
222
 
223
	public void recentrerCarte() {
224
		//mettreAJourInfos(pointCommune,"", niveauZoom);
225
		map.setSize((this.getWidth() - 12)+"px" , (this.getHeight() - 24)+"px");
226
		panneauCarto.setSize((this.getWidth() - 12)+"px" , (this.getHeight() - 12)+"px");
227
		map.setCenter(pointCommune, niveauZoom);
228
		map.checkResizeAndCenter();
229
	}
230
 
231
	public boolean isCarteAjoutee() {
232
		return carteAjoutee;
233
	}
234
 
235
	public void afficherInfoMarker(Marker marker) {
236
		final String htmlBoutonOk = "<br /><button id=\"okMap\" class=\"x-btn-text\" type=\"button\">OK</button>";
237
 
238
		info.open(marker, new InfoWindowContent(""
239
				+valeurCommune+" ("+codeCommune+")<br />"
240
				+"longitude="
241
				+ marker.getLatLng().getLongitude() + "<br />latitude="
242
				+ marker.getLatLng().getLatitude() + htmlBoutonOk));
243
 
244
		ajouterListenerBouton("okMap");
245
	}
246
 
247
}