Skip to main content
Version: Next (5.0)

Map

A map shows the rows of a query as markers over a geographic map. You describe it in the screen XML with a map element. The map loads its data from a query, like any other AWE component, and clicking a marker selects its row, so the dependencies of the map (and the components that depend on it) react to the selection.

Note: The map is available in the React engine. AngularJS support is pending (#798).

The map is drawn with Leaflet (BSD-2-Clause licence) and the tiles come from OpenStreetMap by default. Neither needs an API key.

Map element​

<map id="fleet" initial-load="query" target-action="TstMapPoints"
latitude="Lat" longitude="Lon" marker-label="Lug"
zoom="4" center-latitude="43.86" center-longitude="1.11" style="expand"/>
AttributeUseTypeDescriptionValues
idRequiredStringMap identifier
styleOptionalStringCSS classes of the mapexpand makes the map fill the space of its container
initial-loadOptionalStringLoads the map when the screen is generatedOnly the query value
server-actionOptionalStringType of server action that loads the map
target-actionOptionalStringName of the query that loads the map
maxOptionalNumberNumber of markers to load0 stands for all of them
autorefreshOptionalNumberInterval of the automatic reload of the map
latitudeOptionalStringName of the data column with the latitude of the markerDefaults to latitude
longitudeOptionalStringName of the data column with the longitude of the markerDefaults to longitude
marker-labelOptionalStringName of the data column shown in the popup of the markerWithout it the markers have no popup
zoomOptionalNumberInitial zoom levelDefaults to 4. It applies when the map has a center
center-latitudeOptionalDecimalLatitude of the initial center of the mapSet it together with center-longitude
center-longitudeOptionalDecimalLongitude of the initial center of the mapSet it together with center-latitude

Without center-latitude and center-longitude the map fits its view to the markers. A map with no markers shows a default view.

Data format​

The query returns one row per marker. The id of the row is the value of the marker, the latitude and longitude columns (or the ones named by the attributes) place it and the marker-label column is the text of its popup. A row whose coordinates are empty or not numeric has no marker.

<query id="TstMapPoints" service="TstMapPoints"/>
idLatLonLug
140.4168-3.7038Madrid
241.38742.1686Barcelona
339.4699-0.3763Valencia
437.3891-5.9845Sevilla

Selection and dependencies​

Clicking a marker selects its row (and opens its popup). The id of the row becomes the selected value of the map, so the map is sent to the server with the selected marker, and the marker is drawn in a different color. The rows of the map work like the rows of a grid for the dependencies: the attribute selectedRowValue of a dependency-element is the value of a column in the selected marker.

<criteria id="MapSel" label="Selected place" component="text" readonly="true">
<dependency source-type="formule" target-type="input" formule="'[place]'">
<dependency-element id="fleet" column="Lug" attribute="selectedRowValue" alias="place"/>
</dependency>
</criteria>

The map can also hold its own dependency children, like the other components.

Drawing a route​

The polyline client action draws a route over the map: the points go in the rows parameter, with the latitude and longitude columns of the map (latitude and longitude by default). While the route is shown the markers are hidden and the view centers on the first point of the route (zoom level 8). A route without points removes the route and the markers come back.

public ServiceData route() {
List<Map<String, Object>> rows = List.of(
Map.of("Lat", 40.4168, "Lon", -3.7038),
Map.of("Lat", 41.3874, "Lon", 2.1686));

ClientActionBuilder<?> builder = new ClientActionBuilder<>();
builder.setType("polyline");
builder.setTarget("fleet");
builder.addParameter("rows", rows);
return new ServiceData().addClientAction(builder.build());
}

Tiles and attribution​

The tiles come from the OpenStreetMap server (https://tile.openstreetmap.org/{z}/{x}/{y}.png) unless you set the property awe.application.map.tile-url to the URL template of another tile server, with the {z}, {x} and {y} markers:

awe.application.map.tile-url=https://tiles.example.com/{z}/{x}/{y}.png

Warning: The OpenStreetMap tile server is for light use and has an usage policy that you have to follow. An application with a lot of traffic must use its own tile server or a commercial tile provider, because the policy allows the OpenStreetMap Foundation to block heavy use.

The map shows the attribution "© OpenStreetMap contributors" with a link to the OpenStreetMap copyright page, as the data licence (ODbL) requires, and the Leaflet credit. Do not hide them. The zoom is limited to levels 3 to 19, the ones that the OpenStreetMap tiles provide.