Skip to main content

Fused Map

Using an AI agent?

Give your agent the Fused Map skill so it can inspect UDF outputs, choose the right layer types, and wire map parameters. For canvas and widget work in general, install the Workbench skills from fusedio/skills. Or paste this prompt to build a small example map:

Read https://docs.fused.io/skills/FUSED_MAP.md. Create a Fused canvas named sf_listings_map. Add a UDF sf_listings that reads s3://fused-sample/demo_data/airbnb_listings_sf.parquet and returns name, room_type, price_in_dollar, latitude and longitude. Add a Fused Map that shows the listings as points on a dark basemap, colored by room_type with a legend, and shows name and price_in_dollar in the tooltip. Validate the widget, push the canvas and give me its link.

Fused Map is a map widget in Fused. It draws geospatial data from a UDF, an h3-query widget or the H3 Data Retrieval REST API: points, polygons, H3 hexagons and raster tiles, with many layers on one map.

Its type is fused-map. It works like any other widget: configure it in JSON, connect UDFs with edges, and share it as a URL. To see working examples, open the Fused Map example canvas. For the props, see the Fused Map API reference.

Add a Fused Map widget​

  1. In the Workbench canvas, select the Widget icon in the toolbar.
  2. In the Widget configuration panel, select Preset, then Maps and geo, then Fused map.
  3. Connect the UDF node to the widget node with an edge.
  4. In the JSON, set udf to the name of the UDF in double braces, for example {{my_udf}}.

For a faster way, drag an edge from the output handle of a UDF node to an empty spot on the canvas, then select Fused map in the menu. Workbench creates a Fused Map widget that is already connected to the UDF and draws its result.

Drag an edge from a UDF node and select Fused map

note

The UDF must be on the same canvas. The name in {{ }} must match the UDF name exactly, with the same case.

Get data onto the map​

Each layer reads its rows from one of these sources:

SourceSet on the layerUse it for
A UDF"udf": "{{my_udf}}"Anything a UDF returns: points, polygons, H3 cells or a raster image.
An h3-query widget"data": "{{name}}", with an edge from the h3-query node to the mapThe rows of one query on an indexed H3 dataset, loaded in the browser.
The H3 Data Retrieval REST API"type": "fused-hex" and "source": {"path": "<dataset>"}A whole indexed dataset, fetched tile by tile as you pan and zoom, with no UDF.
A dataset indexed with fused.bbox.index"type": "fused-bbox" and "source": {"path": "<dataset>", "overview": {}}A table of features, fetched tile by tile from zoom 8 (minZoom). Below that zoom, the boxes of its chunks draw instead.

H3 Visualization has working examples of the h3-query and fused-hex sources, and the Fused Map API reference lists every layer type and prop.

To pass a widget input's value to a UDF, write {{my_udf?<udf_argument>=$<param>}}, where <param> is the input's param name. For example, "udf": "{{my_udf?band_index=$band}}" passes the value of an input whose param is band to the UDF's band_index argument, and runs the UDF again when it changes.

Load a UDF per tile​

Name the first argument bounds to load data per tile

With tile: true, the map passes each tile's area as [west, south, east, north] in EPSG:4326. Return only the rows inside bounds. The type doesn't matter, only the name.

@fused.udf
def udf(bounds):
...
tileFirst argument is boundsResult
trueYesEach tile gets its own data.
trueNoEvery tile gets the same result.
falseEitherThe UDF runs once and bounds is ignored.

Example: a raster and points​

This map shows San Francisco Airbnb listings as points on top of a Bay Area seismic hazard raster. A raster layer draws the image a UDF returns. With tile: true and a bounds argument, each tile reads only its window of the GeoTIFF.

