UNPKG

@neshan-maps-platform/react-openlayers

Version:

A react map component wrapping neshan openlayers map.

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