gistda-sphere-react

SphereMap

The map container component

Click, zoom, or drag the map to see events
No events yet
<SphereMap
  center={{ lon: 100.5018, lat: 13.7563 }}
  style={{ width: "100%", height: "300px" }}
  zoom={10}
  onClick={(e) => {
    console.log(`Clicked at ${e.lat.toFixed(4)}, ${e.lon.toFixed(4)}`);
  }}
  onLocation={(e) => {
    console.log(`Moved to ${e.lat.toFixed(4)}, ${e.lon.toFixed(4)}`);
  }}
  onZoom={(e) => {
    console.log(`Zoomed to level ${e.toFixed(2)}`);
  }}
>
  {/* Markers, Polygons, etc. */}
</SphereMap>

Props

PropTypeRequiredDefaultDescription
centerLocationNoBangkok ({ lon: 100.49, lat: 13.72 })Initial map center coordinates
zoomnumberNo7Initial zoom level (1-22)
zoomRangeRangeNoAll zoom levelsAllowed zoom range ({ min, max })
language"th" | "en"No"th"Map language: "th" (Thai) or "en" (English)
inputbooleanNotrueAllow user input (click, drag, scroll)
lastViewbooleanNofalseRestore last location/zoom from local storage
ui"Full" | "Mobile" | "None"NoFit screen sizeUI component mode
filterFilterTypeNo"None"Initial color filter
rotatenumberNo0Initial rotation angle in degrees
pitchnumberNo0Initial pitch angle in degrees
styleCSSPropertiesNo-CSS styles for the map container
classNamestringNo-CSS class for the map container
idstringNo-HTML id attribute
refRef<SphereMapRef>No-Ref for imperative map control
childrenReactNodeNo-Overlay components

Event callbacks

PropTypeDescription
onReady(map: SphereMapInstance) => voidMap initialized and ready
onClick(location: Location) => voidMap clicked
onDoubleClick(location: Location) => voidMap double-clicked
onZoom(zoom: number) => voidZoom level changed
onLocation(location: Location) => voidMap center changed
onRotate(angle: number) => voidRotation changed
onPitch(angle: number) => voidPitch changed
onDrag() => voidUser started dragging
onDrop() => voidUser stopped dragging
onMouseMove(location: Location) => voidMouse moved over map
onIdle() => voidMap is idle
onError(error: Error) => voidAn error occurred

The map container must have an explicit height. Without it, the <div> collapses to 0px.

UI modes

The ui prop controls which built-in UI elements are shown:

ModeDescription
"Full"All controls: zoom bar, d-pad, geolocation, toolbar, layer selector, fullscreen, scale
"Mobile"Compact controls optimized for small screens
"None"No built-in UI controls

By default, the mode is automatically chosen based on screen size.

Available UI controls

ControlDescription
DPadDirectional navigation pad
ZoombarZoom in/out slider
GeolocationNavigate to user's location
ToolbarDrawing tools (desktop only)
LayerSelectorBase layer picker
FullscreenToggle fullscreen (desktop only)
CrosshairCenter crosshair indicator
ScaleDistance scale bar

UI control visibility can be toggled via the raw map instance:

const { map } = useMap();

map?.Ui.DPad.visible(false);    // hide d-pad
map?.Ui.Scale.visible(true);    // show scale bar
map?.Ui.Toolbar.visible(false); // hide toolbar

On this page