Show the widget JSON
{
"type": "fused-map",
"props": {
"basemap": "mapbox://styles/mapbox/dark-v11",
"centerLng": -122.3,
"centerLat": 37.7,
"zoom": 9.5,
"autoFit": false,
"layers": [
{
"id": "sf_listings",
"name": "SF Airbnb listings",
"type": "geojson",
"udf": "{{sf_listings}}",
"latColumn": "latitude",
"lngColumn": "longitude",
"tooltip": ["name", "price_in_dollar", "room_type"],
"legend": true,
"style": {
"fillColor": { "type": "categorical", "attr": "room_type", "palette": "Bold" },
"pointRadius": 4,
"opacity": 0.85
}
},
{
"id": "seismic",
"name": "Bay Area seismic hazard (raster)",
"type": "raster",
"udf": "{{bay_area_seismic_raster}}",
"tile": true,
"minZoom": 0,
"maxZoom": 19,
"style": { "opacity": 0.6 }
}
]
}
}
Show the bay_area_seismic_raster UDF

The raster layer uses tile: true, so the first argument is bounds.

@fused.udf
def udf(
bounds: fused.types.Bounds = [-122.6, 37.2, -121.7, 38.0],
path: str = "s3://fused-asset/demos/seismic_data/v2023_1_pga_475_rock_3min.tif",
):
common = fused.load("https://github.com/fusedio/udfs/tree/fbf5682/public/common/")
tile = common.get_tiles(bounds, zoom=common.estimate_zoom(bounds))
arr = common.read_tiff(tile, input_tiff_path=path)
return common.arr_to_plasma(arr.filled(0), min_max=(0, 1.5))
Show the sf_listings UDF

The points layer runs once and has no bounds argument.

@fused.udf
def udf():
import pandas as pd

path = "s3://fused-sample/demo_data/airbnb_listings_sf.parquet"
df = pd.read_parquet(path)
df = df.dropna(subset=["latitude", "longitude", "price_in_dollar"])
return df[["name", "latitude", "longitude", "price_in_dollar", "room_type"]]

The Fused Map example canvas has working UDF and widget examples. For the style, tooltip, legend, and filter props, see the Fused Map API reference.

Layer order and zoom​

The first layer in layers, the top card in the sidebar, draws on top of the others.

{ "id": "parcels", "type": "geojson", "udf": "{{parcels}}", "visibleMinZoom": 12 }

visibleMinZoom and visibleMaxZoom hide a layer outside a zoom range. The layer keeps its data, so it shows again without reloading. They differ from minZoom and maxZoom, which set the zooms a tiled layer has data at.

Show different data at each zoom​

{
"id": "places",
"type": "composite",
"h3Column": "hex",
"levels": [
{ "id": "z0", "maxZoom": 8, "type": "fused-hex", "source": { "path": "s3://my-bucket/places_res5/", "overview": {} } },
{ "id": "z8", "minZoom": 8, "type": "geojson", "udf": "{{place_shapes}}", "tile": true, "tooltip": ["name"] }
]
}

A composite layer draws one of its levels at a time: the one whose minZoom to maxZoom range holds the map zoom. When you zoom into another level's range, the previous level stays on screen until the new one has loaded, so the map never flashes empty. A level can be any other layer type and only sets what differs from the composite. The composite's sql and filters apply at every level.

Play data over time​

{
"id": "quakes",
"type": "scatterplot",
"udf": "{{quakes}}",
"latColumn": "latitude",
"lngColumn": "longitude",
"filters": [
{
"attr": "time",
"type": "time",
"min": "2024-01-01",
"max": "2024-01-31",
"playback": true,
"playbackOptions": { "mode": "window", "interval": "1-day", "skipEmpty": true }
}
]
}

A time filter keeps the rows whose attr falls between min and max: ISO dates, epoch milliseconds or a $param. With playback: true, the map opens a playback bar on load, with a histogram of the rows over time, a window you can drag, and play and speed controls. In the sidebar, the filter's clock button opens and closes the bar.

playbackOptions.mode is auto, window (a fixed-width window moves), point (one histogram bar at a time) or cumulative (the end grows from the first time). skipEmpty jumps over stretches with no rows. To follow the bar from another widget, set the map's playbackParam.

Color by quantile​

