useTags
Add, replace and remove POI tag layers from code
useTags manages POI tag layers imperatively. It works inside SphereMap and anywhere else under SphereProvider. For tags that follow your state, the <Tag> component is usually simpler.
import { useTags } from "gistda-sphere-react";
function FoodToggle() {
const { add, remove, list } = useTags();
const shown = list().includes("อาหารไทย");
return (
<button onClick={() => (shown ? remove("อาหารไทย") : add("อาหารไทย"))}>
{shown ? "Hide" : "Show"} Thai restaurants
</button>
);
}Return value
| Method | Description |
|---|---|
add(tag, options?) | Add a tag layer, keeping the others. tag is a tag name (several joined with |), or a function that returns POIs for a tile. |
set(tag, options?) | Replace all tag layers with this one. |
remove(tag) | Remove a tag layer. Names joined with | are removed one by one. |
clear() | Remove all tag layers. |
list() / size() | Names / number of the tag layers on the map. |
enablePopup(state) / isPopupEnabled() | Popups when a POI is clicked. |
setLanguage(language) / getLanguage() | Language of POI names. |
isReady | true once the map is ready. |
options are the same as <Tag>'s props: visibleRange, label, icon, area, type, source and so on.
Your own POIs per tile
Pass a function instead of a name to supply POIs yourself. Sphere calls it for every map tile:
import { useTags } from "gistda-sphere-react";
const { add } = useTags();
add((tile) =>
myStores
.filter((store) => isInTile(store, tile))
.map((store) => ({ lat: store.lat, lon: store.lon, name: store.name }))
);Here, myStores is your data and isInTile your own check of whether a store falls inside the tile, which has x, y and z (zoom).
Tag names
Tags are identified by Thai names, such as "ธนาคาร/สถาบันการเงิน" (banks) or "โรงพยาบาล" (hospitals). useTagCategories loads the full list with English labels, and TAG_CATEGORIES is a smaller built-in list that needs no request.