nicecode-v2/packages/map/lib/MapBox.js
2024-03-22 17:39:53 +08:00

132 lines
4.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/MapBox.tsx
var MapBox_exports = {};
__export(MapBox_exports, {
MAP_CENTER: () => MAP_CENTER,
MapConfig: () => MapConfig,
default: () => MapBox_default,
mapboxAccessToken: () => mapboxAccessToken
});
module.exports = __toCommonJS(MapBox_exports);
var import_mapbox_gl = require("mapbox-gl/dist/mapbox-gl.css");
var import_react_map_gl = __toESM(require("react-map-gl"));
var import_index = require("./index.less");
var mapboxAccessToken = "pk.eyJ1IjoiZGluZ2xpMTIzIiwiYSI6ImNra204ODhjczBobTgyeHJ6MmJpZHMxNWgifQ.NbKrXh_hb2gvjr5CEMDnyQ";
var MAP_CENTER = {
longitude: 120.2667694313269,
latitude: 30.180942826533766
};
var MapUrl = "http://10.0.0.120:30003/map";
var MapConfig = {
mapboxAccessToken,
maxZoom: 18,
minZoom: 4,
dragRotate: false,
mapStyle: {
version: 8,
name: "Mapbox Streets",
// sprite: `${location.origin}/mapbox/sprite`, // 地图图标
glyphs: "mapbox://fonts/mapbox/{fontstack}/{range}.pbf",
// 字体
sources: {
//数据源
"osm-tiles": {
type: "raster",
//栅格切片。vector:矢量切片
// Z-瓦片层级一般支持0-18级越大代表越清晰
// X-瓦片列号从西向东0->360依次012……
// Y-瓦片行号从北向南有些也可能是从南向北依次012……
tiles: [`${MapUrl}/api/tilesets/mapfile/{z}/{x}/{y}.png`],
//在线地址先写死120
tileSize: 256
//切片的最小展示尺寸(可选,单位:像素,默认值为 512即 1024/2
}
},
layers: [
// 图层。图层指定了如何渲染数据源提供的数据
{
id: "zhstLayer",
//唯一id
type: "raster",
//类型 栅格。circlesymbolline...
source: "osm-tiles",
// 'source-layer': 'osmtiles',//数据源必须是type:vector
minZoom: 4,
//最小层级
maxZoom: 17,
//最大层级
renderingMode: "2d"
}
]
}
};
var MapBox = (props) => {
const {
style = {},
children,
mapRef,
onLoad,
defaultMode,
onDrawCreate,
setIsReady,
...others
} = props || {};
let mapCneter = MAP_CENTER;
return (
//@ts-ignore
/* @__PURE__ */ React.createElement(
import_react_map_gl.default,
{
ref: (e) => {
if (mapRef) {
mapRef.current = e;
}
},
onLoad: (e) => {
setIsReady && setIsReady(true);
onLoad && onLoad(e);
},
style: { width: "100%", height: 600, ...style },
...MapConfig,
initialViewState: { ...mapCneter, zoom: 10 },
...others
},
children
)
);
};
var MapBox_default = MapBox;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
MAP_CENTER,
MapConfig,
mapboxAccessToken
});