==== Controller for GMap ==== The GMapController gives a simple way to display a map provided by google according to coordinates or address. This is a FieldController that means that it can be linked to the databinding service. ==== Control ==== The control org.adichatz.engine.widgets.GMap was developped by Adichatz. GMap is a composite control which contains a browser. A http request is send to google and map result is displayed. ==== Usage: ==== === Example 1: Store coordinates as String === In this example, field coordinates is stored in the database as a string with following syntax where latitude and longitude use format ##.## (in this example value is <45.75 : 4.85>).\\ Two controllers are linked to the model field coordinates: - **coordinates** which display value in Text control. - **map** which display value as a map in a GMap control. Both controls are databound: If value changes in a control, modification is reported to the other control or anywhere in the application. That is a standard behavior. == Code ==
import adichatzJboss7E4.GeometryUtil; import com.vividsolutions.jts.geom.Point; import org.adichatz.engine.widgets.supplement.LatLng; Point point = (Point) GeometryUtil.getGeometryFromInputStream(value); return new LatLng(point.getX(), point.getY(), getControl().getPattern());
== Overview == {{:controllers:gmap_coordinates.png |GMap - Store coordinates as String}} \\ == Explanations == ^ **coordPattern**: |Coordinates pattern here is using ##.## format.| ^ **mapTypeId**:|Choose between roadmap, satellite, hybrid, terrain.| ^ **mapDataType**:|Choose between COORDINATES ( value is a point) and ADDRESS (value is a postal address).| ^ **mapTypeControl**:true|Add control for choosing Map Type (roadmap, satellite...) in the map .| ^ **noLabel**:|No label are affected to control map. By default, when a field control is linked to a model field (here property="coordinates"), a label control is automatically created.| ^ **toolBarStyle**:|AdiSWT.EDITABLE: Coordinates control is editable.| ^ **zoom**:|Give a value between 0 and 20 (default is 12).| ^ ****:|Value from target is a LatLng type and must be converted to a Point.| \\ \\ === Example 2: Store coordinates as two float fields: Latitude and Longitude === In this example, fields latitude and longitude are stored in the database as floats.\\ So control map cannot be link to the database because one control cannot be databound to 2 model fields. So programming must be used. Synchronization of map control following to database fields is done in displayMap function (lines 6 and 9-19). This function is called thru 3 listeners of detailContainer controller: * AFTER_SYNCHRONIZE: synchronize is a step in the life cycle of controller when data from entity are injected in fields controllers. * AFTER_PROPERTY_CHANGE: After a change was sent to a property of the Entity by the databinding service. * POST_REFRESH: If the entity is refreshed from database. In the other hand, changes made thru GMap control are broadcast to latitude and longitude controllers. This way to manage synchronization between controllers is compatible with databinding service: Changes are synchronized in other editors if needed. == Code ==
displayGMap(); import org.adichatz.engine.widgets.GMap; private boolean doit = true; private void displayGMap() { if (doit) { doit = false; GMap gmapControl = #CONTROL(map); Gmap gmap = #BEAN(); gmapControl.setValue(gmap.getLatitude() + " : " + gmap.getLongitude()); doit = true; } } if (doit) { doit = false; #CONTROLLER(latitude).broadCastedSetValue(gmap.getCenter().getLatitude()); #CONTROLLER(longitude).broadCastedSetValue(gmap.getCenter().getLongitude()); doit = true; }
== Overview == {{:controllers:gmap_lat_lng.png |GMap - Store coordinates as Latitude and Longitude}} \\ == Explanations == ^ **doit**:|Allows to avoid tha change done by programming .| ^ **#BEAN()**:|The bean of the current entity.| ^ **#CONTROLLER(latitude)**:|Reference to the controller containing a FormattedText control and bound to latitude model field of bean Gmap.| ^ **.broadCastedSetValue(...)**:|Sets a value in the control of ther controller and launches the databinding mecchanism.| \\ \\ === Example 3: Store address as string === Two controllers are linked to the model field address: - **address** which display value in Text control. - **map** which display value as a map in a GMap control. Both controls are databound: If value changes in a control, modification is reported to the other control or anywhere in the application. That is a standard behavior. == Code ==
== Overview == {{:controllers:gmap_address.png |GMap - Store Address as String}} \\ == Explanations == ^ **mapType**:|Terrainis selected.| ^ **toolBarStyle**|AdiSWT.ADDRESS: Use Adress text control, AdiSWT.EDITABLE: Address control is editable.| ^ **noLabel**:|No label are affected to control map.|