@arenarium/maps-integration-google 1.0.19 → 1.0.20
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.d.ts +33 -28
- package/dist/main.js +1 -1
- package/package.json +40 -47
package/dist/main.d.ts
CHANGED
|
@@ -1,40 +1,45 @@
|
|
|
1
1
|
import { IMapProvider, IMapProviderMarker, IMapProviderMarkerCircleOptions, IMapProviderMarkerOptions, MapProviderEvent } from "@arenarium/maps-core/declarations/interfaces";
|
|
2
2
|
import { MapBounds, MapCoordinates, MapParameters, MapViewport } from "@arenarium/maps-core/declarations/types";
|
|
3
|
+
|
|
4
|
+
//#region src/lib/provider.d.ts
|
|
3
5
|
interface GoogleMapsClass {
|
|
4
|
-
|
|
6
|
+
new (container: HTMLElement, options: google.maps.MapOptions): google.maps.Map;
|
|
5
7
|
}
|
|
6
8
|
interface GoogleMapsMarkerClass {
|
|
7
|
-
|
|
9
|
+
new (options: google.maps.marker.AdvancedMarkerElementOptions): google.maps.marker.AdvancedMarkerElement;
|
|
8
10
|
}
|
|
9
11
|
interface GoogleMapsOptions extends google.maps.MapOptions {
|
|
10
|
-
|
|
12
|
+
attribution?: boolean;
|
|
11
13
|
}
|
|
12
14
|
declare class GoogleMapsProvider implements IMapProvider {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
15
|
+
private MapClass;
|
|
16
|
+
private MapMarkerClass;
|
|
17
|
+
private map;
|
|
18
|
+
private options;
|
|
19
|
+
private circles;
|
|
20
|
+
private listeners;
|
|
21
|
+
private attributionObserver;
|
|
22
|
+
private attributionElement;
|
|
23
|
+
constructor(mapClass: GoogleMapsClass, mapMarkerClass: GoogleMapsMarkerClass, container: HTMLElement, options: GoogleMapsOptions);
|
|
24
|
+
private insertAttributionElement;
|
|
25
|
+
private updateAttributionElement;
|
|
26
|
+
getParameters(): MapParameters;
|
|
27
|
+
getMap(): google.maps.Map;
|
|
28
|
+
getContainer(): HTMLElement;
|
|
29
|
+
getZoom(): number;
|
|
30
|
+
getCenter(): MapCoordinates;
|
|
31
|
+
getBounds(): MapBounds;
|
|
32
|
+
getViewport(): MapViewport;
|
|
33
|
+
panBy(x: number, y: number): void;
|
|
34
|
+
moveTo(lat: number, lng: number, zoom: number): void;
|
|
35
|
+
createMarker(options: IMapProviderMarkerOptions): IMapProviderMarker;
|
|
36
|
+
updateCircles(options: IMapProviderMarkerCircleOptions[], depth: number): void;
|
|
37
|
+
subscribe(event: MapProviderEvent, callback: () => void): void;
|
|
38
|
+
unsubscribe(event: MapProviderEvent, callback: () => void): void;
|
|
37
39
|
}
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region src/lib/styles.d.ts
|
|
38
42
|
declare const GoogleMapLightStyle: google.maps.MapTypeStyle[];
|
|
39
43
|
declare const GoogleMapDarkStyle: google.maps.MapTypeStyle[];
|
|
40
|
-
|
|
44
|
+
//#endregion
|
|
45
|
+
export { GoogleMapDarkStyle, GoogleMapLightStyle, GoogleMapsProvider };
|
package/dist/main.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
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{parameters;canvas;context;listeners=[];circles=[];animationFrameId=null;animationDirty=!1;constructor(e,t){super(),this.parameters=t,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 n=this.canvas.getContext(`2d`);if(n==null)throw Error(`Failed to get canvas context`);this.context=n,this.setMap(e)}onAdd(){this.getPanes().markerLayer.appendChild(this.canvas);let e=this.getMap();this.listeners.push(e.addListener(`bounds_changed`,()=>this.quedraw())),this.listeners.push(e.addListener(`zoom_changed`,()=>this.quedraw())),new ResizeObserver(this.resize.bind(this)).observe(e.getDiv()),this.resize()}onRemove(){this.canvas.parentNode?.removeChild(this.canvas),this.listeners.forEach(e=>e.remove()),this.listeners=[],this.animationFrameId!==null&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null)}draw(){this.quedraw()}update(e,t){this.circles=[];for(let n of e){let e=Number.isNaN(n.zoom),r=e?0:n.zoom-t,i=e?1/0:n.zoom;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.context.setTransform(t,0,0,t,0,0))}quedraw(){this.animationDirty=!0,this.animationFrameId??=requestAnimationFrame(()=>{this.animationFrameId=null,this.animationDirty&&(this.animationDirty=!1,this.redraw())})}redraw(){let e=this.getMap(),t=this.getProjection(),n=e.getBounds();if(!e||!t||!n)return;let r=this.context;r.save(),r.clearRect(0,0,this.canvas.width,this.canvas.height),r.translate(this.canvas.width/2,this.canvas.height/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 i=Number.isNaN(t.threshold),{option:a,minzoom:l,maxzoom:u,coordinate:d}=t;if(!(i||n>=l&&n<u))return;let f=i?0:c(n,l,u),p=i?.5:1,m=o(a.radius.min,a.radius.max,f),h=s(a.color.min,a.color.max,p,f),g=s(a.stroke.color.min,a.stroke.color.max,p,f),_=o(a.stroke.width.min,a.stroke.width.max,f),v=r.fromLatLngToDivPixel(d);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,this.getParameters()),(o.attribution==1||o.attribution==null)&&(this.map.addListener(`idle`,()=>{this.attributionObserver||(this.attributionObserver=new MutationObserver((e,t)=>{this.insertAttributionElement(),this.attributionElement!=null&&(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==null)return;let n=t.getElementsByClassName(`gmnoprint`)[0];if(n==null||n.parentElement==null)return;let r=n.cloneNode(!0),i=r.childNodes.item(0)?.childNodes.item(1)?.childNodes.item(0);i!=null&&(i.title=``,i.innerHTML=e.getHtml(),n.parentElement.insertBefore(r,n),this.attributionElement=i)}updateAttributionElement(){let e=this.map.getDiv();if(e==null)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==null?{lat:NaN,lng:NaN}:{lat:e.lat(),lng:e.lng()}}getBounds(){let e=this.map.getBounds();if(e==null)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.setCenter({lat:e,lng:t}),this.map.setZoom(n)}createMarker(e){let t=new this.MapMarkerClass({position:{lat:e.lat,lng:e.lng},content:e.element,zIndex:e.z});return{inserted:()=>t.map!=null&&t.map==this.map,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=this.listeners.values().find(n=>n.event===e&&n.callback===t);n!=null&&(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};
|
package/package.json
CHANGED
|
@@ -1,48 +1,41 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
"lib_google_build": "bun run lib_google_check && bunup",
|
|
43
|
-
"lib_google_patch": "bun pm version patch --no-git-tag-version",
|
|
44
|
-
"lib_google_commit": "git add . && git commit -m 'PUBLISH @arenarium/maps-integration-google'",
|
|
45
|
-
"lib_google_publish": "bun publish --access public",
|
|
46
|
-
"lib_google_package": "bun run lib_google_build && bun run lib_google_patch && bun run lib_google_commit && bun run lib_google_publish"
|
|
47
|
-
}
|
|
48
|
-
}
|
|
2
|
+
"name": "@arenarium/maps-integration-google",
|
|
3
|
+
"description": "Integration with Google Maps for @arenarium/maps.",
|
|
4
|
+
"version": "1.0.20",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
9
|
+
"types": "./dist/main.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": "./dist/main.js",
|
|
12
|
+
"./package.json": "./package.json"
|
|
13
|
+
},
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"author": "arenarium",
|
|
16
|
+
"homepage": "https://arenarium.dev",
|
|
17
|
+
"keywords": [
|
|
18
|
+
"arenarium",
|
|
19
|
+
"maps",
|
|
20
|
+
"google",
|
|
21
|
+
"google maps"
|
|
22
|
+
],
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"tsdown": "^0.21.4",
|
|
25
|
+
"prettier": "^3.8.1"
|
|
26
|
+
},
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"@googlemaps/js-api-loader": "^2.0.2",
|
|
29
|
+
"@types/google.maps": "^3.58.1"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@arenarium/maps-core": "1.0.25"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"lib_google_check": "pnpm exec tsc --noEmit",
|
|
36
|
+
"lib_google_build": "pnpm run lib_google_check && tsdown",
|
|
37
|
+
"lib_google_patch": "npm version patch --no-git-tag-version",
|
|
38
|
+
"lib_google_publish": "pnpm publish --access public --no-git-checks",
|
|
39
|
+
"lib_google_package": "pnpm run lib_google_build && pnpm run lib_google_patch && pnpm run lib_google_publish"
|
|
40
|
+
}
|
|
41
|
+
}
|