@arenarium/maps-integration-google 1.0.22 → 1.0.24
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/main.js +1 -1
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import*as e from"@arenarium/maps-core/map/attribution";import{MAP_BASE_SIZE as t,MAP_ZOOM_MAX as n,MAP_ZOOM_MIN as r,MAP_ZOOM_SCALE as i}from"@arenarium/maps-core/map/constants";function a(){class e extends google.maps.OverlayView{canvas;
|
|
1
|
+
import*as e from"@arenarium/maps-core/map/attribution";import{MAP_BASE_SIZE as t,MAP_ZOOM_MAX as n,MAP_ZOOM_MIN as r,MAP_ZOOM_SCALE as i}from"@arenarium/maps-core/map/constants";function a(){class e extends google.maps.OverlayView{canvas;canvasContext;canvasWidth;canvasHeight;listeners=[];observer=null;circles=[];animationFrameId=null;animationDirty=!1;constructor(e){super(),this.canvas=document.createElement(`canvas`),this.canvas.style.position=`absolute`,this.canvas.style.top=`0px`,this.canvas.style.left=`0px`,this.canvas.style.transform=`translate(-50%, -50%)`,this.canvas.style.pointerEvents=`none`;let t=this.canvas.getContext(`2d`);if(t===null)throw Error(`Failed to get canvas context`);this.canvasContext=t,this.canvasWidth=0,this.canvasHeight=0,this.setMap(e)}onAdd(){let e=this.getPanes();if(e===null)return;e.markerLayer.appendChild(this.canvas);let t=this.getMap();this.listeners.push(t.addListener(`bounds_changed`,()=>this.quedraw())),this.listeners.push(t.addListener(`zoom_changed`,()=>this.quedraw())),this.observer=new ResizeObserver(this.resize.bind(this)),this.observer.observe(t.getDiv())}onRemove(){this.canvas.parentNode?.removeChild(this.canvas),this.listeners.forEach(e=>e.remove()),this.listeners=[],this.observer!==null&&(this.observer.disconnect(),this.observer=null),this.animationFrameId!==null&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null)}draw(){this.redraw()}update(e,t){this.circles=[];for(let n of e){let e=!Number.isNaN(n.zoom),r=e?n.zoom-t:0,i=e?n.zoom:1/0;this.circles.push({option:n,threshold:n.zoom,minzoom:r,maxzoom:i,coordinate:{lat:n.lat,lng:n.lng}})}this.circles.sort((e,t)=>t.threshold-e.threshold),this.quedraw()}remove(){this.setMap(null)}resize(){let e=this.getMap();if(!e)return;let t=window.devicePixelRatio||1,n=e.getDiv(),r=n.offsetWidth,i=n.offsetHeight;(this.canvas.width!==r*t||this.canvas.height!==i*t)&&(this.canvas.width=r*t,this.canvas.height=i*t,this.canvas.style.width=`${r}px`,this.canvas.style.height=`${i}px`,this.canvasContext.scale(t,t),this.canvasWidth=r,this.canvasHeight=i)}quedraw(){this.animationDirty===!1&&(this.animationDirty=!0,this.animationFrameId=requestAnimationFrame(()=>{this.animationFrameId=null,this.animationDirty=!1,this.redraw()}))}redraw(){let e=this.getMap(),t=this.getProjection(),n=e.getBounds();if(!e||!t||!n)return;let r=this.canvasContext;r.save(),r.clearRect(0,0,this.canvas.width,this.canvas.height),r.translate(this.canvasWidth/2,this.canvasHeight/2);let i=e.getZoom()??0;for(let e of this.circles)this.redrawCircle(r,e,i,t);r.restore()}redrawCircle(e,t,n,r){let{option:i,minzoom:a,maxzoom:l,coordinate:u}=t,d=!Number.isNaN(t.threshold);if(!(!d||n>=a&&n<l))return;let f=d?c(n,a,l):.5,p=d?1:.5,m=o(i.radius.min,i.radius.max,f),h=s(i.color.min,i.color.max,p,f),g=s(i.stroke.color.min,i.stroke.color.max,p,f),_=o(i.stroke.width.min,i.stroke.width.max,f),v=r.fromLatLngToDivPixel(u);v&&(e.save(),e.beginPath(),e.arc(v.x,v.y,m,0,Math.PI*2),e.fillStyle=h,e.fill(),_>0&&(e.strokeStyle=g,e.lineWidth=_,e.stroke()),e.restore())}}return e}function o(e,t,n){return e+(t-e)*Math.max(0,Math.min(1,n))}function s(e,t,n,r){let i=e=>{let t=e.slice(e.indexOf(`(`)+1,e.indexOf(`)`)).split(`,`);return[Number(t[0]),Number(t[1]),Number(t[2]),t[3]===void 0?1:Number(t[3])]},[a,s,c,l]=i(e),[u,d,f,p]=i(t);return`rgba(${Math.round(o(a,u,r))},${Math.round(o(s,d,r))},${Math.round(o(c,f,r))},${o(l*n,p*n,r)})`}function c(e,t,n){return n===t?1:Math.max(0,Math.min(1,(e-t)/(n-t)))}var l=class{MapClass;MapMarkerClass;map;options;circles;listeners=new Set;attributionObserver;attributionElement;constructor(e,t,i,o){this.MapClass=e,this.MapMarkerClass=t,this.options=o,this.map=new this.MapClass(i,{...o,minZoom:Math.max(o.minZoom??r,r),maxZoom:Math.min(o.maxZoom??n,n),tilt:0,tiltInteractionEnabled:!1,heading:0,headingInteractionEnabled:!1,rotateControl:!1,scaleControl:!1,clickableIcons:!1}),this.circles=new(a())(this.map),(o.attribution===!0||o.attribution===void 0)&&(this.map.addListener(`idle`,()=>{this.attributionObserver||(this.attributionObserver=new MutationObserver((e,t)=>{this.insertAttributionElement(),this.attributionElement!==void 0&&(this.updateAttributionElement(),t.disconnect())}),this.attributionObserver.observe(i,{childList:!0,subtree:!0}))}),this.map.addListener(`bounds_changed`,()=>{this.updateAttributionElement()}))}insertAttributionElement(){let t=this.map.getDiv();if(t===void 0)return;let n=t.getElementsByClassName(`gmnoprint`)[0];if(n===void 0||n.parentElement===null)return;let r=n.cloneNode(!0),i=r.childNodes.item(0)?.childNodes.item(1)?.childNodes.item(0);i!==void 0&&(i.title=``,i.innerHTML=e.getHtml(),n.parentElement.insertBefore(r,n),this.attributionElement=i)}updateAttributionElement(){let e=this.map.getDiv();if(e===void 0)return;let t=this.attributionElement?.childNodes.item(0);if(t){t.style.height=`14px`,t.style.display=`inline-flex`,t.style.alignItems=`center`,t.style.gap=`1px`;let n=t.childNodes.item(0);n&&(n.style.height=`12px`,n.style.width=`auto`);let r=t.childNodes.item(1);r&&(r.style.display=e.clientWidth>500?`initial`:`none`,r.style.color=this.options.colorScheme===google.maps.ColorScheme.DARK?`#fff`:`#000`)}}getParameters(){return{size:t,zoom:{min:this.options.minZoom??r,max:this.options.maxZoom??n,scale:i}}}getMap(){return this.map}getContainer(){return this.map.getDiv()}getZoom(){return this.map.getZoom()??NaN}getCenter(){let e=this.map.getCenter();return e===void 0?{lat:NaN,lng:NaN}:{lat:e.lat(),lng:e.lng()}}getBounds(){let e=this.map.getBounds();if(e===void 0)return{sw:{lat:NaN,lng:NaN},ne:{lat:NaN,lng:NaN}};let t=e.getSouthWest(),n=e.getNorthEast();return{sw:{lat:t.lat(),lng:t.lng()},ne:{lat:n.lat(),lng:n.lng()}}}getViewport(){return{bounds:this.getBounds(),center:this.getCenter(),zoom:this.getZoom()}}panBy(e,t){this.map.panBy(e,t)}moveTo(e,t,n){this.map.moveCamera({center:{lat:e,lng:t},zoom:n})}createMarker(e){let t=new this.MapMarkerClass({position:{lat:e.lat,lng:e.lng},content:e.element,zIndex:e.z});return{insert:()=>t.map=this.map,remove:()=>t.map=void 0,update:e=>t.zIndex=e}}updateCircles(e,t){this.circles.update(e,t)}subscribe(e,t){let n=google.maps.event.addListener(this.map,e,t);this.listeners.add({id:n,event:e,callback:t})}unsubscribe(e,t){let n=Array.from(this.listeners).find(n=>n.event===e&&n.callback===t);n!==void 0&&(google.maps.event.removeListener(n.id),this.listeners.delete(n))}};const u=[{elementType:`labels.icon`,stylers:[{visibility:`off`}]},{stylers:[{saturation:-100},{lightness:-10}]},{featureType:`landscape`,stylers:[{lightness:30}]},{featureType:`road`,elementType:`geometry`,stylers:[{saturation:-100}]}],d=[{elementType:`labels.icon`,stylers:[{visibility:`off`}]},{stylers:[{saturation:-100}]},{elementType:`geometry`,stylers:[{lightness:-45}]},{elementType:`labels.text.fill`,stylers:[{lightness:-100}]},{elementType:`labels.text.stroke`,stylers:[{lightness:-15}]},{featureType:`water`,elementType:`geometry`,stylers:[{lightness:-50}]}];export{d as GoogleMapDarkStyle,u as GoogleMapLightStyle,l as GoogleMapsProvider};
|