@neshan-maps-platform/react-openlayers
Version:
A react map component wrapping neshan openlayers map.
659 lines (658 loc) • 18.8 kB
JavaScript
import he, { forwardRef as ge, useRef as ee, useState as te, useImperativeHandle as Pe, useEffect as Re } from "react";
import { Map as we, View as Te } from "@neshan-maps-platform/ol";
var j = { exports: {} }, v = {};
/**
* @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 re;
function be() {
if (re) return v;
re = 1;
var r = Symbol.for("react.transitional.element"), t = Symbol.for("react.fragment");
function n(s, o, l) {
var _ = null;
if (l !== void 0 && (_ = "" + l), o.key !== void 0 && (_ = "" + o.key), "key" in o) {
l = {};
for (var m in o)
m !== "key" && (l[m] = o[m]);
} else l = o;
return o = l.ref, {
$$typeof: r,
type: s,
key: _,
ref: o !== void 0 ? o : null,
props: l
};
}
return v.Fragment = t, v.jsx = n, v.jsxs = n, v;
}
var S = {};
/**
* @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 ne;
function ve() {
return ne || (ne = 1, process.env.NODE_ENV !== "production" && function() {
function r(e) {
if (e == null) return null;
if (typeof e == "function")
return e.$$typeof === Ee ? null : e.displayName || e.name || null;
if (typeof e == "string") return e;
switch (e) {
case h:
return "Fragment";
case A:
return "Profiler";
case F:
return "StrictMode";
case c:
return "Suspense";
case k:
return "SuspenseList";
case de:
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 $:
return "Portal";
case U:
return e.displayName || "Context";
case Y:
return (e._context.displayName || "Context") + ".Consumer";
case D:
var a = e.render;
return e = e.displayName, e || (e = a.displayName || a.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
case C:
return a = e.displayName || null, a !== null ? a : r(e.type) || "Memo";
case W:
a = e._payload, e = e._init;
try {
return r(e(a));
} catch {
}
}
return null;
}
function t(e) {
return "" + e;
}
function n(e) {
try {
t(e);
var a = !1;
} catch {
a = !0;
}
if (a) {
a = console;
var i = a.error, u = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
return i.call(
a,
"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 === h) return "<>";
if (typeof e == "object" && e !== null && e.$$typeof === W)
return "<...>";
try {
var a = r(e);
return a ? "<" + a + ">" : "<...>";
} catch {
return "<...>";
}
}
function o() {
var e = X.A;
return e === null ? null : e.getOwner();
}
function l() {
return Error("react-stack-top-frame");
}
function _(e) {
if (z.call(e, "key")) {
var a = Object.getOwnPropertyDescriptor(e, "key").get;
if (a && a.isReactWarning) return !1;
}
return e.key !== void 0;
}
function m(e, a) {
function i() {
B || (B = !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)",
a
));
}
i.isReactWarning = !0, Object.defineProperty(e, "key", {
get: i,
configurable: !0
});
}
function O() {
var e = r(this.type);
return H[e] || (H[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 M(e, a, i, u, N, q) {
var f = i.ref;
return e = {
$$typeof: b,
type: e,
key: a,
props: i,
_owner: u
}, (f !== void 0 ? f : null) !== null ? Object.defineProperty(e, "ref", {
enumerable: !1,
get: O
}) : 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: N
}), Object.defineProperty(e, "_debugTask", {
configurable: !1,
enumerable: !1,
writable: !0,
value: q
}), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
}
function p(e, a, i, u, N, q) {
var f = a.children;
if (f !== void 0)
if (u)
if (_e(f)) {
for (u = 0; u < f.length; u++)
y(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 y(f);
if (z.call(a, "key")) {
f = r(e);
var P = Object.keys(a).filter(function(me) {
return me !== "key";
});
u = 0 < P.length ? "{key: someKey, " + P.join(": ..., ") + ": ...}" : "{key: someKey}", K[f + u] || (P = 0 < P.length ? "{" + P.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,
P,
f
), K[f + u] = !0);
}
if (f = null, i !== void 0 && (n(i), f = "" + i), _(a) && (n(a.key), f = "" + a.key), "key" in a) {
i = {};
for (var J in a)
J !== "key" && (i[J] = a[J]);
} else i = a;
return f && m(
i,
typeof e == "function" ? e.displayName || e.name || "Unknown" : e
), M(
e,
f,
i,
o(),
N,
q
);
}
function y(e) {
E(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e !== null && e.$$typeof === W && (e._payload.status === "fulfilled" ? E(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
}
function E(e) {
return typeof e == "object" && e !== null && e.$$typeof === b;
}
var d = he, b = Symbol.for("react.transitional.element"), $ = Symbol.for("react.portal"), h = Symbol.for("react.fragment"), F = Symbol.for("react.strict_mode"), A = Symbol.for("react.profiler"), Y = Symbol.for("react.consumer"), U = Symbol.for("react.context"), D = Symbol.for("react.forward_ref"), c = Symbol.for("react.suspense"), k = Symbol.for("react.suspense_list"), C = Symbol.for("react.memo"), W = Symbol.for("react.lazy"), de = Symbol.for("react.activity"), Ee = Symbol.for("react.client.reference"), X = d.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, z = Object.prototype.hasOwnProperty, _e = Array.isArray, L = console.createTask ? console.createTask : function() {
return null;
};
d = {
react_stack_bottom_frame: function(e) {
return e();
}
};
var B, H = {}, Z = d.react_stack_bottom_frame.bind(
d,
l
)(), Q = L(s(l)), K = {};
S.Fragment = h, S.jsx = function(e, a, i) {
var u = 1e4 > X.recentlyCreatedOwnerStacks++;
return p(
e,
a,
i,
!1,
u ? Error("react-stack-top-frame") : Z,
u ? L(s(e)) : Q
);
}, S.jsxs = function(e, a, i) {
var u = 1e4 > X.recentlyCreatedOwnerStacks++;
return p(
e,
a,
i,
!0,
u ? Error("react-stack-top-frame") : Z,
u ? L(s(e)) : Q
);
};
}()), S;
}
var ae;
function Se() {
return ae || (ae = 1, process.env.NODE_ENV === "production" ? j.exports = be() : j.exports = ve()), j.exports;
}
var xe = Se();
const Oe = "_map_1tyvt_2", pe = {
map: Oe
}, ye = {
// 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 ue {
/**
* @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_ || ye[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 x = 6378137, w = Math.PI * x, Ae = [-w, -w, w, w], ke = [-180, -85, 180, 85], I = x * Math.log(Math.tan(Math.PI / 2));
class R extends ue {
/**
* @param {string} code Code.
*/
constructor(t) {
super({
code: t,
units: "m",
extent: Ae,
global: !0,
worldExtent: ke,
getPointResolution: function(n, s) {
return n / Math.cosh(s[1] / x);
}
});
}
}
const oe = [
new R("EPSG:3857"),
new R("EPSG:102100"),
new R("EPSG:102113"),
new R("EPSG:900913"),
new R("http://www.opengis.net/def/crs/EPSG/0/3857"),
new R("http://www.opengis.net/gml/srs/epsg.xml#3857")
];
function Ce(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 o = 0; o < s; o += n) {
t[o] = w * r[o] / 180;
let l = x * Math.log(Math.tan(Math.PI * (+r[o + 1] + 90) / 360));
l > I ? l = I : l < -I && (l = -I), t[o + 1] = l;
}
return t;
}
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 o = 0; o < s; o += n)
t[o] = 180 * r[o] / w, t[o + 1] = 360 * Math.atan(Math.exp(r[o + 1] / x)) / Math.PI - 90;
return t;
}
const je = 6378137, se = [-180, -90, 180, 90], Ie = Math.PI * je / 180;
class g extends ue {
/**
* @param {string} code Code.
* @param {string} [axisOrientation] Axis orientation.
*/
constructor(t, n) {
super({
code: t,
units: "degrees",
extent: se,
axisOrientation: n,
global: !0,
metersPerUnit: Ie,
worldExtent: se
});
}
}
const le = [
new g("CRS:84"),
new g("EPSG:4326", "neu"),
new g("urn:ogc:def:crs:OGC:1.3:CRS84"),
new g("urn:ogc:def:crs:OGC:2:84"),
new g("http://www.opengis.net/def/crs/OGC/1.3/CRS84"),
new g("http://www.opengis.net/gml/srs/epsg.xml#4326", "neu"),
new g("http://www.opengis.net/def/crs/EPSG/0/4326", "neu")
];
let V = {};
function Ge(r) {
return V[r] || V[r.replace(/urn:(x-)?ogc:def:crs:EPSG:(.*:)?(\w+)$/, "EPSG:$3")] || null;
}
function Me(r, t) {
V[r] = t;
}
let T = {};
function G(r, t, n) {
const s = r.getCode(), o = t.getCode();
s in T || (T[s] = {}), T[s][o] = n;
}
function $e(r, t) {
let n;
return r in T && t in T[r] && (n = T[r][t]), n;
}
function fe(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 Fe(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 Ye(r) {
Me(r.getCode(), r), G(r, r, fe);
}
function Ue(r) {
r.forEach(Ye);
}
function ie(r) {
return typeof r == "string" ? Ge(
/** @type {string} */
r
) : (
/** @type {Projection} */
r || null
);
}
function ce(r) {
Ue(r), r.forEach(function(t) {
r.forEach(function(n) {
t !== n && G(t, n, fe);
});
});
}
function De(r, t, n, s) {
r.forEach(function(o) {
t.forEach(function(l) {
G(o, l, n), G(l, o, s);
});
});
}
function We(r, t) {
return qe(
r,
"EPSG:4326",
"EPSG:3857"
);
}
function Xe(r, t) {
const n = r.getCode(), s = t.getCode();
let o = $e(n, s);
return o || (o = Fe), o;
}
function Le(r, t) {
const n = ie(r), s = ie(t);
return Xe(n, s);
}
function qe(r, t, n) {
return Le(t, n)(r, void 0, r.length);
}
function Je() {
ce(oe), ce(le), De(
le,
oe,
Ce,
Ne
);
}
Je();
const Be = ge(
({
options: r,
mapKey: t,
zoom: n,
defaultType: s,
scale: o,
center: l,
poi: _,
traffic: m,
onInit: O,
className: M,
style: p
}, y) => {
const E = ee(null), d = ee(null), [b, $] = te(!1), [h, F] = te(null);
Pe(
y,
() => ({
get mapContainer() {
return E;
},
get map() {
return d.current;
},
get isInitiated() {
return b;
}
}),
[b, d.current]
);
const A = () => {
var k, C;
if (h) return h;
const c = (C = (k = E.current) == null ? void 0 : k.querySelector(".ol-viewport")) == null ? void 0 : C.querySelectorAll("div:last-child");
if (c)
return F(
Array.from(c)[c.length - 1]
), h;
}, Y = () => {
const c = A();
c == null || c.style.setProperty("scale", "" + o);
}, U = () => {
const c = A();
c == null || c.style.setProperty("bottom", "0.2em"), c == null || c.style.setProperty("left", "0.4em");
}, D = () => {
if (d.current != null || !E.current) return;
const c = {};
l != null && l.longitude && l.latitude && (c.center = We([l == null ? void 0 : l.longitude, l == null ? void 0 : l.latitude])), n && (c.zoom = n), d.current = new we({
target: E.current,
key: t || "",
mapType: s,
// poi: store.state.poiLayer,
poi: _,
// traffic: store.state.trafficLayer,
traffic: m,
view: new Te(c),
controls: [],
...r
}), $(!0), O && O(d.current);
};
return Re(() => {
D(), Y(), U();
}, []), /* @__PURE__ */ xe.jsx(
"div",
{
ref: E,
className: M || pe.map,
style: p
}
);
}
);
export {
Be as default
};