Container for all built-in visualization modules.

class LeafletPortrayal(style: dict[str, LeafletOption] | None = None, pointToLayer: dict[str, LeafletOption] | None = None, popupProperties: dict[str, LeafletOption] | None = None)[source]#

A dataclass defining the portrayal of a GeoAgent in Leaflet map.

The fields are defined to be consistent with GeoJSON options in Leaflet.js:

style: dict[str, LeafletOption] | None = None#
pointToLayer: dict[str, LeafletOption] | None = None#
popupProperties: dict[str, LeafletOption] | None = None#
class MapModule(portrayal_method=None, view=None, zoom=None, map_width=500, map_height=500, tiles={'attribution': '(C) OpenStreetMap contributors', 'html_attribution': '&copy; <a href="">OpenStreetMap</a> contributors', 'max_zoom': 19, 'name': 'OpenStreetMap.Mapnik', 'url': '{z}/{x}/{y}.png'}, scale_options=None)[source]#

A MapModule for Leaflet maps that uses a user-defined portrayal method to generate a portrayal of a raster Cell or a GeoAgent.

For a raster Cell, the portrayal method should return a (r, g, b, a) tuple.

For a GeoAgent, the portrayal method should return a dictionary.

Create a new MapModule.

  • portrayal_method – A method that takes a GeoAgent (or a Cell) and returns a dictionary of options (or a (r, g, b, a) tuple) for Leaflet.js.

  • view – The initial view of the map. Must be set together with zoom. If both view and zoom are None, the map will be centered on the total bounds of the space. Default is None.

  • zoom – The initial zoom level of the map. Must be set together with view. If both view and zoom are None, the map will be centered on the total bounds of the space. Default is None.

  • map_width – The width of the map in pixels. Default is 500.

  • map_height – The height of the map in pixels. Default is 500.

  • tiles

    An optional tile layer to use. Can be a RasterWebTile or a xyzservices.TileProvider. Default is xyzservices.providers.OpenStreetMap.Mapnik.

    If the tile provider requires registration, you can pass the API key inside the options parameter of the RasterWebTile constructor.

    For example, to use the Mapbox raster tile provider, you can use:

    import mesa_geo as mg
            "access_token": "my-private-ACCESS_TOKEN",
            "attribution": '&copy; <a href="" target="_blank">Mapbox</a> &copy; <a href="">OpenStreetMap</a> contributors <a href="" target="_blank">Improve this map</a>',

    Note that access_token can have different names depending on the provider, e.g., api_key or key. You can check the documentation of the provider for more details.

    xyzservices provides a list of providers requiring registration as well:

    For example, you may use the following code to use the Mapbox provider:

    import xyzservices.providers as xyz
    xyz.MapBox(id="<insert map_ID here>", accessToken="my-private-ACCESS_TOKEN")

  • scale_options – A dictionary of options for the map scale. Default is None (no map scale). The available options can be found at:

local_includes: ClassVar = ['js/MapModule.js', 'css/external/leaflet.css', 'js/external/leaflet.js']#
local_dir = PosixPath('/home/docs/checkouts/')#
js_code = ''#

Build visualization data from a model object.


model: A model object


A JSON-ready object.

package_includes: ClassVar = []#
render_args: ClassVar = {}#