UNPKG

@neshan-maps-platform/react-openlayers

Version:

A react map component wrapping neshan openlayers map.

661 lines (660 loc) 18.7 kB
import ge, { forwardRef as Pe, useRef as te, useState as re, useImperativeHandle as Re, useEffect as we } from "react"; import { Map as Te, View as be } from "@neshan-maps-platform/ol"; var G = { exports: {} }, O = {}; /** * @license React * react-jsx-runtime.production.js * * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ var ne; function ve() { if (ne) return O; ne = 1; var r = Symbol.for("react.transitional.element"), t = Symbol.for("react.fragment"); function n(s, a, i) { var h = null; if (i !== void 0 && (h = "" + i), a.key !== void 0 && (h = "" + a.key), "key" in a) { i = {}; for (var g in a) g !== "key" && (i[g] = a[g]); } else i = a; return a = i.ref, { $$typeof: r, type: s, key: h, ref: a !== void 0 ? a : null, props: i }; } return O.Fragment = t, O.jsx = n, O.jsxs = n, O; } var A = {}; /** * @license React * react-jsx-runtime.development.js * * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ var oe; function Se() { return oe || (oe = 1, process.env.NODE_ENV !== "production" && function() { function r(e) { if (e == null) return null; if (typeof e == "function") return e.$$typeof === me ? null : e.displayName || e.name || null; if (typeof e == "string") return e; switch (e) { case v: return "Fragment"; case Y: return "Profiler"; case S: return "StrictMode"; case W: return "Suspense"; case c: return "SuspenseList"; case Ee: return "Activity"; } if (typeof e == "object") switch (typeof e.tag == "number" && console.error( "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue." ), e.$$typeof) { case N: return "Portal"; case U: return (e.displayName || "Context") + ".Provider"; case j: return (e._context.displayName || "Context") + ".Consumer"; case D: var o = e.render; return e = e.displayName, e || (e = o.displayName || o.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e; case I: return o = e.displayName || null, o !== null ? o : r(e.type) || "Memo"; case x: o = e._payload, e = e._init; try { return r(e(o)); } catch { } } return null; } function t(e) { return "" + e; } function n(e) { try { t(e); var o = !1; } catch { o = !0; } if (o) { o = console; var l = o.error, u = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object"; return l.call( o, "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.", u ), t(e); } } function s(e) { if (e === v) return "<>"; if (typeof e == "object" && e !== null && e.$$typeof === x) return "<...>"; try { var o = r(e); return o ? "<" + o + ">" : "<...>"; } catch { return "<...>"; } } function a() { var e = X.A; return e === null ? null : e.getOwner(); } function i() { return Error("react-stack-top-frame"); } function h(e) { if (B.call(e, "key")) { var o = Object.getOwnPropertyDescriptor(e, "key").get; if (o && o.isReactWarning) return !1; } return e.key !== void 0; } function g(e, o) { function l() { H || (H = !0, console.error( "%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)", o )); } l.isReactWarning = !0, Object.defineProperty(e, "key", { get: l, configurable: !0 }); } function p() { var e = r(this.type); return Z[e] || (Z[e] = !0, console.error( "Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release." )), e = this.props.ref, e !== void 0 ? e : null; } function $(e, o, l, u, _, E, q, J) { return l = E.ref, e = { $$typeof: m, type: e, key: o, props: E, _owner: _ }, (l !== void 0 ? l : null) !== null ? Object.defineProperty(e, "ref", { enumerable: !1, get: p }) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", { configurable: !1, enumerable: !1, writable: !0, value: 0 }), Object.defineProperty(e, "_debugInfo", { configurable: !1, enumerable: !1, writable: !0, value: null }), Object.defineProperty(e, "_debugStack", { configurable: !1, enumerable: !1, writable: !0, value: q }), Object.defineProperty(e, "_debugTask", { configurable: !1, enumerable: !1, writable: !0, value: J }), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e; } function k(e, o, l, u, _, E, q, J) { var f = o.children; if (f !== void 0) if (u) if (_e(f)) { for (u = 0; u < f.length; u++) C(f[u]); Object.freeze && Object.freeze(f); } else console.error( "React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead." ); else C(f); if (B.call(o, "key")) { f = r(e); var R = Object.keys(o).filter(function(he) { return he !== "key"; }); u = 0 < R.length ? "{key: someKey, " + R.join(": ..., ") + ": ...}" : "{key: someKey}", ee[f + u] || (R = 0 < R.length ? "{" + R.join(": ..., ") + ": ...}" : "{}", console.error( `A props object containing a "key" prop is being spread into JSX: let props = %s; <%s {...props} /> React keys must be passed directly to JSX without using spread: let props = %s; <%s key={someKey} {...props} />`, u, f, R, f ), ee[f + u] = !0); } if (f = null, l !== void 0 && (n(l), f = "" + l), h(o) && (n(o.key), f = "" + o.key), "key" in o) { l = {}; for (var V in o) V !== "key" && (l[V] = o[V]); } else l = o; return f && g( l, typeof e == "function" ? e.displayName || e.name || "Unknown" : e ), $( e, f, E, _, a(), l, q, J ); } function C(e) { typeof e == "object" && e !== null && e.$$typeof === m && e._store && (e._store.validated = 1); } var d = ge, m = Symbol.for("react.transitional.element"), N = Symbol.for("react.portal"), v = Symbol.for("react.fragment"), S = Symbol.for("react.strict_mode"), Y = Symbol.for("react.profiler"), j = Symbol.for("react.consumer"), U = Symbol.for("react.context"), D = Symbol.for("react.forward_ref"), W = Symbol.for("react.suspense"), c = Symbol.for("react.suspense_list"), I = Symbol.for("react.memo"), x = Symbol.for("react.lazy"), Ee = Symbol.for("react.activity"), me = Symbol.for("react.client.reference"), X = d.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, B = Object.prototype.hasOwnProperty, _e = Array.isArray, L = console.createTask ? console.createTask : function() { return null; }; d = { "react-stack-bottom-frame": function(e) { return e(); } }; var H, Z = {}, Q = d["react-stack-bottom-frame"].bind( d, i )(), K = L(s(i)), ee = {}; A.Fragment = v, A.jsx = function(e, o, l, u, _) { var E = 1e4 > X.recentlyCreatedOwnerStacks++; return k( e, o, l, !1, u, _, E ? Error("react-stack-top-frame") : Q, E ? L(s(e)) : K ); }, A.jsxs = function(e, o, l, u, _) { var E = 1e4 > X.recentlyCreatedOwnerStacks++; return k( e, o, l, !0, u, _, E ? Error("react-stack-top-frame") : Q, E ? L(s(e)) : K ); }; }()), A; } var ae; function xe() { return ae || (ae = 1, process.env.NODE_ENV === "production" ? G.exports = ve() : G.exports = Se()), G.exports; } var Oe = xe(); const Ae = "_map_1tyvt_2", ye = { map: Ae }, pe = { // use the radius of the Normal sphere radians: 6370997 / (2 * Math.PI), degrees: 2 * Math.PI * 6370997 / 360, ft: 0.3048, m: 1, "us-ft": 1200 / 3937 }; class fe { /** * @param {Options} options Projection options. */ constructor(t) { this.code_ = t.code, this.units_ = /** @type {import("./Units.js").Units} */ t.units, this.extent_ = t.extent !== void 0 ? t.extent : null, this.worldExtent_ = t.worldExtent !== void 0 ? t.worldExtent : null, this.axisOrientation_ = t.axisOrientation !== void 0 ? t.axisOrientation : "enu", this.global_ = t.global !== void 0 ? t.global : !1, this.canWrapX_ = !!(this.global_ && this.extent_), this.getPointResolutionFunc_ = t.getPointResolution, this.defaultTileGrid_ = null, this.metersPerUnit_ = t.metersPerUnit; } /** * @return {boolean} The projection is suitable for wrapping the x-axis */ canWrapX() { return this.canWrapX_; } /** * Get the code for this projection, e.g. 'EPSG:4326'. * @return {string} Code. * @api */ getCode() { return this.code_; } /** * Get the validity extent for this projection. * @return {import("../extent.js").Extent} Extent. * @api */ getExtent() { return this.extent_; } /** * Get the units of this projection. * @return {import("./Units.js").Units} Units. * @api */ getUnits() { return this.units_; } /** * Get the amount of meters per unit of this projection. If the projection is * not configured with `metersPerUnit` or a units identifier, the return is * `undefined`. * @return {number|undefined} Meters. * @api */ getMetersPerUnit() { return this.metersPerUnit_ || pe[this.units_]; } /** * Get the world extent for this projection. * @return {import("../extent.js").Extent} Extent. * @api */ getWorldExtent() { return this.worldExtent_; } /** * Get the axis orientation of this projection. * Example values are: * enu - the default easting, northing, elevation. * neu - northing, easting, up - useful for "lat/long" geographic coordinates, * or south orientated transverse mercator. * wnu - westing, northing, up - some planetary coordinate systems have * "west positive" coordinate systems * @return {string} Axis orientation. * @api */ getAxisOrientation() { return this.axisOrientation_; } /** * Is this projection a global projection which spans the whole world? * @return {boolean} Whether the projection is global. * @api */ isGlobal() { return this.global_; } /** * Set if the projection is a global projection which spans the whole world * @param {boolean} global Whether the projection is global. * @api */ setGlobal(t) { this.global_ = t, this.canWrapX_ = !!(t && this.extent_); } /** * @return {import("../tilegrid/TileGrid.js").default} The default tile grid. */ getDefaultTileGrid() { return this.defaultTileGrid_; } /** * @param {import("../tilegrid/TileGrid.js").default} tileGrid The default tile grid. */ setDefaultTileGrid(t) { this.defaultTileGrid_ = t; } /** * Set the validity extent for this projection. * @param {import("../extent.js").Extent} extent Extent. * @api */ setExtent(t) { this.extent_ = t, this.canWrapX_ = !!(this.global_ && t); } /** * Set the world extent for this projection. * @param {import("../extent.js").Extent} worldExtent World extent * [minlon, minlat, maxlon, maxlat]. * @api */ setWorldExtent(t) { this.worldExtent_ = t; } /** * Set the getPointResolution function (see {@link module:ol/proj.getPointResolution} * for this projection. * @param {function(number, import("../coordinate.js").Coordinate):number} func Function * @api */ setGetPointResolution(t) { this.getPointResolutionFunc_ = t; } /** * Get the custom point resolution function for this projection (if set). * @return {function(number, import("../coordinate.js").Coordinate):number|undefined} The custom point * resolution function (if set). */ getPointResolutionFunc() { return this.getPointResolutionFunc_; } } const y = 6378137, T = Math.PI * y, ke = [-T, -T, T, T], Ce = [-180, -85, 180, 85], M = y * Math.log(Math.tan(Math.PI / 2)); class w extends fe { /** * @param {string} code Code. */ constructor(t) { super({ code: t, units: "m", extent: ke, global: !0, worldExtent: Ce, getPointResolution: function(n, s) { return n / Math.cosh(s[1] / y); } }); } } const se = [ new w("EPSG:3857"), new w("EPSG:102100"), new w("EPSG:102113"), new w("EPSG:900913"), new w("http://www.opengis.net/def/crs/EPSG/0/3857"), new w("http://www.opengis.net/gml/srs/epsg.xml#3857") ]; function Ne(r, t, n) { const s = r.length; n = n > 1 ? n : 2, t === void 0 && (n > 2 ? t = r.slice() : t = new Array(s)); for (let a = 0; a < s; a += n) { t[a] = T * r[a] / 180; let i = y * Math.log(Math.tan(Math.PI * (+r[a + 1] + 90) / 360)); i > M ? i = M : i < -M && (i = -M), t[a + 1] = i; } return t; } function je(r, t, n) { const s = r.length; n = n > 1 ? n : 2, t === void 0 && (n > 2 ? t = r.slice() : t = new Array(s)); for (let a = 0; a < s; a += n) t[a] = 180 * r[a] / T, t[a + 1] = 360 * Math.atan(Math.exp(r[a + 1] / y)) / Math.PI - 90; return t; } const Ie = 6378137, ie = [-180, -90, 180, 90], Ge = Math.PI * Ie / 180; class P extends fe { /** * @param {string} code Code. * @param {string} [axisOrientation] Axis orientation. */ constructor(t, n) { super({ code: t, units: "degrees", extent: ie, axisOrientation: n, global: !0, metersPerUnit: Ge, worldExtent: ie }); } } const le = [ new P("CRS:84"), new P("EPSG:4326", "neu"), new P("urn:ogc:def:crs:OGC:1.3:CRS84"), new P("urn:ogc:def:crs:OGC:2:84"), new P("http://www.opengis.net/def/crs/OGC/1.3/CRS84"), new P("http://www.opengis.net/gml/srs/epsg.xml#4326", "neu"), new P("http://www.opengis.net/def/crs/EPSG/0/4326", "neu") ]; let z = {}; function Me(r) { return z[r] || z[r.replace(/urn:(x-)?ogc:def:crs:EPSG:(.*:)?(\w+)$/, "EPSG:$3")] || null; } function Fe(r, t) { z[r] = t; } let b = {}; function F(r, t, n) { const s = r.getCode(), a = t.getCode(); s in b || (b[s] = {}), b[s][a] = n; } function $e(r, t) { let n; return r in b && t in b[r] && (n = b[r][t]), n; } function de(r, t) { if (t !== void 0) { for (let n = 0, s = r.length; n < s; ++n) t[n] = r[n]; t = t; } else t = r.slice(); return t; } function Ye(r, t) { if (t !== void 0 && r !== t) { for (let n = 0, s = r.length; n < s; ++n) t[n] = r[n]; r = t; } return r; } function Ue(r) { Fe(r.getCode(), r), F(r, r, de); } function De(r) { r.forEach(Ue); } function ce(r) { return typeof r == "string" ? Me( /** @type {string} */ r ) : ( /** @type {Projection} */ r || null ); } function ue(r) { De(r), r.forEach(function(t) { r.forEach(function(n) { t !== n && F(t, n, de); }); }); } function We(r, t, n, s) { r.forEach(function(a) { t.forEach(function(i) { F(a, i, n), F(i, a, s); }); }); } function Xe(r, t) { return Je( r, "EPSG:4326", "EPSG:3857" ); } function Le(r, t) { const n = r.getCode(), s = t.getCode(); let a = $e(n, s); return a || (a = Ye), a; } function qe(r, t) { const n = ce(r), s = ce(t); return Le(n, s); } function Je(r, t, n) { return qe(t, n)(r, void 0, r.length); } function Ve() { ue(se), ue(le), We( le, se, Ne, je ); } Ve(); const He = Pe( ({ options: r, mapKey: t, zoom: n, defaultType: s, scale: a, center: i, poi: h, traffic: g, onInit: p, className: $, style: k }, C) => { const d = te(null), m = te(null), [N, v] = re(!1), [S, Y] = re(null); Re( C, () => ({ get mapContainer() { return d; }, get map() { return m.current; }, get isInitiated() { return N; } }), [N, m.current] ); const j = () => { var I, x; if (S) return S; const c = (x = (I = d.current) == null ? void 0 : I.querySelector(".ol-viewport")) == null ? void 0 : x.querySelectorAll("div:last-child"); if (c) return Y( Array.from(c)[c.length - 1] ), S; }, U = () => { const c = j(); c == null || c.style.setProperty("scale", "" + a); }, D = () => { const c = j(); c == null || c.style.setProperty("bottom", "0.2em"), c == null || c.style.setProperty("left", "0.4em"); }, W = () => { if (m.current != null || !d.current) return; const c = {}; i != null && i.longitude && i.latitude && (c.center = Xe([i == null ? void 0 : i.longitude, i == null ? void 0 : i.latitude])), n && (c.zoom = n), m.current = new Te({ target: d.current, key: t || "", mapType: s, // poi: store.state.poiLayer, poi: h, // traffic: store.state.trafficLayer, traffic: g, view: new be(c), controls: [], ...r }), v(!0), p && p(m.current); }; return we(() => { W(), U(), D(); }, []), /* @__PURE__ */ Oe.jsx( "div", { ref: d, className: $ || ye.map, style: k } ); } ); export { He as default };