admin/components/map/mapirMapFactory.ts
alisaza e1eaf5eff5 feat: initial ghabilee-admin backoffice app
Extract admin dashboard from ghabilee-frontend2 into a dedicated Next.js
app for backoffice.ghabilee.ir (no SEO indexing / Clarity).
2026-09-05 13:12:59 +03:30

41 lines
901 B
TypeScript

'use client'
import type { ComponentType } from 'react'
import Mapir from 'mapir-react-component'
import 'mapir-react-component/dist/index.css'
/** Default Map.ir vector style (mapir-react, no wrapper) */
export const MAPIR_STYLE_URL = 'https://map.ir/vector/styles/main/mapir-xyz-style.json'
const mapCache = new Map<string, ComponentType<Record<string, unknown>>>()
export function getMapirMapComponent(apiKey: string): ComponentType<Record<string, unknown>> {
const key = apiKey.trim()
if (!key) {
throw new Error('Map API key is empty')
}
const hit = mapCache.get(key)
if (hit) {
return hit
}
const MapComponent = Mapir.setToken({
transformRequest(url: string) {
return {
url,
headers: {
'x-api-key': key,
'Mapir-SDK': 'reactjs',
},
}
},
})
mapCache.set(key, MapComponent)
return MapComponent
}