{
"id": "sf_listings",
"type": "geojson",
"udf": "{{sf_listings}}",
"latColumn": "latitude",
"lngColumn": "longitude",
"style": {
"fillColor": { "type": "continuous", "attr": "price_in_dollar", "palette": "Sunset", "steps": 7, "scaleType": "quantile" }
}
}

"scaleType": "quantile" gives each color about the same number of rows, so skewed values still use every color. The default, quantize, splits domain into equal-width steps.

Send map values to other widgets​

A map can send its viewport bounds (param), the clicked feature (clickParam), the hovered feature (hoverParam), its selection (selectParam: shift+drag draws a box, shift+click adds or removes one feature), its camera (stateParam) and a per-layer row version (sourceParam) to canvas parameters. Other widgets and UDFs read them as $<name>. See the Fused Map API reference for each one.

In this widget the map reads $room_type from the dropdown, and sends its bounds to $map_bounds and the clicked listing to $clicked_listing. The bar chart counts the listings in view by room type.

Show the widget JSON
{
"type": "div",
"props": {
"style": "display:flex;flex-direction:row;gap:8px;height:100%"
},
"children": [
{
"type": "div",
"props": {
"style": "flex:1;min-width:0;display:flex;flex-direction:column;gap:8px"
},
"children": [
{
"type": "dropdown",
"props": {
"label": "Room type",
"param": "room_type",
"defaultValue": "All",
"sql": "SELECT value, label FROM (SELECT 'All' AS value, 'All room types' AS label, 0 AS o UNION ALL SELECT DISTINCT room_type, room_type, 1 FROM {{sf_listings}}) ORDER BY o, label"
}
},
{
"type": "fused-map",
"props": {
"style": "flex:1;min-height:0",
"basemap": "mapbox://styles/mapbox/dark-v11",
"centerLng": -122.43,
"centerLat": 37.76,
"zoom": 12,
"param": "map_bounds",
"autoSend": true,
"clickParam": "clicked_listing",
"layers": [
{
"id": "listings",
"name": "SF Airbnb listings",
"type": "geojson",
"sql": "SELECT * FROM {{sf_listings}} WHERE $room_type = 'All' OR room_type = $room_type",
"latColumn": "latitude",
"lngColumn": "longitude",
"tooltip": ["name", "room_type", "price_in_dollar"],
"style": {
"fillColor": { "type": "categorical", "attr": "room_type", "palette": "Bold" },
"pointRadius": 3
}
}
]
}
}
]
},
{
"type": "div",
"props": {
"style": "width:320px;flex-shrink:0;display:flex;flex-direction:column;gap:8px"
},
"children": [
{
"type": "bar-chart",
"props": {
"title": "Listings in view by room type",
"sql": "SELECT room_type AS label, COUNT(*) AS value FROM {{sf_listings}} WHERE longitude BETWEEN $map_bounds[1] AND $map_bounds[3] AND latitude BETWEEN $map_bounds[2] AND $map_bounds[4] GROUP BY 1 ORDER BY 2 DESC",
"style": "flex:1;min-height:0"
}
},
{
"type": "text",
"props": {
"value": "Clicked: $clicked_listing",
"variant": "small"
}
}
]
}
]
}

To link a map to several charts in one HTML template node, see cross-filtering.

Map options​

{
"type": "fused-map",
"props": {
"showSearch": true,
"layerBlending": "additive",
"layers": []
}
}

showSearch adds a place search that takes place names, lat, lng pairs and H3 cell IDs, and flies the map there. layerBlending sets how overlapping layers blend: normal (the default), additive (overlaps grow brighter, best on a dark basemap) or subtractive (overlaps grow darker).

The sidebar​

The sidebar lists the map's layers. For each one, the viewer can change the type, the style, the filters and the SQL in the browser. Its tabs are Layers, Filters, Base map and Settings. Settings shows the full map config, with every default filled in.

The Fused Map sidebar next to the map and the widget configuration

On your own canvas, sidebar edits are written into the widget JSON as you make them; undo them with ⌘/Ctrl+Z. Elsewhere, such as on a shared page, they apply to your view only: select Copy config to paste them into the JSON.