Skip to content

Leaflet module methods

In the following functions, mapId always refers to the unique id of a single map in the GUI, as defined in the Leaflet.createMap function with the mapId parameter.

Leaflet.addCircle

Leaflet.addCircle(mapId, shapeId, point, tooltip="", options=list())

Queue a new circle in the shapes layer. When all shapes are added, call flushShapes() to draw all the shapes at once.

  • shapeId is a unique shape id;
  • point is the center of the circle created with Leaflet.latLng();
  • tooltip is a text showing when clicking on the shape;
  • options are the Circle polygon options. You should at least set the radius of the circle.

Leaflet.addGeoJSON

Leaflet.addGeoJSON(mapId, data)

Queue a new GeoJSON shape for future rendering on the map. When all GeoJSON shapes are added, call flushGeoJSON() to draw all the GeoJSON shapes at once.

  • mapId is the id of the map;
  • data is a list of:
    • id: a unique id for the shape/zone;
    • points: a list of points;
    • tooltip: the HTML content of the tooltip when the user put its mouse over the shape;
    • color: an HTML hex color, like #ff0000.

Leaflet.addPolygon

Leaflet.addPolygon(mapId, shapeId, points, tooltip="", options=list())

Queue a new polygon in the shapes layer. When all shapes are added, call flushShapes() to draw all the shapes at once.

  • shapeId is a unique shape id;
  • points is a list of points for the polygon created with Leaflet.latLng();
  • tooltip is a text showing when clicking on the shape;
  • options are the Leaflet polygon options.

Leaflet.createIcon

Leaflet.createIcon(iconId, options)

Create a new icon for future markers. Icon should be created before initializing the map.

Leaflet.createMap

Leaflet.createMap(mapId, step, widgetId, layer = layerURL, height = 512, options = list(), layerOptions = list())

Create a new map widget. This function must be called before entering the GUI containing the map.

  • mapId is a unique name you give to the map
  • step is the step where the map will be, created with rpgm.step()
  • widgetId is the id of the label widget that will contain the map
  • layerURL is the tile layer URL (see TileLayer documentation), and layerOptions are the TileLayer Options.
  • options is the map options as defined by the Leaflet map options

Leaflet.fitBounds

Leaflet.fitBounds(mapId, bounds)

Show a specific view on the map.

  • bounds is a LatLngBounds created with Leaflet.latLngBounds()

Leaflet.flushGeoJSON

Leaflet.flushGeoJSON(mapId)

Remove all previous rendered geojson shapes and draw all the queued shapes with addGeoJSON().

Leaflet.flushShapes

Leaflet.flushShapes(mapId)

Remove all previous rendered simple shapes and draw all the queued shapes with addCircle() and addPolygon().

Leaflet.hideLoading

Leaflet.hideLoading(mapId)

Hide the loading state of a map.

Leaflet.latLng

Leaflet.latLng(lat, lng)

Create a new LatLng object to use where Leaflet LatLng object are used.

Leaflet.latLngBounds

Leaflet.latLngBounds(corner1, corner2)

Create a new LatLng object to use where Leaflet LatLngBounds object are used.

Leaflet.marker

Leaflet.marker(iconId, latlng, popup, options = list())

Create a new marker to be used with Leaflet.updateMarkers().

  • iconId is the id of an icon created with Leaflet.createIcon();
  • latlng is the position of the marker created with Leaflet.latLng();
  • popup is the HTML content of the popup when the user click on the marker;
  • options is a list of Leaflet marker options.

Leaflet.on

Leaflet.on(mapId, eventName, callback)

Add a new event listener. See the Events section for more information.

Leaflet.off

Leaflet.off(mapId, eventName, callback)

Remove an existing event listener. See the Events section for more information.

Leaflet.setView

Leaflet.setView(mapId, center, zoom)

Set the view of the map to a specific point and zoom.

  • center is a LatLng point created with Leaflet.latLng();
  • zoom is the wanted zoom level.

Leaflet.setZoom

Leaflet.setZoom(mapId, zoom)

Set the zoom level of the map.

Leaflet.showLoading

Leaflet.showLoading(mapId)

Show the loading state of a map with a spinning animation over the map.

Leaflet.triggerViewEvent

Leaflet.triggerViewEvent(mapId)

Force the map to send an onDidChangeView event. Useful to refresh the map view after loading data for example.

Leaflet.updateLegend

Leaflet.updateLegend(mapId, content)

Update the content of the legend of the map with content.

Leaflet.updateMarkers

Leaflet.updateMarkers(mapId, markers)

Remove all existing markers on the map and draw all the markers in the markers parameter.

  • mapId is the id of the map;
  • markers should be a list of markers created with Leaflet.marker().