@djangocfg/widget-map

中文文档
0.1.36发布于 2026/11/11MITTypeScriptES Module近 30 天下载 4803

Interactive maps on MapLibre GL: markers, clustered GeoJSON, layer factories, key-free basemaps, terrain, geocoding and measuring behind one provider

原始使用文档
文档目录7 节
  1. Install
  2. Quick start
  3. Public exports — @djangocfg/widget-map
  4. Docs
  5. The two entries
  6. Verify
  7. Related

Map

Interactive maps for @djangocfg/widget-map, built on MapLibre GL via react-map-gl — markers, clustered GeoJSON, popups, layer factories, free OpenFreeMap / PMTiles basemaps, a runtime basemap switcher, 3D terrain, address/place autocomplete (geocoder), a compass, click-to-measure, draggable markers, custom marker icons, and an opt-in locate-me (GPS) chip, all behind a small Provider/Context surface.

Bundle warning. MapLibre GL is heavy (~800 KB gzipped). The @djangocfg/widget-map entry is already the lazy one — LazyMapContainer defers the MapLibre chunk until it mounts. All components are 'use client'; never render them on the Next.js server.

Install

pnpm add @djangocfg/widget-map @djangocfg/ui-core

Quick start

import { LazyMapContainer, MapMarker } from '@djangocfg/widget-map';

<div className="h-96 rounded-xl overflow-hidden">
  <LazyMapContainer
    initialViewport={{ latitude: 25.08, longitude: 55.14, zoom: 13 }}
    mapStyle="light"
  >
    <MapMarker
      marker={{ id: 'home', latitude: 25.08, longitude: 55.14 }}
      color="#10b981"
      size={32}
    />
  </LazyMapContainer>
</div>

The container provides its own MapProvider. To use the map context from a sibling (e.g. a button calling flyTo), wrap your tree in <MapProvider> and render <MapView> inside it. See container.

Public exports — @djangocfg/widget-map

The package subpath resolves to the lazy entry. It surfaces:

Components — LazyMapContainer, LazyMapView (code-split), MapView-via-MapContainer types, plus the light primitives: MapMarker, MapPopup, MapCluster, MapSource, MapLayer, MapControls, CustomOverlay, MapLegend, LayerSwitcher, MeasureControl, DraggableMarkers, GeocoderInput, GeocoderControl, CompassChip, MarkerCard, MapMarkers.

Context — MapProvider, useMapContext, MapContext.

Styles — MAP_STYLES, getMapStyle, MAP_STYLE_LABELS, KEY_FREE_STYLES, resolveBasemapOptions, and the free terrain DEM source TERRAIN_DEM / TERRAIN_DEM_URL.

PMTiles — addPMTilesProtocol, pmtilesSourceUrl (self-hosted / offline basemaps).

Geocoder — photonResolve (default key-free Photon resolver), cameraForResult (smart-zoom helper), and types GeocodeResult, GeocodeKind, ResolveGeocode. See geocoder.

Types — MapContainerProps, GeolocateOptions, GeolocatePosition, MapMarkerProps, MapPopupProps, MapClusterProps, MapSourceProps, MapLayerProps, MapControlsProps, MeasureControlProps, DraggableMarkersProps, DraggablePoint, GeocoderInputProps, GeocoderControlProps, CompassChipProps, MapProviderProps, MapViewport, MapStyleKey, MarkerData, plus hook types GeolocationFix, GeolocationStatus, UseGeolocationOptions, UseGeolocationResult, UseGeocoderOptions, UseGeocoderResult, UseCompassResult, UseTerrainOptions, UseMeasureResult, MeasureMode, MapImage, UseMapImagesResult, UseDraggableMarkersOptions, UseDraggableMarkersResult, DraggableMarkerHandlers, plus the marker-card types MarkerCardProps, MapMarkersProps, MarkerWithCard, MarkerCardInfo (the card data shape), MarkerCardAction, MarkerCardData, MarkerCardActionData, UseMarkerCardResult.

