gistda-sphere-react

ObjectOverlay

Draw a province, district, landmark or POI from Sphere's data by its ID

<ObjectOverlay> loads a predefined object from Sphere, such as an administrative area or a place, and draws it: areas as polygons, points as markers. IDs come from search results (the id of each result).

import { ObjectOverlay, SphereMap } from "gistda-sphere-react";

<SphereMap style={{ height: 400 }}>
  <ObjectOverlay
    id="A10000000"               // Bangkok
    fitBounds
    fillColor="rgba(59, 130, 246, 0.15)"
    lineColor="rgb(37, 99, 235)"
    label
    onLoad={(data, overlays) => console.log("Loaded", data)}
    onError={(error) => setMessage(error.message)}
  />
</SphereMap>

The shorter samples below leave out <SphereMap>, but every overlay goes inside one.

Objects come from Sphere's POI details service (poi/get). If your API key doesn't have that service, Sphere draws nothing and reports nothing. Use onError to notice: it's called when the object hasn't loaded within timeout.

Props

PropTypeDefaultDescription
idstringrequiredObject ID, e.g. "A10000000" (Bangkok) or a POI ID like "P00000046".
datasetstringSphere's defaultDataset to load the object from.
fitBoundsboolean | FitBoundsOptions–Fit the map to the object once it loads.
labelstring | boolean–Label text, or true to label the object with its name.
iconIcon–Marker icon for point objects.
onLoad(data, overlays) => void–The object loaded. overlays are the shapes created for it.
onError(error) => void–The object didn't load within timeout.
timeoutnumber15000Milliseconds to wait before onError. 0 turns it off.
onClick(overlay, location) => void–One of the object's shapes was clicked.
simplifynumber–Simplification tolerance, from about 0.00005 (fine) to 0.001 (rough).
combineboolean–Merge the object's parts into one shape.
ignorefragmentboolean–Skip small fragments.
refRef<ObjectOverlayRef>–getObject() and getOverlays().

It also takes the shape style props (fillColor, lineColor, lineWidth, lineStyle…).

Area IDs

Area IDs start with A followed by the province, district and subdistrict codes. The province code is the same as in Thai postal and census codes:

IDArea
A10000000Bangkok
A50000000Chiang Mai
A83000000Phuket
A50010000Mueang Chiang Mai district

To find an ID, search for the place: useSearch().search("เชียงใหม่") returns results with their id.

On this page