← คอมโพเนนต์ทั้งหมด
แผงเลเยอร์
สวิตช์และแถบความโปร่งใสสำหรับทุกกลุ่มเลเยอร์
ตัวอย่างทำงานบนคลังข้อมูลประเทศไทยสาธารณะของ MapScale
ติดตั้ง
npx shadcn@latest add https://mapscale.io/r/layer-panel.jsonวิธีใช้
import { LayerPanel, type LayerPanelLayer } from "@/components/mapscale/layer-panel"
const [layers, setLayers] = useState<LayerPanelLayer[]>([
{ id: "stations", label: "Stations", layerIds: ["stations"], visible: true, opacity: 1, swatch: "#e11d48" },
])
<Map>
<GeoJSONLayer id="stations" type="circle" data={stations} paint={{ "circle-radius": 6 }} />
<LayerPanel layers={layers} onChange={setLayers} />
</Map>พร็อพ
| พร็อพ | ชนิด | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|---|
| layers | LayerPanelLayer[] | - | Rows of { id, label, layerIds, visible, opacity, swatch }. |
| onChange | (layers) => void | - | Receives the next array of rows. Keep it in state. |
| applyToMap | boolean | true | Set false to drive the map yourself from onChange. |
| title | string | "Layers" | Heading of the panel. |
คีย์
แผนที่ การค้นหาที่อยู่ และรายละเอียดสถานที่ใช้คีย์ pk_ ที่ปลอดภัยบนเบราว์เซอร์ ส่วนเส้นทางและ isochrone ต้องใช้คีย์ลับ sk_ จึงต้องผ่านเส้นทางพร็อกซีบนเซิร์ฟเวอร์ของแอปคุณ