Hooks — useMap, useMapControl, useMarkers, useMapEvents, useMapViewport, useMapLayers, useControl, useSpiderfy (+ UseSpiderfyOptions / UseSpiderfyResult types), useMarkerCard (single-open marker-card selection state), the feature hooks useCompass, useTerrain, useMeasure, useMapImages, useDraggableMarkers, useGeocoder, and the map-independent useGeolocation (live browser position for custom "where am I" UI; see hooks). useMapScrollProtection / useMapTouchMode are also exported — they power scrollProtection, which wires them for you.

Layer factories — createClusterLayers, createPointLayer, createHeatmapLayer, createPolygonLayer, createPolygonOutlineLayer, createHighlightLayer, createLineLayer, createRouteLayers, createDashedLineLayer, createAnimatedLineLayer, createSymbolLayer.

Geometry utils — calculateBounds, calculateCenter, calculateDistance, isPointInBounds, expandBounds, toGeoJSON, fromGeoJSON, createPoint, createPolygon, createLineString, createFeatureCollection.

Spiderfy utils — offsetOverlappingMarkers, getSpiderfyPositions, groupOverlappingMarkers, hasOverlappingMarkers, getOverlapStats.

Docs

DocCovers
container.mdMapContainer / MapView — full props, control toolbar (search · terrain · compass · locate-me / GPS chips), scroll protection & mobile, fullscreen dialog.
basemaps.mdMap styles, the runtime basemap switcher, OpenFreeMap, satellite/keys, PMTiles, 3D terrain (free DEM).
markers-popups.mdMapMarker, MapPopup, MapCluster, marker info-cards (MarkerCard / MapMarkers / useMarkerCard), draggable markers, overlapping points / spiderfy.
layers.mdMapSource / MapLayer, the layer factories, custom marker icons (symbol layer), geometry utilities.
geocoder.mdAddress/place autocomplete — GeocoderInput / GeocoderControl, the toolbar search chip, photonResolve, smart zoom (cameraForResult), useGeocoder.
hooks.mdEvery hook, with an example.
advanced.mdCustomOverlay, MapLegend, LayerSwitcher, MeasureControl, the DrawControl recipe, lazy loading, SSR.
stories.mdThe Storybook stories list.

The two entries

ImportContainerFor
@djangocfg/widget-mapbehind React.lazyeverything — this is the default for a reason
@djangocfg/widget-map/eagera static edgethe map IS the page and a placeholder reads as a flash

eager is derived from the root (export * from './index' plus the static container), so the two surfaces cannot drift; src/entries.test.ts walks the static import graph and holds the split itself.

Importing both in one app defeats the split — the static edge pulls MapLibre into the entry chunk whatever the other half does.

Verify

pnpm --filter @djangocfg/widget-map check-types test

版本与发布记录

@djangocfg/widget-map 共发布 32 个版本,首次发布于 2026/09/09;过去 12 个月发布了 32 个版本。

版本发布日期距今
0.1.36latest2026/11/111 天前
0.1.352026/11/111 天前
0.1.342026/11/102 天前
0.1.332026/11/102 天前
0.1.322026/11/092 天前
0.1.312026/11/092 天前

关于 @djangocfg/widget-map 的常见问题

@djangocfg/widget-map 是什么?

Interactive maps on MapLibre GL: markers, clustered GeoJSON, layer factories, key-free basemaps, terrain, geocoding and measuring behind one provider

如何安装 @djangocfg/widget-map?

在项目目录运行 npm install @djangocfg/widget-map,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(^19.0.0)、react-dom(^19.0.0)、lucide-react(^1.68.0)、@djangocfg/ui-core(^2.1.648)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@djangocfg/widget-map 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@djangocfg/widget-map 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@djangocfg/widget-map 可以商用吗?

@djangocfg/widget-map 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@djangocfg/widget-map 的下载量有多少?

根据 npm 官方下载统计,@djangocfg/widget-map 在 2026/10/13 – 2026/11/11 这 30 天内被下载 4,803 次,日均约 160 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@djangocfg/widget-map 还在维护吗?

最新版本 0.1.36 发布于 2026/11/11(1 天前);至今共发布 32 个版本,其中过去 12 个月发布了 32 个;首次发布于 2026/09/09。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。