mapicgc-gl-js 1.0.4 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/mapicgc-gl.js +1 -1
- package/dist/mapicgc-gl.mjs +8 -1
- package/package.json +1 -1
- package/src/plugins/CompareMaps.js +24 -0
package/dist/mapicgc-gl.js
CHANGED
|
@@ -3845,4 +3845,4 @@ end`};t.events.push([`putFont`,function(t){(function(t){var n=t.font,i=t.out,a=t
|
|
|
3845
3845
|
</div>
|
|
3846
3846
|
</div>
|
|
3847
3847
|
</div>
|
|
3848
|
-
`).addTo(this.map)}catch(e){return console.error(`Error adding popup: ${e.message}`),null}}addFullScreen(e){try{e===void 0&&(e=`top-right`),this.map.addControl(new f.default.FullscreenControl,e)}catch(e){console.error(`Error adding fullscreen control: ${e.message}`)}}addMenuItem(e){try{let t;if(t=e.includes(`-userFieldFilter-`)?e.split(`-userFieldFilter-`)[0]:e,e.length>0){let n=document.getElementById(`menu-group`),r=document.createElement(`input`);r.type=`checkbox`,r.id=e,r.checked=!0,n.appendChild(r);let i=document.createElement(`label`);i.setAttribute(`for`,e),i.textContent=t,n.appendChild(i),r.addEventListener(`change`,t=>{this.map.setLayoutProperty(e,`visibility`,t.target.checked?`visible`:`none`)})}}catch(e){console.error(`Error adding menu item: ${e.message}`)}}addLayerTree(e){try{let t=e.features,n=document.getElementById(`map`),r=document.createElement(`nav`);r.id=`filter-group`,n.appendChild(r);let i=document.getElementById(`filter-group`);this.map.addSource(`${e.id}`,{type:e.type,data:t}),t.features.forEach(t=>{let n=t.properties.icon,r=`poi-${n}`;if(!this.map.getLayer(r)){this.map.addLayer({id:r,type:`circle`,source:`${e.id}`,paint:{"circle-radius":6,"circle-color":`#B42222`},filter:[`==`,`icon`,n]},this._firstSymbolLayer());let t=document.createElement(`input`);t.type=`checkbox`,t.id=r,t.checked=!0,i.appendChild(t);let a=document.createElement(`label`);a.setAttribute(`for`,r),a.textContent=n,i.appendChild(a),t.addEventListener(`change`,e=>{this.map.setLayoutProperty(r,`visibility`,e.target.checked?`visible`:`none`)})}})}catch(e){console.error(`Error adding layer tree: ${e.message}`)}}createNavigationControl(e,t){try{t===void 0&&(t=`top-right`),this.map.addControl(new f.default.NavigationControl(e),t)}catch(e){return console.error(`Error creating navigation control: ${e.message}`),null}}addNavigationControl(e,t){try{t===void 0&&(t=`top-right`),this.map.addControl(new f.default.NavigationControl(e),t)}catch(e){console.error(`Error adding navigation control: ${e.message}`)}}addAttributionControl(e,t){try{let n=`<a style="font-weight: bold; color: #D97634;" href="https://www.icgc.cat/Eines-i-visors/Recursos-desenvolupadors/Biblioteca-MapICGC-GL-JS/" target="_blank">Fet amb MapICGC</a>`,r=Object.assign({},{compact:!0},e),i=r.autoCollapseDelay;delete r.autoCollapseDelay,r.customAttribution?Array.isArray(r.customAttribution)?r.customAttribution.includes(n)||(r.customAttribution=[n,...r.customAttribution]):r.customAttribution!==n&&(r.customAttribution=[n,r.customAttribution]):r.customAttribution=n,this.map.addControl(new f.default.AttributionControl(r),t),i&&typeof i==`number`&&i>0&&setTimeout(()=>{let e=document.querySelector(`.maplibregl-ctrl-attrib-button`);e&&e.getAttribute(`aria-pressed`)===`true`&&e.click()},i)}catch(e){console.error(`Error adding attribution control: ${e.message}`)}}addImageLayerICGC(e,t,n){try{let r=null,i;n?(i=n,n.layerPosition):i={type:`raster`,layout:{visibility:`visible`},paint:{"raster-opacity":1},layerPosition:y8},r=this._findImageType(e,C8.Orto,C8.VectorAdmin,C8.WMS,C8.Vector),r||console.log(`❌ %c The layer: %c%s%c does not exist in the ICGC DB. Consult the documentation.`,`font-weight: bold; font-style: italic;`,`font-weight: normal; font-style: normal; color: red;`,e,`font-weight: bold; font-style: italic;`),this.addLayerWMS(e,t,i)}catch(e){console.error(`Error adding ICGC image layer: ${e.message}`)}}async addVectorLayerICGC(e,t,n){try{let{type:r=`line`,layerPosition:i=y8,layoutOptions:a={visibility:`visible`},paintOption:o}=n||{},s=this._dealOrderLayer(i);if(!e){console.log(`❌ %c The layer: %c%s%c does not exist in the ICGC DB. Consult the documentation.`,`font-weight: bold; font-style: italic;`,`font-weight: normal; font-style: normal; color: red;`,e,`font-weight: bold; font-style: italic;`);return}if(e.includes(`https`)){let t=this._getKeyByUrlVector(e);this.map.addSource(t,{type:`vector`,url:e});let r={id:t,type:`fill`,source:t,"source-layer":`cobertes`,maxzoom:18,layout:n.layout,paint:_8.cobertesSol};if(t===`cobertes2018`&&this.map.addLayer(r,s),a.visibility===`visible`){let e=this._getLegendByName(t);this.addLegend(e,t)}}else{let i=t;this.map.addSource(i,{type:`vector`,url:w8.limitsUrl});let a={id:t,type:r,source:i,"source-layer":e,layout:n.layout,paint:n.paint||{}};r===`fill`||r===`polygon`?a.paint=o||{"fill-color":`#0000FF`,"fill-opacity":0}:r===`line`&&(a.paint=o||{"line-color":`#4832a8`,"line-opacity":1,"line-width":1}),this.map.addLayer(a,s)}}catch(e){console.error(`Error adding ICGC vector layer: ${e.message}`)}}async addFGBLayerICGC(e,t,n){try{n||(n.layout={visibility:!0},n.paint={"line-color":`#4832a8`,"line-opacity":1,"line-width":1},n.type=`lines`,n.layerPosition=`labels`);let r=this._dealOrderLayer(n.layerPosition),i=await fetch(e),a={type:`FeatureCollection`,features:[]};for await(let e of qe(i.body))a.features.push(e);let o=t;this.map.addSource(o,{type:`geojson`,data:a}),e.includes(`text`)?this.map.addLayer({id:t,type:`symbol`,source:o,layout:{"text-letter-spacing":.1,"text-size":{base:1.2,stops:[[8,0],[12,14],[15,15]]},"text-font":[`FiraSans-Regular`],"text-field":[`get`,`NOM_AC`],"text-transform":`none`,"text-max-width":25,visibility:n.layout.visibility,"text-justify":`right`,"text-anchor":`top`,"text-allow-overlap":!1,"symbol-spacing":2,"text-line-height":1},paint:{"text-halo-blur":.5,"text-color":`rgba(90, 7, 7, 1)`,"text-halo-width":2,"text-halo-color":`rgba(255, 255, 255,0.8)`}},r):this.map.addLayer({id:t,type:n.type,source:o,layout:n.layout,paint:n.paint},r)}catch(e){console.error(`Error adding ICGC FGB layer: ${e.message}`)}}addTerrainICGC(e,t){try{let n;for(let t in S8)if(S8.hasOwnProperty(t)){let r=S8[t];r===e&&(n=r)}let r=n;this.getSource(`terrainICGC`)!==void 0&&(this.getStyle().layers.forEach(e=>{e.source===`terrainICGC`&&this.removeLayer(e.id)}),this.removeSource(`terrainICGC`)),this.getSource(`terrainICGC`)===void 0&&(e.includes(`terrarium`)?this.map.addSource(`terrainICGC`,{type:`raster-dem`,tiles:[r],tileSize:512,encoding:`terrarium`,maxzoom:16}):this.map.addSource(`terrainICGC`,{type:`raster-dem`,tiles:[r],tileSize:256,maxzoom:14,minzoom:7})),this.map.setTerrain({source:`terrainICGC`,exaggeration:1.5}),t==null||this.map.addControl(new V({pitch:90,bearing:null,minpitchzoom:null}),t)}catch(e){console.error(`Error adding 3D terrain: ${e.message}`)}}addLegend(e,t){try{this.map.addControl(new g4({url:e,idLayer:t}))}catch(e){console.error(`Error adding legend: ${e.message}`)}}_findImageType(e,t,n,r,i){let a=[t,n,r,i];for(let t of a)for(let[n,r]of Object.entries(t))if(r===e)return n;return null}_getKeyByUrlFGB(e){for(let t in C8.FGBAdmin)if(C8.FGBAdmin.hasOwnProperty(t)&&C8.FGBAdmin[t]===e)return t;return null}_getLegendByName(e){for(let t in w8.vectorLayers){let n=w8.vectorLayers[t];if(n.key===e)return n.legend}return null}_getKeyByUrlVector(e){for(let t in C8.Vector)if(C8.Vector.hasOwnProperty(t)&&C8.Vector[t]===e)return t;return null}async _raiseText3DStyle(){try{let e=await this.map.loadImage(w8.map3dOptions.imageIcon);this.map.hasImage(`stick`)||this.map.addImage(`stick`,e.data),this.map.getStyle().layers.forEach(t=>{if(t[`source-layer`]===w8.map3dOptions.sourceLayerFilterId&&t.minzoom>=w8.map3dOptions.minZoomFilter&&e){let e=t.id;this.map.setLayoutProperty(e,`icon-image`,`stick`),this.map.setLayoutProperty(e,`text-offset`,[0,-9]),this.map.setLayoutProperty(e,`symbol-placement`,`point`),this.map.setLayoutProperty(e,`symbol-avoid-edges`,!1),this.map.setLayoutProperty(e,`text-allow-overlap`,!0),this.map.setLayoutProperty(e,`text-ignore-placement`,!1),this.map.setLayoutProperty(e,`text-pitch-alignment`,`auto`),this.map.setLayoutProperty(e,`text-rotation-alignment`,`auto`),this.map.setLayoutProperty(e,`text-justify`,`center`),this.map.setLayoutProperty(e,`text-anchor`,`bottom`),this.map.setLayoutProperty(e,`icon-anchor`,`bottom`),this.map.setPaintProperty(e,`text-color`,`#ffffff`),this.map.setPaintProperty(e,`text-halo-color`,`#000000`),this.map.setPaintProperty(e,`text-halo-width`,2)}})}catch(e){return console.error(`Error dealing orto 3D: ${e.message}`),null}}_dealStyleMaps(e){try{if(e&&e.indexOf(`icgc.cat`)!=-1){for(let t in x8)if(x8.hasOwnProperty(t)){let n=x8[t];if(t===e)return n}return x8[0]}else return e}catch(e){return console.error(`Error dealing with map styles: ${e.message}`),null}}_dealOrto3dStyle(e){try{if(e==`orto3d`){this.map.setMaxZoom(18.8),this.map.easeTo({pitch:45});let e=new rv({intensity:4});this.map.getTerrain()&&this.map.setTerrain(null),this.map.setTerrain({source:w8.map3dOptions.terrainSource,exaggeration:w8.map3dOptions.exaggeration});let t=new vv({ambientLight:e});b8=new zD({interleaved:!0,layers:[this._createCitiesMapboxLayer(!1)],effects:[t],onAfterRender:()=>{try{let e=this.map.getZoom()>=w8.map3dOptions.minZoomRange;b8.setProps({layers:[this._createCitiesMapboxLayer(e)]})}catch{console.log(`No render 3D Mesh`)}}}),this.map.hasControl(b8)||(this.map.addControl(b8),this._raiseText3DStyle()),this.map.setSky({"sky-color":`#86bbd5`,"sky-horizon-blend":.3,"horizon-color":`#ffffff33`,"horizon-fog-blend":.1,"fog-ground-blend":.75,"fog-color":`#c5d6d6`}),this.map.on(`zoomend`,()=>{!this.map.getStyle().name==`orto3d`&&this.map.hasControl(b8)&&(this.map.removeControl(b8),b8.setProps({layers:[]}),this.map.setTerrain(null))})}else b8?.setProps({layers:[]}),this.map.hasControl(b8)&&(this.map.removeControl(b8),b8.setProps({layers:[]}),this.map.setTerrain(null))}catch(e){return console.error(`Error dealing orto 3D: ${e.message}`),null}}_dealOrderLayer(e){return e===y8?this._firstSymbolLayer():e===v8?this._firstLineLayer():``}_firstSymbolLayer(){try{let e=this.map.getStyle().layers,t;for(let n=0;n<e.length;n++)if(e[n].type===`symbol`&&e[n].id.indexOf(`contour`)===-1&&e[n].id.indexOf(`water`)===-1){t=e[n].id;break}return t}catch(e){console.error(`Error getting first symbol layer: ${e.message}`)}}_firstLineLayer(){try{let e=this.map.getStyle().layers,t;for(let n=0;n<e.length;n++)if(e[n].type===`line`){t=e[n].id;break}return t}catch(e){console.error(`Error getting first symbol layer: ${e.message}`)}}_createCitiesMapboxLayer(e=!1){try{return new Mz({id:w8.map3dOptions.layerId3d,data:w8.map3dOptions.urlTilesetCities,loader:Tz,beforeId:w8.map3dOptions.layerIdOrder,visible:e,loadOptions:{tileset:{viewDistanceScale:1,memoryAdjustedScreenSpaceError:w8.map3dOptions.spaceErrorFactor,updateTransforms:!0,adjustScreenSpaceError:w8.map3dOptions.spaceErrorFactor}},onTilesetLoad:e=>{e.adjustScreenSpaceError=w8.map3dOptions.spaceErrorFactor,e.memoryAdjustedScreenSpaceError=w8.map3dOptions.spaceErrorFactor},onTileLoad:e=>{e.content.cartographicOrigin.z-=w8.map3dOptions.zfactor},operation:`terrain+draw`,pickable:!1})}catch(e){return console.error(`Error adding MapboxOverlay: ${e.message}`),null}}},E8=c(((e,t)=>{function n(e,t){var n=e.getCenter(),r=e.getZoom(),i=e.getBearing(),a=e.getPitch();t.forEach(function(e){e.jumpTo({center:n,zoom:r,bearing:i,pitch:a})})}function r(){var e,t=arguments.length;if(t===1)e=arguments[0];else{e=[];for(var r=0;r<t;r++)e.push(arguments[r])}var i=[];e.forEach(function(t,n){i[n]=s.bind(null,t,e.filter(function(e,t){return t!==n}))});function a(){e.forEach(function(e,t){e.on(`move`,i[t])})}function o(){e.forEach(function(e,t){e.off(`move`,i[t])})}function s(e,t){o(),n(e,t),a()}return a(),function(){o(),i=[],e=[]}}t.exports=r})),D8=c(((e,t)=>{var n=typeof Reflect==`object`?Reflect:null,r=n&&typeof n.apply==`function`?n.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)},i=n&&typeof n.ownKeys==`function`?n.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};function a(e){console&&console.warn&&console.warn(e)}var o=Number.isNaN||function(e){return e!==e};function s(){s.init.call(this)}t.exports=s,t.exports.once=y,s.EventEmitter=s,s.prototype._events=void 0,s.prototype._eventsCount=0,s.prototype._maxListeners=void 0;var c=10;function l(e){if(typeof e!=`function`)throw TypeError(`The "listener" argument must be of type Function. Received type `+typeof e)}Object.defineProperty(s,`defaultMaxListeners`,{enumerable:!0,get:function(){return c},set:function(e){if(typeof e!=`number`||e<0||o(e))throw RangeError(`The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received `+e+`.`);c=e}}),s.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},s.prototype.setMaxListeners=function(e){if(typeof e!=`number`||e<0||o(e))throw RangeError(`The value of "n" is out of range. It must be a non-negative number. Received `+e+`.`);return this._maxListeners=e,this};function u(e){return e._maxListeners===void 0?s.defaultMaxListeners:e._maxListeners}s.prototype.getMaxListeners=function(){return u(this)},s.prototype.emit=function(e){for(var t=[],n=1;n<arguments.length;n++)t.push(arguments[n]);var i=e===`error`,a=this._events;if(a!==void 0)i&&=a.error===void 0;else if(!i)return!1;if(i){var o;if(t.length>0&&(o=t[0]),o instanceof Error)throw o;var s=Error(`Unhandled error.`+(o?` (`+o.message+`)`:``));throw s.context=o,s}var c=a[e];if(c===void 0)return!1;if(typeof c==`function`)r(c,this,t);else for(var l=c.length,u=g(c,l),n=0;n<l;++n)r(u[n],this,t);return!0};function d(e,t,n,r){var i,o,s;if(l(n),o=e._events,o===void 0?(o=e._events=Object.create(null),e._eventsCount=0):(o.newListener!==void 0&&(e.emit(`newListener`,t,n.listener?n.listener:n),o=e._events),s=o[t]),s===void 0)s=o[t]=n,++e._eventsCount;else if(typeof s==`function`?s=o[t]=r?[n,s]:[s,n]:r?s.unshift(n):s.push(n),i=u(e),i>0&&s.length>i&&!s.warned){s.warned=!0;var c=Error(`Possible EventEmitter memory leak detected. `+s.length+` `+String(t)+` listeners added. Use emitter.setMaxListeners() to increase limit`);c.name=`MaxListenersExceededWarning`,c.emitter=e,c.type=t,c.count=s.length,a(c)}return e}s.prototype.addListener=function(e,t){return d(this,e,t,!1)},s.prototype.on=s.prototype.addListener,s.prototype.prependListener=function(e,t){return d(this,e,t,!0)};function f(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function p(e,t,n){var r={fired:!1,wrapFn:void 0,target:e,type:t,listener:n},i=f.bind(r);return i.listener=n,r.wrapFn=i,i}s.prototype.once=function(e,t){return l(t),this.on(e,p(this,e,t)),this},s.prototype.prependOnceListener=function(e,t){return l(t),this.prependListener(e,p(this,e,t)),this},s.prototype.removeListener=function(e,t){var n,r,i,a,o;if(l(t),r=this._events,r===void 0||(n=r[e],n===void 0))return this;if(n===t||n.listener===t)--this._eventsCount===0?this._events=Object.create(null):(delete r[e],r.removeListener&&this.emit(`removeListener`,e,n.listener||t));else if(typeof n!=`function`){for(i=-1,a=n.length-1;a>=0;a--)if(n[a]===t||n[a].listener===t){o=n[a].listener,i=a;break}if(i<0)return this;i===0?n.shift():_(n,i),n.length===1&&(r[e]=n[0]),r.removeListener!==void 0&&this.emit(`removeListener`,e,o||t)}return this},s.prototype.off=s.prototype.removeListener,s.prototype.removeAllListeners=function(e){var t,n=this._events,r;if(n===void 0)return this;if(n.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):n[e]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[e]),this;if(arguments.length===0){var i=Object.keys(n),a;for(r=0;r<i.length;++r)a=i[r],a!==`removeListener`&&this.removeAllListeners(a);return this.removeAllListeners(`removeListener`),this._events=Object.create(null),this._eventsCount=0,this}if(t=n[e],typeof t==`function`)this.removeListener(e,t);else if(t!==void 0)for(r=t.length-1;r>=0;r--)this.removeListener(e,t[r]);return this};function m(e,t,n){var r=e._events;if(r===void 0)return[];var i=r[t];return i===void 0?[]:typeof i==`function`?n?[i.listener||i]:[i]:n?v(i):g(i,i.length)}s.prototype.listeners=function(e){return m(this,e,!0)},s.prototype.rawListeners=function(e){return m(this,e,!1)},s.listenerCount=function(e,t){return typeof e.listenerCount==`function`?e.listenerCount(t):h.call(e,t)},s.prototype.listenerCount=h;function h(e){var t=this._events;if(t!==void 0){var n=t[e];if(typeof n==`function`)return 1;if(n!==void 0)return n.length}return 0}s.prototype.eventNames=function(){return this._eventsCount>0?i(this._events):[]};function g(e,t){for(var n=Array(t),r=0;r<t;++r)n[r]=e[r];return n}function _(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}function v(e){for(var t=Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}function y(e,t){return new Promise(function(n,r){function i(n){e.removeListener(t,a),r(n)}function a(){typeof e.removeListener==`function`&&e.removeListener(`error`,i),n([].slice.call(arguments))}x(e,t,a,{once:!0}),t!==`error`&&b(e,i,{once:!0})})}function b(e,t,n){typeof e.on==`function`&&x(e,`error`,t,n)}function x(e,t,n,r){if(typeof e.on==`function`)r.once?e.once(t,n):e.on(t,n);else if(typeof e.addEventListener==`function`)e.addEventListener(t,function i(a){r.once&&e.removeEventListener(t,i),n(a)});else throw TypeError(`The "emitter" argument must be of type EventEmitter. Received type `+typeof e)}})),O8=d(c(((e,t)=>{var n=E8(),r=D8().EventEmitter;function i(e,t,i,a){if(this.options=a||{},this._mapA=e,this._mapB=t,this._horizontal=this.options.orientation===`horizontal`,this._onDown=this._onDown.bind(this),this._onMove=this._onMove.bind(this),this._onMouseUp=this._onMouseUp.bind(this),this._onTouchEnd=this._onTouchEnd.bind(this),this._ev=new r,this._swiper=document.createElement(`div`),this._swiper.className=this._horizontal?`compare-swiper-horizontal`:`compare-swiper-vertical`,this._controlContainer=document.createElement(`div`),this._controlContainer.className=this._horizontal?`maplibregl-compare maplibregl-compare-horizontal`:`maplibregl-compare`,this._controlContainer.className=this._controlContainer.className,this._controlContainer.appendChild(this._swiper),typeof i==`string`&&document.body.querySelectorAll){var o=document.body.querySelectorAll(i)[0];if(!o)throw Error(`Cannot find element with specified container selector.`);o.appendChild(this._controlContainer)}else if(i instanceof Element&&i.appendChild)i.appendChild(this._controlContainer);else throw Error(`Invalid container specified. Must be CSS selector or HTML element.`);this._bounds=t.getContainer().getBoundingClientRect();var s=(this._horizontal?this._bounds.height:this._bounds.width)/2;this._setPosition(s),this._clearSync=n(e,t),this._onResize=function(){this._bounds=t.getContainer().getBoundingClientRect(),this.currentPosition&&this._setPosition(this.currentPosition)}.bind(this),t.on(`resize`,this._onResize),this.options&&this.options.mousemove&&(e.getContainer().addEventListener(`mousemove`,this._onMove),t.getContainer().addEventListener(`mousemove`,this._onMove)),this._swiper.addEventListener(`mousedown`,this._onDown),this._swiper.addEventListener(`touchstart`,this._onDown)}i.prototype={_setPointerEvents:function(e){this._controlContainer.style.pointerEvents=e,this._swiper.style.pointerEvents=e},_onDown:function(e){e.touches?(document.addEventListener(`touchmove`,this._onMove),document.addEventListener(`touchend`,this._onTouchEnd)):(document.addEventListener(`mousemove`,this._onMove),document.addEventListener(`mouseup`,this._onMouseUp))},_setPosition:function(e){e=Math.min(e,this._horizontal?this._bounds.height:this._bounds.width);var t=this._horizontal?`translate(0, `+e+`px)`:`translate(`+e+`px, 0)`;this._controlContainer.style.transform=t,this._controlContainer.style.WebkitTransform=t;var n=this._horizontal?`rect(0, 999em, `+e+`px, 0)`:`rect(0, `+e+`px, `+this._bounds.height+`px, 0)`,r=this._horizontal?`rect(`+e+`px, 999em, `+this._bounds.height+`px,0)`:`rect(0, 999em, `+this._bounds.height+`px,`+e+`px)`;this._mapA.getContainer().style.clip=n,this._mapB.getContainer().style.clip=r,this.currentPosition=e},_onMove:function(e){this.options&&this.options.mousemove&&this._setPointerEvents(e.touches?`auto`:`none`),this._horizontal?this._setPosition(this._getY(e)):this._setPosition(this._getX(e))},_onMouseUp:function(){document.removeEventListener(`mousemove`,this._onMove),document.removeEventListener(`mouseup`,this._onMouseUp),this.fire(`slideend`,{currentPosition:this.currentPosition})},_onTouchEnd:function(){document.removeEventListener(`touchmove`,this._onMove),document.removeEventListener(`touchend`,this._onTouchEnd),this.fire(`slideend`,{currentPosition:this.currentPosition})},_getX:function(e){e=e.touches?e.touches[0]:e;var t=e.clientX-this._bounds.left;return t<0&&(t=0),t>this._bounds.width&&(t=this._bounds.width),t},_getY:function(e){e=e.touches?e.touches[0]:e;var t=e.clientY-this._bounds.top;return t<0&&(t=0),t>this._bounds.height&&(t=this._bounds.height),t},setSlider:function(e){this._setPosition(e)},on:function(e,t){return this._ev.on(e,t),this},fire:function(e,t){return this._ev.emit(e,t),this},off:function(e,t){return this._ev.removeListener(e,t),this},remove:function(){this._clearSync(),this._mapB.off(`resize`,this._onResize);var e=this._mapA.getContainer();e&&(e.style.clip=null,e.removeEventListener(`mousemove`,this._onMove));var t=this._mapB.getContainer();t&&(t.style.clip=null,t.removeEventListener(`mousemove`,this._onMove)),this._swiper.removeEventListener(`mousedown`,this._onDown),this._swiper.removeEventListener(`touchstart`,this._onDown),this._controlContainer.remove()}},window.maplibregl?maplibregl.Compare=i:t!==void 0&&(t.exports=i)}))());e.CompareMaps=class{constructor(e,t,n,r){let i=this;setTimeout(function(){i.mapCompare=new O8.default(e.map,t.map,n,{})},1e3)}},e.Config=g8,e.Map=T8});
|
|
3848
|
+
`).addTo(this.map)}catch(e){return console.error(`Error adding popup: ${e.message}`),null}}addFullScreen(e){try{e===void 0&&(e=`top-right`),this.map.addControl(new f.default.FullscreenControl,e)}catch(e){console.error(`Error adding fullscreen control: ${e.message}`)}}addMenuItem(e){try{let t;if(t=e.includes(`-userFieldFilter-`)?e.split(`-userFieldFilter-`)[0]:e,e.length>0){let n=document.getElementById(`menu-group`),r=document.createElement(`input`);r.type=`checkbox`,r.id=e,r.checked=!0,n.appendChild(r);let i=document.createElement(`label`);i.setAttribute(`for`,e),i.textContent=t,n.appendChild(i),r.addEventListener(`change`,t=>{this.map.setLayoutProperty(e,`visibility`,t.target.checked?`visible`:`none`)})}}catch(e){console.error(`Error adding menu item: ${e.message}`)}}addLayerTree(e){try{let t=e.features,n=document.getElementById(`map`),r=document.createElement(`nav`);r.id=`filter-group`,n.appendChild(r);let i=document.getElementById(`filter-group`);this.map.addSource(`${e.id}`,{type:e.type,data:t}),t.features.forEach(t=>{let n=t.properties.icon,r=`poi-${n}`;if(!this.map.getLayer(r)){this.map.addLayer({id:r,type:`circle`,source:`${e.id}`,paint:{"circle-radius":6,"circle-color":`#B42222`},filter:[`==`,`icon`,n]},this._firstSymbolLayer());let t=document.createElement(`input`);t.type=`checkbox`,t.id=r,t.checked=!0,i.appendChild(t);let a=document.createElement(`label`);a.setAttribute(`for`,r),a.textContent=n,i.appendChild(a),t.addEventListener(`change`,e=>{this.map.setLayoutProperty(r,`visibility`,e.target.checked?`visible`:`none`)})}})}catch(e){console.error(`Error adding layer tree: ${e.message}`)}}createNavigationControl(e,t){try{t===void 0&&(t=`top-right`),this.map.addControl(new f.default.NavigationControl(e),t)}catch(e){return console.error(`Error creating navigation control: ${e.message}`),null}}addNavigationControl(e,t){try{t===void 0&&(t=`top-right`),this.map.addControl(new f.default.NavigationControl(e),t)}catch(e){console.error(`Error adding navigation control: ${e.message}`)}}addAttributionControl(e,t){try{let n=`<a style="font-weight: bold; color: #D97634;" href="https://www.icgc.cat/Eines-i-visors/Recursos-desenvolupadors/Biblioteca-MapICGC-GL-JS/" target="_blank">Fet amb MapICGC</a>`,r=Object.assign({},{compact:!0},e),i=r.autoCollapseDelay;delete r.autoCollapseDelay,r.customAttribution?Array.isArray(r.customAttribution)?r.customAttribution.includes(n)||(r.customAttribution=[n,...r.customAttribution]):r.customAttribution!==n&&(r.customAttribution=[n,r.customAttribution]):r.customAttribution=n,this.map.addControl(new f.default.AttributionControl(r),t),i&&typeof i==`number`&&i>0&&setTimeout(()=>{let e=document.querySelector(`.maplibregl-ctrl-attrib-button`);e&&e.getAttribute(`aria-pressed`)===`true`&&e.click()},i)}catch(e){console.error(`Error adding attribution control: ${e.message}`)}}addImageLayerICGC(e,t,n){try{let r=null,i;n?(i=n,n.layerPosition):i={type:`raster`,layout:{visibility:`visible`},paint:{"raster-opacity":1},layerPosition:y8},r=this._findImageType(e,C8.Orto,C8.VectorAdmin,C8.WMS,C8.Vector),r||console.log(`❌ %c The layer: %c%s%c does not exist in the ICGC DB. Consult the documentation.`,`font-weight: bold; font-style: italic;`,`font-weight: normal; font-style: normal; color: red;`,e,`font-weight: bold; font-style: italic;`),this.addLayerWMS(e,t,i)}catch(e){console.error(`Error adding ICGC image layer: ${e.message}`)}}async addVectorLayerICGC(e,t,n){try{let{type:r=`line`,layerPosition:i=y8,layoutOptions:a={visibility:`visible`},paintOption:o}=n||{},s=this._dealOrderLayer(i);if(!e){console.log(`❌ %c The layer: %c%s%c does not exist in the ICGC DB. Consult the documentation.`,`font-weight: bold; font-style: italic;`,`font-weight: normal; font-style: normal; color: red;`,e,`font-weight: bold; font-style: italic;`);return}if(e.includes(`https`)){let t=this._getKeyByUrlVector(e);this.map.addSource(t,{type:`vector`,url:e});let r={id:t,type:`fill`,source:t,"source-layer":`cobertes`,maxzoom:18,layout:n.layout,paint:_8.cobertesSol};if(t===`cobertes2018`&&this.map.addLayer(r,s),a.visibility===`visible`){let e=this._getLegendByName(t);this.addLegend(e,t)}}else{let i=t;this.map.addSource(i,{type:`vector`,url:w8.limitsUrl});let a={id:t,type:r,source:i,"source-layer":e,layout:n.layout,paint:n.paint||{}};r===`fill`||r===`polygon`?a.paint=o||{"fill-color":`#0000FF`,"fill-opacity":0}:r===`line`&&(a.paint=o||{"line-color":`#4832a8`,"line-opacity":1,"line-width":1}),this.map.addLayer(a,s)}}catch(e){console.error(`Error adding ICGC vector layer: ${e.message}`)}}async addFGBLayerICGC(e,t,n){try{n||(n.layout={visibility:!0},n.paint={"line-color":`#4832a8`,"line-opacity":1,"line-width":1},n.type=`lines`,n.layerPosition=`labels`);let r=this._dealOrderLayer(n.layerPosition),i=await fetch(e),a={type:`FeatureCollection`,features:[]};for await(let e of qe(i.body))a.features.push(e);let o=t;this.map.addSource(o,{type:`geojson`,data:a}),e.includes(`text`)?this.map.addLayer({id:t,type:`symbol`,source:o,layout:{"text-letter-spacing":.1,"text-size":{base:1.2,stops:[[8,0],[12,14],[15,15]]},"text-font":[`FiraSans-Regular`],"text-field":[`get`,`NOM_AC`],"text-transform":`none`,"text-max-width":25,visibility:n.layout.visibility,"text-justify":`right`,"text-anchor":`top`,"text-allow-overlap":!1,"symbol-spacing":2,"text-line-height":1},paint:{"text-halo-blur":.5,"text-color":`rgba(90, 7, 7, 1)`,"text-halo-width":2,"text-halo-color":`rgba(255, 255, 255,0.8)`}},r):this.map.addLayer({id:t,type:n.type,source:o,layout:n.layout,paint:n.paint},r)}catch(e){console.error(`Error adding ICGC FGB layer: ${e.message}`)}}addTerrainICGC(e,t){try{let n;for(let t in S8)if(S8.hasOwnProperty(t)){let r=S8[t];r===e&&(n=r)}let r=n;this.getSource(`terrainICGC`)!==void 0&&(this.getStyle().layers.forEach(e=>{e.source===`terrainICGC`&&this.removeLayer(e.id)}),this.removeSource(`terrainICGC`)),this.getSource(`terrainICGC`)===void 0&&(e.includes(`terrarium`)?this.map.addSource(`terrainICGC`,{type:`raster-dem`,tiles:[r],tileSize:512,encoding:`terrarium`,maxzoom:16}):this.map.addSource(`terrainICGC`,{type:`raster-dem`,tiles:[r],tileSize:256,maxzoom:14,minzoom:7})),this.map.setTerrain({source:`terrainICGC`,exaggeration:1.5}),t==null||this.map.addControl(new V({pitch:90,bearing:null,minpitchzoom:null}),t)}catch(e){console.error(`Error adding 3D terrain: ${e.message}`)}}addLegend(e,t){try{this.map.addControl(new g4({url:e,idLayer:t}))}catch(e){console.error(`Error adding legend: ${e.message}`)}}_findImageType(e,t,n,r,i){let a=[t,n,r,i];for(let t of a)for(let[n,r]of Object.entries(t))if(r===e)return n;return null}_getKeyByUrlFGB(e){for(let t in C8.FGBAdmin)if(C8.FGBAdmin.hasOwnProperty(t)&&C8.FGBAdmin[t]===e)return t;return null}_getLegendByName(e){for(let t in w8.vectorLayers){let n=w8.vectorLayers[t];if(n.key===e)return n.legend}return null}_getKeyByUrlVector(e){for(let t in C8.Vector)if(C8.Vector.hasOwnProperty(t)&&C8.Vector[t]===e)return t;return null}async _raiseText3DStyle(){try{let e=await this.map.loadImage(w8.map3dOptions.imageIcon);this.map.hasImage(`stick`)||this.map.addImage(`stick`,e.data),this.map.getStyle().layers.forEach(t=>{if(t[`source-layer`]===w8.map3dOptions.sourceLayerFilterId&&t.minzoom>=w8.map3dOptions.minZoomFilter&&e){let e=t.id;this.map.setLayoutProperty(e,`icon-image`,`stick`),this.map.setLayoutProperty(e,`text-offset`,[0,-9]),this.map.setLayoutProperty(e,`symbol-placement`,`point`),this.map.setLayoutProperty(e,`symbol-avoid-edges`,!1),this.map.setLayoutProperty(e,`text-allow-overlap`,!0),this.map.setLayoutProperty(e,`text-ignore-placement`,!1),this.map.setLayoutProperty(e,`text-pitch-alignment`,`auto`),this.map.setLayoutProperty(e,`text-rotation-alignment`,`auto`),this.map.setLayoutProperty(e,`text-justify`,`center`),this.map.setLayoutProperty(e,`text-anchor`,`bottom`),this.map.setLayoutProperty(e,`icon-anchor`,`bottom`),this.map.setPaintProperty(e,`text-color`,`#ffffff`),this.map.setPaintProperty(e,`text-halo-color`,`#000000`),this.map.setPaintProperty(e,`text-halo-width`,2)}})}catch(e){return console.error(`Error dealing orto 3D: ${e.message}`),null}}_dealStyleMaps(e){try{if(e&&e.indexOf(`icgc.cat`)!=-1){for(let t in x8)if(x8.hasOwnProperty(t)){let n=x8[t];if(t===e)return n}return x8[0]}else return e}catch(e){return console.error(`Error dealing with map styles: ${e.message}`),null}}_dealOrto3dStyle(e){try{if(e==`orto3d`){this.map.setMaxZoom(18.8),this.map.easeTo({pitch:45});let e=new rv({intensity:4});this.map.getTerrain()&&this.map.setTerrain(null),this.map.setTerrain({source:w8.map3dOptions.terrainSource,exaggeration:w8.map3dOptions.exaggeration});let t=new vv({ambientLight:e});b8=new zD({interleaved:!0,layers:[this._createCitiesMapboxLayer(!1)],effects:[t],onAfterRender:()=>{try{let e=this.map.getZoom()>=w8.map3dOptions.minZoomRange;b8.setProps({layers:[this._createCitiesMapboxLayer(e)]})}catch{console.log(`No render 3D Mesh`)}}}),this.map.hasControl(b8)||(this.map.addControl(b8),this._raiseText3DStyle()),this.map.setSky({"sky-color":`#86bbd5`,"sky-horizon-blend":.3,"horizon-color":`#ffffff33`,"horizon-fog-blend":.1,"fog-ground-blend":.75,"fog-color":`#c5d6d6`}),this.map.on(`zoomend`,()=>{!this.map.getStyle().name==`orto3d`&&this.map.hasControl(b8)&&(this.map.removeControl(b8),b8.setProps({layers:[]}),this.map.setTerrain(null))})}else b8?.setProps({layers:[]}),this.map.hasControl(b8)&&(this.map.removeControl(b8),b8.setProps({layers:[]}),this.map.setTerrain(null))}catch(e){return console.error(`Error dealing orto 3D: ${e.message}`),null}}_dealOrderLayer(e){return e===y8?this._firstSymbolLayer():e===v8?this._firstLineLayer():``}_firstSymbolLayer(){try{let e=this.map.getStyle().layers,t;for(let n=0;n<e.length;n++)if(e[n].type===`symbol`&&e[n].id.indexOf(`contour`)===-1&&e[n].id.indexOf(`water`)===-1){t=e[n].id;break}return t}catch(e){console.error(`Error getting first symbol layer: ${e.message}`)}}_firstLineLayer(){try{let e=this.map.getStyle().layers,t;for(let n=0;n<e.length;n++)if(e[n].type===`line`){t=e[n].id;break}return t}catch(e){console.error(`Error getting first symbol layer: ${e.message}`)}}_createCitiesMapboxLayer(e=!1){try{return new Mz({id:w8.map3dOptions.layerId3d,data:w8.map3dOptions.urlTilesetCities,loader:Tz,beforeId:w8.map3dOptions.layerIdOrder,visible:e,loadOptions:{tileset:{viewDistanceScale:1,memoryAdjustedScreenSpaceError:w8.map3dOptions.spaceErrorFactor,updateTransforms:!0,adjustScreenSpaceError:w8.map3dOptions.spaceErrorFactor}},onTilesetLoad:e=>{e.adjustScreenSpaceError=w8.map3dOptions.spaceErrorFactor,e.memoryAdjustedScreenSpaceError=w8.map3dOptions.spaceErrorFactor},onTileLoad:e=>{e.content.cartographicOrigin.z-=w8.map3dOptions.zfactor},operation:`terrain+draw`,pickable:!1})}catch(e){return console.error(`Error adding MapboxOverlay: ${e.message}`),null}}},E8=c(((e,t)=>{function n(e,t){var n=e.getCenter(),r=e.getZoom(),i=e.getBearing(),a=e.getPitch();t.forEach(function(e){e.jumpTo({center:n,zoom:r,bearing:i,pitch:a})})}function r(){var e,t=arguments.length;if(t===1)e=arguments[0];else{e=[];for(var r=0;r<t;r++)e.push(arguments[r])}var i=[];e.forEach(function(t,n){i[n]=s.bind(null,t,e.filter(function(e,t){return t!==n}))});function a(){e.forEach(function(e,t){e.on(`move`,i[t])})}function o(){e.forEach(function(e,t){e.off(`move`,i[t])})}function s(e,t){o(),n(e,t),a()}return a(),function(){o(),i=[],e=[]}}t.exports=r})),D8=c(((e,t)=>{var n=typeof Reflect==`object`?Reflect:null,r=n&&typeof n.apply==`function`?n.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)},i=n&&typeof n.ownKeys==`function`?n.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};function a(e){console&&console.warn&&console.warn(e)}var o=Number.isNaN||function(e){return e!==e};function s(){s.init.call(this)}t.exports=s,t.exports.once=y,s.EventEmitter=s,s.prototype._events=void 0,s.prototype._eventsCount=0,s.prototype._maxListeners=void 0;var c=10;function l(e){if(typeof e!=`function`)throw TypeError(`The "listener" argument must be of type Function. Received type `+typeof e)}Object.defineProperty(s,`defaultMaxListeners`,{enumerable:!0,get:function(){return c},set:function(e){if(typeof e!=`number`||e<0||o(e))throw RangeError(`The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received `+e+`.`);c=e}}),s.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},s.prototype.setMaxListeners=function(e){if(typeof e!=`number`||e<0||o(e))throw RangeError(`The value of "n" is out of range. It must be a non-negative number. Received `+e+`.`);return this._maxListeners=e,this};function u(e){return e._maxListeners===void 0?s.defaultMaxListeners:e._maxListeners}s.prototype.getMaxListeners=function(){return u(this)},s.prototype.emit=function(e){for(var t=[],n=1;n<arguments.length;n++)t.push(arguments[n]);var i=e===`error`,a=this._events;if(a!==void 0)i&&=a.error===void 0;else if(!i)return!1;if(i){var o;if(t.length>0&&(o=t[0]),o instanceof Error)throw o;var s=Error(`Unhandled error.`+(o?` (`+o.message+`)`:``));throw s.context=o,s}var c=a[e];if(c===void 0)return!1;if(typeof c==`function`)r(c,this,t);else for(var l=c.length,u=g(c,l),n=0;n<l;++n)r(u[n],this,t);return!0};function d(e,t,n,r){var i,o,s;if(l(n),o=e._events,o===void 0?(o=e._events=Object.create(null),e._eventsCount=0):(o.newListener!==void 0&&(e.emit(`newListener`,t,n.listener?n.listener:n),o=e._events),s=o[t]),s===void 0)s=o[t]=n,++e._eventsCount;else if(typeof s==`function`?s=o[t]=r?[n,s]:[s,n]:r?s.unshift(n):s.push(n),i=u(e),i>0&&s.length>i&&!s.warned){s.warned=!0;var c=Error(`Possible EventEmitter memory leak detected. `+s.length+` `+String(t)+` listeners added. Use emitter.setMaxListeners() to increase limit`);c.name=`MaxListenersExceededWarning`,c.emitter=e,c.type=t,c.count=s.length,a(c)}return e}s.prototype.addListener=function(e,t){return d(this,e,t,!1)},s.prototype.on=s.prototype.addListener,s.prototype.prependListener=function(e,t){return d(this,e,t,!0)};function f(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function p(e,t,n){var r={fired:!1,wrapFn:void 0,target:e,type:t,listener:n},i=f.bind(r);return i.listener=n,r.wrapFn=i,i}s.prototype.once=function(e,t){return l(t),this.on(e,p(this,e,t)),this},s.prototype.prependOnceListener=function(e,t){return l(t),this.prependListener(e,p(this,e,t)),this},s.prototype.removeListener=function(e,t){var n,r,i,a,o;if(l(t),r=this._events,r===void 0||(n=r[e],n===void 0))return this;if(n===t||n.listener===t)--this._eventsCount===0?this._events=Object.create(null):(delete r[e],r.removeListener&&this.emit(`removeListener`,e,n.listener||t));else if(typeof n!=`function`){for(i=-1,a=n.length-1;a>=0;a--)if(n[a]===t||n[a].listener===t){o=n[a].listener,i=a;break}if(i<0)return this;i===0?n.shift():_(n,i),n.length===1&&(r[e]=n[0]),r.removeListener!==void 0&&this.emit(`removeListener`,e,o||t)}return this},s.prototype.off=s.prototype.removeListener,s.prototype.removeAllListeners=function(e){var t,n=this._events,r;if(n===void 0)return this;if(n.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):n[e]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[e]),this;if(arguments.length===0){var i=Object.keys(n),a;for(r=0;r<i.length;++r)a=i[r],a!==`removeListener`&&this.removeAllListeners(a);return this.removeAllListeners(`removeListener`),this._events=Object.create(null),this._eventsCount=0,this}if(t=n[e],typeof t==`function`)this.removeListener(e,t);else if(t!==void 0)for(r=t.length-1;r>=0;r--)this.removeListener(e,t[r]);return this};function m(e,t,n){var r=e._events;if(r===void 0)return[];var i=r[t];return i===void 0?[]:typeof i==`function`?n?[i.listener||i]:[i]:n?v(i):g(i,i.length)}s.prototype.listeners=function(e){return m(this,e,!0)},s.prototype.rawListeners=function(e){return m(this,e,!1)},s.listenerCount=function(e,t){return typeof e.listenerCount==`function`?e.listenerCount(t):h.call(e,t)},s.prototype.listenerCount=h;function h(e){var t=this._events;if(t!==void 0){var n=t[e];if(typeof n==`function`)return 1;if(n!==void 0)return n.length}return 0}s.prototype.eventNames=function(){return this._eventsCount>0?i(this._events):[]};function g(e,t){for(var n=Array(t),r=0;r<t;++r)n[r]=e[r];return n}function _(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}function v(e){for(var t=Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}function y(e,t){return new Promise(function(n,r){function i(n){e.removeListener(t,a),r(n)}function a(){typeof e.removeListener==`function`&&e.removeListener(`error`,i),n([].slice.call(arguments))}x(e,t,a,{once:!0}),t!==`error`&&b(e,i,{once:!0})})}function b(e,t,n){typeof e.on==`function`&&x(e,`error`,t,n)}function x(e,t,n,r){if(typeof e.on==`function`)r.once?e.once(t,n):e.on(t,n);else if(typeof e.addEventListener==`function`)e.addEventListener(t,function i(a){r.once&&e.removeEventListener(t,i),n(a)});else throw TypeError(`The "emitter" argument must be of type EventEmitter. Received type `+typeof e)}})),O8=d(c(((e,t)=>{var n=E8(),r=D8().EventEmitter;function i(e,t,i,a){if(this.options=a||{},this._mapA=e,this._mapB=t,this._horizontal=this.options.orientation===`horizontal`,this._onDown=this._onDown.bind(this),this._onMove=this._onMove.bind(this),this._onMouseUp=this._onMouseUp.bind(this),this._onTouchEnd=this._onTouchEnd.bind(this),this._ev=new r,this._swiper=document.createElement(`div`),this._swiper.className=this._horizontal?`compare-swiper-horizontal`:`compare-swiper-vertical`,this._controlContainer=document.createElement(`div`),this._controlContainer.className=this._horizontal?`maplibregl-compare maplibregl-compare-horizontal`:`maplibregl-compare`,this._controlContainer.className=this._controlContainer.className,this._controlContainer.appendChild(this._swiper),typeof i==`string`&&document.body.querySelectorAll){var o=document.body.querySelectorAll(i)[0];if(!o)throw Error(`Cannot find element with specified container selector.`);o.appendChild(this._controlContainer)}else if(i instanceof Element&&i.appendChild)i.appendChild(this._controlContainer);else throw Error(`Invalid container specified. Must be CSS selector or HTML element.`);this._bounds=t.getContainer().getBoundingClientRect();var s=(this._horizontal?this._bounds.height:this._bounds.width)/2;this._setPosition(s),this._clearSync=n(e,t),this._onResize=function(){this._bounds=t.getContainer().getBoundingClientRect(),this.currentPosition&&this._setPosition(this.currentPosition)}.bind(this),t.on(`resize`,this._onResize),this.options&&this.options.mousemove&&(e.getContainer().addEventListener(`mousemove`,this._onMove),t.getContainer().addEventListener(`mousemove`,this._onMove)),this._swiper.addEventListener(`mousedown`,this._onDown),this._swiper.addEventListener(`touchstart`,this._onDown)}i.prototype={_setPointerEvents:function(e){this._controlContainer.style.pointerEvents=e,this._swiper.style.pointerEvents=e},_onDown:function(e){e.touches?(document.addEventListener(`touchmove`,this._onMove),document.addEventListener(`touchend`,this._onTouchEnd)):(document.addEventListener(`mousemove`,this._onMove),document.addEventListener(`mouseup`,this._onMouseUp))},_setPosition:function(e){e=Math.min(e,this._horizontal?this._bounds.height:this._bounds.width);var t=this._horizontal?`translate(0, `+e+`px)`:`translate(`+e+`px, 0)`;this._controlContainer.style.transform=t,this._controlContainer.style.WebkitTransform=t;var n=this._horizontal?`rect(0, 999em, `+e+`px, 0)`:`rect(0, `+e+`px, `+this._bounds.height+`px, 0)`,r=this._horizontal?`rect(`+e+`px, 999em, `+this._bounds.height+`px,0)`:`rect(0, 999em, `+this._bounds.height+`px,`+e+`px)`;this._mapA.getContainer().style.clip=n,this._mapB.getContainer().style.clip=r,this.currentPosition=e},_onMove:function(e){this.options&&this.options.mousemove&&this._setPointerEvents(e.touches?`auto`:`none`),this._horizontal?this._setPosition(this._getY(e)):this._setPosition(this._getX(e))},_onMouseUp:function(){document.removeEventListener(`mousemove`,this._onMove),document.removeEventListener(`mouseup`,this._onMouseUp),this.fire(`slideend`,{currentPosition:this.currentPosition})},_onTouchEnd:function(){document.removeEventListener(`touchmove`,this._onMove),document.removeEventListener(`touchend`,this._onTouchEnd),this.fire(`slideend`,{currentPosition:this.currentPosition})},_getX:function(e){e=e.touches?e.touches[0]:e;var t=e.clientX-this._bounds.left;return t<0&&(t=0),t>this._bounds.width&&(t=this._bounds.width),t},_getY:function(e){e=e.touches?e.touches[0]:e;var t=e.clientY-this._bounds.top;return t<0&&(t=0),t>this._bounds.height&&(t=this._bounds.height),t},setSlider:function(e){this._setPosition(e)},on:function(e,t){return this._ev.on(e,t),this},fire:function(e,t){return this._ev.emit(e,t),this},off:function(e,t){return this._ev.removeListener(e,t),this},remove:function(){this._clearSync(),this._mapB.off(`resize`,this._onResize);var e=this._mapA.getContainer();e&&(e.style.clip=null,e.removeEventListener(`mousemove`,this._onMove));var t=this._mapB.getContainer();t&&(t.style.clip=null,t.removeEventListener(`mousemove`,this._onMove)),this._swiper.removeEventListener(`mousedown`,this._onDown),this._swiper.removeEventListener(`touchstart`,this._onDown),this._controlContainer.remove()}},window.maplibregl?maplibregl.Compare=i:t!==void 0&&(t.exports=i)}))());e.CompareMaps=class{constructor(e,t,n,r){let i=this;setTimeout(function(){i.mapCompare=new O8.default(e.map,t.map,n,{}),i.collapseAttribution(e.map),i.collapseAttribution(t.map)},1e3)}collapseAttribution(e){let t=()=>{let n=e.getContainer().querySelector(`.maplibregl-ctrl-attrib-button`);n?n.click():requestAnimationFrame(t)};t()}},e.Config=g8,e.Map=T8});
|
package/dist/mapicgc-gl.mjs
CHANGED
|
@@ -88131,9 +88131,16 @@ var cK = "https://eines.icgc.cat/recursos/mapicgc-gl-js/mapicgc-config.json", lK
|
|
|
88131
88131
|
constructor(e, t, n, r) {
|
|
88132
88132
|
let i = this;
|
|
88133
88133
|
setTimeout(function() {
|
|
88134
|
-
i.mapCompare = new SK.default(e.map, t.map, n, {});
|
|
88134
|
+
i.mapCompare = new SK.default(e.map, t.map, n, {}), i.collapseAttribution(e.map), i.collapseAttribution(t.map);
|
|
88135
88135
|
}, 1e3);
|
|
88136
88136
|
}
|
|
88137
|
+
collapseAttribution(e) {
|
|
88138
|
+
let t = () => {
|
|
88139
|
+
let n = e.getContainer().querySelector(".maplibregl-ctrl-attrib-button");
|
|
88140
|
+
n ? n.click() : requestAnimationFrame(t);
|
|
88141
|
+
};
|
|
88142
|
+
t();
|
|
88143
|
+
}
|
|
88137
88144
|
};
|
|
88138
88145
|
//#endregion
|
|
88139
88146
|
export { CK as CompareMaps, uK as Config, yK as Map };
|
package/package.json
CHANGED
|
@@ -20,9 +20,33 @@ export default class CompareMaps {
|
|
|
20
20
|
|
|
21
21
|
setTimeout(function () {
|
|
22
22
|
_this.mapCompare = new Compare(map1.map, map2.map, container, {});
|
|
23
|
+
|
|
24
|
+
// Collapse attribution controls on both maps
|
|
25
|
+
_this.collapseAttribution(map1.map);
|
|
26
|
+
_this.collapseAttribution(map2.map);
|
|
23
27
|
}, 1000);
|
|
24
28
|
|
|
25
29
|
//this.mapCompare=new Compare(map1.map,map2.map, container,{});
|
|
26
30
|
//console.info( this.mapCompare);
|
|
27
31
|
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Collapses the attribution control on a map.
|
|
35
|
+
* @function collapseAttribution
|
|
36
|
+
* @param {Object} map - The map object to collapse attribution on.
|
|
37
|
+
*/
|
|
38
|
+
collapseAttribution(map) {
|
|
39
|
+
const tryCollapse = () => {
|
|
40
|
+
const container = map.getContainer();
|
|
41
|
+
const button = container.querySelector('.maplibregl-ctrl-attrib-button');
|
|
42
|
+
|
|
43
|
+
if (button) {
|
|
44
|
+
button.click();
|
|
45
|
+
} else {
|
|
46
|
+
requestAnimationFrame(tryCollapse);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
tryCollapse();
|
|
51
|
+
}
|
|
28
52
|
}
|