Custom markers and popups
React components as marker icons and popup content, and custom popups for POIs
Markers and popups can render any React content, with your styles, state and event handlers.
import { Marker, SphereMap } from "gistda-sphere-react";
const price = {
background: "#7c3aed",
borderRadius: 999,
color: "white",
display: "inline-block",
fontSize: 12,
fontWeight: 600,
padding: "2px 8px",
whiteSpace: "nowrap",
};
<SphereMap center={{ lon: 100.5018, lat: 13.7563 }} style={{ height: 320 }} zoom={12}>
<Marker position={{ lon: 100.5018, lat: 13.7563 }} title="Democracy Monument">
<span style={price}>฿ 1,290</span>
</Marker>
<Marker position={{ lon: 100.53, lat: 13.745 }} title="Siam">
<span style={price}>฿ 2,450</span>
</Marker>
</SphereMap>React marker icons
import { type Location, Marker } from "gistda-sphere-react";
import { useState } from "react";
interface Hotel {
id: string;
location: Location;
name: string;
photo: string;
price: number;
rating: number;
reviews: number;
}
function PriceMarker({ hotel }: { hotel: Hotel }) {
const [hovered, setHovered] = useState(false);
return (
<Marker
position={hotel.location}
title={hotel.name}
onHover={() => setHovered(true)}
onLeave={() => setHovered(false)}
options={{ anchor: "bottom" }}
>
<span className={hovered ? "price price--active" : "price"}>฿ {hotel.price}</span>
</Marker>
);
}React popups
import { Marker } from "gistda-sphere-react";
<Marker
position={hotel.location}
title={hotel.name}
popupContent={
<div className="w-56">
<img src={hotel.photo} alt="" className="rounded" />
<p>{hotel.rating} ★ · {hotel.reviews} reviews</p>
<button onClick={() => book(hotel.id)}>Book</button>
</div>
}
/>Shapes take popupContent too:
import { Polygon } from "gistda-sphere-react";
<Polygon positions={district.outline} title={district.name} popupContent={<DistrictStats id={district.id} />} />Popups for Sphere's own POIs
Tag layers and search results open Sphere's popups. Change what they show on SphereProvider:
import { SphereProvider } from "gistda-sphere-react";
<SphereProvider
apiKey={apiKey}
formatPoi={(poi) => {
const element = document.createElement("div");
const name = document.createElement("strong");
name.textContent = poi.name;
const address = document.createElement("p");
address.textContent = poi.address ?? "";
element.append(name, address);
return element;
}}
>For full control, return popup options from poiPopupOptions(source, id, name, language), for example to load details from your own API. See SphereProvider.