Visualization#

Modules#

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: https://leafletjs.com/reference.html#geojson

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="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors', 'max_zoom': 19, 'name': 'OpenStreetMap.Mapnik', 'url': 'https://tile.openstreetmap.org/{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.

Parameters:
  • 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
    
    mg.RasterWebTile(
        url="https://api.mapbox.com/v4/mapbox.satellite/{z}/{x}/{y}.png?access_token={access_token}",
        options={
            "access_token": "my-private-ACCESS_TOKEN",
            "attribution": '&copy; <a href="https://www.mapbox.com/about/maps/" target="_blank">Mapbox</a> &copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors <a href="https://www.mapbox.com/map-feedback/" 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: https://xyzservices.readthedocs.io/en/stable/registration.html

    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: https://leafletjs.com/reference.html#control-scale-option

local_includes: ClassVar = ['js/MapModule.js', 'css/external/leaflet.css', 'js/external/leaflet.js']#
local_dir = PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/mesa-geo/checkouts/main/mesa_geo/visualization/templates')#
js_code = ''#
render(model)[source]#

Build visualization data from a model object.

Args:

model: A model object

Returns:

A JSON-ready object.

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