@facilitronworks/react-native-windows-maps

中文文档
0.1.0-pre.0发布于 2026/08/25MITTypeScriptCommonJS零依赖近 30 天下载 4244

The app-agnostic half of a react-native-windows map: Web Mercator projection maths, and a builder for the maplibre-gl page that renders inside a WebView2 island. Zero runtime dependencies.

原始使用文档
文档目录7 节
  1. What this is not
  2. Usage
  3. Bridge protocol
  4. Markers render in the page, not over it
  5. maplibre-gl is pinned by version and SRI
  6. Platform
  7. License

@facilitronworks/react-native-windows-maps

The app-agnostic half of a react-native-windows map surface: Web Mercator projection maths, and a builder for the maplibre-gl HTML page that renders inside a WebView2 island.

Zero runtime dependencies. Both modules are pure TypeScript with no imports.

What this is not

This package deliberately does not ship a <MapView> component or any basemap style resolution.

Style resolution reads EXPO_PUBLIC_* environment variables, and babel-preset-expo only inlines those for files outside node_modules. A resolver living in this package would silently read '' in every build: the map would fall back to raw OSM tiles and the dark-mode toggle would inject a byte-identical style, doing nothing, with no error and no failing test. The host app owns styling and passes the resolved style in.

Usage

import {
  buildMapPage,
  projectToViewport,
  regionToZoom,
  viewportToRegion,
  type LatLng,
  type Region,
} from '@facilitronworks/react-native-windows-maps';

buildMapPage(options) returns a complete HTML document. Render it in a WebView that injects window.ReactNativeWebView.postMessage before content load.

Bridge protocol

page → host, via window.ReactNativeWebView.postMessage:

messagemeaning
{type:'ready'}maplibre constructed, first style loaded
{type:'viewport', center, zoom, css}on every move and on resize
{type:'press', coordinate}single click on the map surface
{type:'markerPress', id}an in-page marker element was clicked
{type:'error', message}script / style / tile failure

host → page, via injectJavaScript against window.__worksMap:

callmeaning
setRegion({center, zoom}, durationMs)camera move (0 = jump)
setStyle(styleJsonOrUrl)appearance change
setMarkers(list)replace the in-page marker layer

Markers render in the page, not over it

On react-native-windows the WebView2 island composites above all react-native content within its bounds, regardless of sibling order or zIndex (verified against three independent layering strategies). An RN overlay can therefore never be seen. The host still computes clusters and owns every handler; the page only draws the bubbles it is handed via setMarkers and reports presses back. Each entry is plain data — {id, latitude, longitude, kind:'cluster'|'pin', label, bg, fg, border, size} — themed by the host.

maplibre-gl is pinned by version and SRI

The page loads maplibre-gl from unpkg pinned by version and by sha384 subresource integrity. MAPLIBRE_JS_SRI / MAPLIBRE_CSS_SRI are the hashes of the exact artifacts in [email protected]. A tampered or substituted file fails the check, the script does not execute, and the page reports {type:'error'} so the host can fall back.

maplibre-gl is declared as an optional peer dependency so a host on a different version gets an install-time signal. If you bump it, the two SRI constants must be regenerated in the same change or the map loads nothing.

Platform

Correct only under the windows platform, where Metro redirects react-native to react-native-windows.

License

MIT

版本与发布记录

@facilitronworks/react-native-windows-maps 共发布 1 个版本,首次发布于 2026/08/25;过去 12 个月发布了 1 个版本。

版本发布日期距今
0.1.0-pre.0latest2026/08/252 个月前

关于 @facilitronworks/react-native-windows-maps 的常见问题

@facilitronworks/react-native-windows-maps 是什么?

The app-agnostic half of a react-native-windows map: Web Mercator projection maths, and a builder for the maplibre-gl page that renders inside a WebView2 island. Zero runtime dependencies.

如何安装 @facilitronworks/react-native-windows-maps?

在项目目录运行 npm install @facilitronworks/react-native-windows-maps,或使用 pnpm add / yarn add / bun add。

@facilitronworks/react-native-windows-maps 支持 TypeScript 吗?

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

@facilitronworks/react-native-windows-maps 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@facilitronworks/react-native-windows-maps 可以商用吗?

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

@facilitronworks/react-native-windows-maps 的下载量有多少?

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

@facilitronworks/react-native-windows-maps 还在维护吗?

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