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