Skip to main content

Spherical lines, polygons and shared queries

Shared GeoJSON circle, line and fill layers survive globe projection changes and support creation, order, paint, filters and visibility on the sphere. Browser main/strict Worker, native-library scripts and desktop scripts use the same calls. Naming follows the MapLibre Map API, with paint conventions from the MapLibre layer specification; SqsMap implements the engine independently.

import { map } from 'sqsmap';
const capabilities = await map.sqs.getCapabilities();
if (!capabilities.globeGeoJsonSurfaceLayers || !capabilities.globeGeoJsonSurfaceQueries)
  throw new Error('Spherical line and fill support is required');
map.setProjection({ type: 'globe' });
map.addSource('route-data', { type: 'geojson', data: {
  type: 'Feature', id: 7, properties: { name: 'Example route' },
  geometry: { type: 'LineString', coordinates: [[179, 38], [183, 38]] }
}});
map.addLayer({ id: 'route', type: 'line', source: 'route-data', paint: {
  'line-color': '#0080ff', 'line-width': 12
}});
await map.sqs.flush({ render: true });
const point = await map.project([181, 38]);
const hits = await map.queryRenderedFeatures(point, { layers: ['route'] });
console.log(hits);

Complete common script · Complete HTML/CSS/JavaScript. All visibility, paint, order, width, projection, click and destruction handlers use public APIs; controls read actual map state. Copy the whole file with its matching SDK files and serve it over HTTP. This example owns its data and uses no external basemap; external maps still require their applicable credits.

Original longitude/latitude enters spherical projection without Mercator latitude clamping. Polygons retain holes, MultiPolygon and parent collection identity, including polar regions and world copies such as 181°. GeoJSON edges interpolate in the supplied longitude/latitude plane. Cross the dateline with continuous copies (179 to 183) or split geometry; 170 to -170 is not silently converted to a shortest great-circle edge. Curves subdivide against logical-pixel error and clip at spherical visibility boundaries. Line width and the 1-pixel fill-outline-color boundary scale with DPR.

Drawing and queries use the same visible triangles. Point/box queries support selected layers, filters, feature state and topmost order, preserving original properties, complete parent geometry, source/layer instances and historical snapshots. Reordering changes both display and hits; paint changes do not rewrite source properties. A line layer also strokes Polygon geometry from mixed sources. To draw only routes, add filter: ['==', ['geometry-type'], 'LineString'].

This is a 2D style overlay on the earth surface. Arbitrary 3D occlusion, elevated geometry, spherical terrain and symbol/extrusion layers remain separate work. Unsupported paint/layout rejects explicitly: spherical lines currently support line-color, line-width and line-opacity; caps are butt with shared round joins; dashes, gradients and configurable caps/joins remain pending.

Each spherical line/fill draw or query shares 500,000 projection/triangle work items; raw overlays contain at most 100,000 coordinates. Exhaustion fails with RESOURCE_LIMIT as a whole. Existing 1000-item/8 MiB query output and 100,000-display-feature budgets still apply. Narrow data, area or layers before retrying; no silent truncation. Current-frame receipts compare pose, density and geometry, so old content cannot certify new order or paint.

The same 19-assertion script runs in actual one-shot/persistent native sessions, main/strict Worker at DPR1/2 and Linux desktop at DPR2/1.25. Separate model checks cover holes, poles, date-line copies, back-surface visibility and budgets. Actual pixel evidence covers colors, holes, width and order on software GPUs. Windows/macOS, physical mobile devices and formal release remain separate acceptance.

See spherical circles, pointer input and shared-map reference.