UNPKG

@pansy/react-mapbox-gl

Version:

🌍 基于 Mapbox GL 封装的 React 组件库

91 lines (89 loc) 3.2 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getOwnPropSymbols = Object.getOwnPropertySymbols; var __hasOwnProp = Object.prototype.hasOwnProperty; var __propIsEnum = Object.prototype.propertyIsEnumerable; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __spreadValues = (a, b) => { for (var prop in b || (b = {})) if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]); if (__getOwnPropSymbols) for (var prop of __getOwnPropSymbols(b)) { if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]); } return a; }; 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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/components/Source/utils.ts var utils_exports = {}; __export(utils_exports, { createSource: () => createSource, updateSource: () => updateSource }); module.exports = __toCommonJS(utils_exports); var import_assert = require("../../utils/assert"); var import_isStyleLoaded = require("../../utils/isStyleLoaded"); var import_deepEqual = require("../../utils/deepEqual"); function createSource(map, id, props) { if ((0, import_isStyleLoaded.isStyleLoaded)(map)) { const options = __spreadValues({}, props); delete options.id; delete options.children; map.addSource(id, options); return map.getSource(id); } } function updateSource(source, props, prevProps) { (0, import_assert.assert)(props.id === prevProps.id, "source id changed"); (0, import_assert.assert)(props.type === prevProps.type, "source type changed"); let changedKey = ""; let changedKeyCount = 0; for (const key in props) { if (key !== "children" && key !== "id" && // @ts-ignore !(0, import_deepEqual.deepEqual)(prevProps[key], props[key])) { changedKey = key; changedKeyCount++; } } if (!changedKeyCount) { return; } const type = props.type; if (type === "geojson") { source.setData(props.data); } else if (type === "image") { source.updateImage({ url: props.url, coordinates: props.coordinates }); } else if ("setCoordinates" in source && changedKeyCount === 1 && changedKey === "coordinates") { source.setCoordinates(props.coordinates); } else if ("setUrl" in source) { switch (changedKey) { case "url": source.setUrl(props.url); break; case "tiles": source.setTiles(props.tiles); break; default: } } else { console.warn(`Unable to update <Source> prop: ${changedKey}`); } }