FitToSchema
constFitToSchema:ZodObject<{maxZoom:ZodOptional<ZodNumber>;padding:ZodOptional<ZodNumber>;source:ZodString; },"strip",ZodTypeAny, {maxZoom?:number;padding?:number;source:string; }, {maxZoom?:number;padding?:number;source:string; }>
Defined in: packages/core/src/schemas/map.schema.ts:224
Fit the initial camera to a source’s data (U14, ml-chh.9).
Remarks
Section titled “Remarks”The data-driven sibling of bounds: — where bounds takes literal
coordinates, fitTo names a GeoJSON entry in sources: and the camera
frames whatever that source holds. It reuses the bounds walk the
zoomToFeature click interaction uses, applied to the whole source on
load instead of one clicked feature on click.
- Inline
data:— the bounds are known before the map exists, so the map is constructed already framed (no camera jump). url:— the map opens at the authoredcenter/zoom, then jumps to the data’s bounds once the first fetch lands (refreshes do not re-fit: the user owns the camera after load).- vector / raster / raster-dem — not supported: tiled sources have no client-side extent before they render. The renderer warns once and keeps the authored camera.
center/zoom stay required: they are the camera before the data
arrives, the camera when the fit cannot apply, and the fallback emit uses
when the data is not inline. fitTo wins over bounds when both are set.
On emit (fallback class) an inline source’s bounds compile to a
concrete center/zoom computed for a 1024×768 reference viewport —
lossy, because a live map fits its own container.