Focusing selected layers
06.4 fixes the browser host's selected-layer operation falling back to the whole map. map.camera.fitLayer and fitLayers from the gis module use real layer references. Explicitly selected hidden layers are included, duplicate references are counted once, and unrelated layers do not affect the extent.
The local development SDK with matching WASM uses shared-core fitBounds, unions WGS84 vector extents, and applies padding and maxZoom. It handles ordinary geometries, GeometryCollection, null geometry, and string GeoJSON. Empty extents return NOT_FOUND. Invalid references, options, or coordinates reject before camera mutation. Traversal does not copy all coordinates or use an argument spread that can overflow; depth and node counts are bounded.
This complete application script targets the desktop console or web workbench with the matching development SDK. Layers still use the existing GIS interface; shared camera queries and confirmation import from sqsmap.
// @gis-api 0.5-session
// @permissions ["project.read", "map.write"]
import { map as legacy } from 'gis';
import { map } from 'sqsmap';
const west = await legacy.addGeoJSON('focus-west', {
type: 'FeatureCollection', features: [{ type: 'Feature', properties: {},
geometry: { type: 'Polygon', coordinates: [[[-100,30],[-99,30],[-99,31],[-100,31],[-100,30]]] }
}]
});
const east = await legacy.addGeoJSON('focus-east', {
type: 'FeatureCollection', features: [{ type: 'Feature', properties: {},
geometry: { type: 'Polygon', coordinates: [[[140,20],[141,20],[141,21],[140,21],[140,20]]] }
}]
});
await legacy.camera.fitLayer(west, { padding: 40 });
const single = await map.sqs.flush();
await legacy.camera.fitLayers([west, east], { padding: 24 });
const combined = await map.sqs.flush();
export default { single, combined };
| API/condition | Current behavior |
|---|---|
| New SDK: selected single/multiple layers | Focus only selected vector extents; immediate movement, default padding of 24 logical pixels |
| Older npm SDK: single layer with no focus options | Call existing focusLayer for that actual layer, never the whole map |
| Older npm SDK: multiple layers or padding/maxZoom options | CAPABILITY_UNAVAILABLE; leave the camera unchanged |
| Raster/terrain without a known extent | CAPABILITY_UNAVAILABLE; do not assume global coverage |
| Whole-map focus with padding/maxZoom | The browser does not implement this combination; explicit rejection, existing no-option behavior remains |
padding must be finite and nonnegative. maxZoom is 0–24; zero is preserved. Unknown options reject. The legacy desktop GIS maxZoom requires an explicit EPSG:3857 view; other GIS CRSs retain resolution-based calls. Shared map.fitBounds has the separate options documented in camera API.
GeoJSON extents use the minimum/maximum actual longitudes. Split date-line geometries or supply explicit world-copy coordinates when appropriate. Direct shared map.fitBounds([[170,-10],[-170,10]]) supports the date-line convention; these extent formats are not interchangeable.
This stage exercises the actual browser host's extent selection, options, empty data, collection geometries, large coordinate arrays, budgets, and old-SDK rejection. Its SDK is a test fixture, not browser GPU acceptance. Existing desktop selected-layer behavior is preserved. Mobile host, source updates, full globe/animation, and device acceptance remain in the task list.