@arenarium/maps-integration-google 1.0.0
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/LICENSE.txt +21 -0
- package/dist/main.cjs.js +1 -0
- package/dist/main.d.ts +93 -0
- package/dist/main.es.js +243 -0
- package/package.json +45 -0
- package/src/lib/provider.ts +144 -0
- package/src/lib/styles.ts +88 -0
- package/src/main.ts +3 -0
- package/tsconfig.json +19 -0
- package/vite.config.ts +23 -0
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 arenarium.dev
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/main.cjs.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d="5";typeof window<"u"&&((window.__svelte??={}).v??=new Set).add(d);var u;(l=>{function i(e,s,t){const n=e/2,a=s/2,r=Math.sqrt(n*n+a*a),h=Math.atan(a/n)*(180/Math.PI),o=t*(Math.PI/180);return t<180?t<90?t<h?{x:0,y:r*Math.sin(o)-a}:{x:r*Math.cos(o)-n,y:0}:t<180-h?{x:r*Math.cos(o)-n,y:0}:{x:-e,y:r*Math.sin(o)-a}:t<270?t<180+h?{x:-e,y:r*Math.sin(o)-a}:{x:r*Math.cos(o)-n,y:-s}:t<360-h?{x:r*Math.cos(o)-n,y:-s}:{x:0,y:r*Math.sin(o)-a}}l.getOffsets=i})(u||(u={}));var p;(l=>{async function i(s,t){const n=await fetch(s,t);if(!n.ok)throw new Error(n.statusText);return n.json()}l.get=i;async function e(s,t,n){const a=await fetch(s,{method:"POST",body:JSON.stringify(t),headers:{"Content-Type":"application/json",...n?.headers},...n});if(!a.ok)throw new Error(a.statusText);return a.json()}l.post=e})(p||(p={}));var m;(l=>{function i(r,h,o){return{x:s(h)*o,y:t(r)*o}}l.project=i;function e(r,h,o){return{lat:a(h/o),lng:n(r/o)}}l.unproject=e;function s(r){return(180+r)/360}function t(r){return(180-180/Math.PI*Math.log(Math.tan(Math.PI/4+r*Math.PI/360)))/360}function n(r){return r*360-180}function a(r){return 360/Math.PI*Math.atan(Math.exp((180-r*360)*Math.PI/180))-90}})(m||(m={}));var c;(l=>{l.COUNT=12,l.DEGREES=[0,30,60,90,120,150,180,210,240,270,300,330],l.DEGREES_DEFAULT=270})(c||(c={}));const y=()=>'<img src="https://arenarium.dev/favicon.svg" alt="Arenarium Maps" style="height: 1.25em; vertical-align: middle;" />',g=()=>`<a href="https://arenarium.dev" target="_blank" style="color: inherit;">${y()}<span> @arenarium/maps</span></a>`;class M{constructor(i,e,s,t){this.MapClass=i,this.MapMarkerClass=e,this.options=t,this.map=new this.MapClass(s,{...t}),(t.attribution||t.attribution==null)&&(this.map.addListener("idle",()=>{this.attributionObserver||(this.attributionObserver=new MutationObserver((n,a)=>{this.insertAttributionElement(),this.attributionElement!=null&&(this.updateAttributionElement(),a.disconnect())}),this.attributionObserver.observe(s,{childList:!0,subtree:!0}))}),this.map.addListener("bounds_changed",()=>{this.updateAttributionElement()}))}insertAttributionElement(){const i=this.map.getDiv();if(i==null)return;const e=i.getElementsByClassName("gmnoprint")[0];if(e==null||e.parentElement==null)return;const s=e.cloneNode(!0),t=s.childNodes.item(0)?.childNodes.item(1)?.childNodes.item(0);t!=null&&(t.title="",t.innerHTML=g(),e.parentElement.insertBefore(s,e),this.attributionElement=t)}updateAttributionElement(){const i=this.map.getDiv();if(i==null)return;const e=this.attributionElement?.childNodes.item(0)?.childNodes.item(1);e!=null&&(e.style.display=i.clientWidth>500?"initial":"none")}getParameters(){return{mapSize:256,zoomMin:this.options.minZoom??0,zoomMax:this.options.maxZoom??24,zoomScale:10}}getMap(){return this.map}getContainer(){return this.map.getDiv()}getZoom(){return this.map.getZoom()??NaN}getBounds(){const i=this.map.getBounds();if(i==null)return{sw:{lat:NaN,lng:NaN},ne:{lat:NaN,lng:NaN}};const e=i.getSouthWest(),s=i.getNorthEast();return{sw:{lat:e.lat(),lng:e.lng()},ne:{lat:s.lat(),lng:s.lng()}}}panBy(i,e){this.map.panBy(i,e)}createMarker(i,e,s,t){const n=new this.MapMarkerClass({position:{lat:e,lng:s},content:i,zIndex:t});return{inserted:()=>n.map!=null&&n.map==this.map,insert:()=>n.map=this.map,remove:()=>n.map=void 0,update:a=>n.zIndex=a}}}const f=[{elementType:"labels.icon",stylers:[{visibility:"off"}]},{stylers:[{saturation:-100},{lightness:-10}]},{featureType:"landscape",stylers:[{lightness:30}]},{featureType:"road",elementType:"geometry",stylers:[{saturation:-100}]}],b=[{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}]}];exports.GoogleMapDarkStyle=b;exports.GoogleMapLightStyle=f;exports.GoogleMapsProvider=M;
|
package/dist/main.d.ts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { MapBounds } from '@arenarium/maps';
|
|
2
|
+
import { MapProvider } from '@arenarium/maps';
|
|
3
|
+
import { MapProviderMarker } from '@arenarium/maps';
|
|
4
|
+
import { MapProviderParameters } from '@arenarium/maps';
|
|
5
|
+
|
|
6
|
+
export declare const GoogleMapDarkStyle: ({
|
|
7
|
+
elementType: string;
|
|
8
|
+
stylers: {
|
|
9
|
+
visibility: string;
|
|
10
|
+
}[];
|
|
11
|
+
featureType?: undefined;
|
|
12
|
+
} | {
|
|
13
|
+
stylers: {
|
|
14
|
+
saturation: number;
|
|
15
|
+
}[];
|
|
16
|
+
elementType?: undefined;
|
|
17
|
+
featureType?: undefined;
|
|
18
|
+
} | {
|
|
19
|
+
elementType: string;
|
|
20
|
+
stylers: {
|
|
21
|
+
lightness: number;
|
|
22
|
+
}[];
|
|
23
|
+
featureType?: undefined;
|
|
24
|
+
} | {
|
|
25
|
+
featureType: string;
|
|
26
|
+
elementType: string;
|
|
27
|
+
stylers: {
|
|
28
|
+
lightness: number;
|
|
29
|
+
}[];
|
|
30
|
+
})[];
|
|
31
|
+
|
|
32
|
+
export declare const GoogleMapLightStyle: ({
|
|
33
|
+
elementType: string;
|
|
34
|
+
stylers: {
|
|
35
|
+
visibility: string;
|
|
36
|
+
}[];
|
|
37
|
+
featureType?: undefined;
|
|
38
|
+
} | {
|
|
39
|
+
stylers: ({
|
|
40
|
+
saturation: number;
|
|
41
|
+
lightness?: undefined;
|
|
42
|
+
} | {
|
|
43
|
+
lightness: number;
|
|
44
|
+
saturation?: undefined;
|
|
45
|
+
})[];
|
|
46
|
+
elementType?: undefined;
|
|
47
|
+
featureType?: undefined;
|
|
48
|
+
} | {
|
|
49
|
+
featureType: string;
|
|
50
|
+
stylers: {
|
|
51
|
+
lightness: number;
|
|
52
|
+
}[];
|
|
53
|
+
elementType?: undefined;
|
|
54
|
+
} | {
|
|
55
|
+
featureType: string;
|
|
56
|
+
elementType: string;
|
|
57
|
+
stylers: {
|
|
58
|
+
saturation: number;
|
|
59
|
+
}[];
|
|
60
|
+
})[];
|
|
61
|
+
|
|
62
|
+
declare interface GoogleMapsClass {
|
|
63
|
+
new (container: HTMLElement, options: google.maps.MapOptions): google.maps.Map;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
declare interface GoogleMapsMarkerClass {
|
|
67
|
+
new (options: google.maps.marker.AdvancedMarkerElementOptions): google.maps.marker.AdvancedMarkerElement;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
declare interface GoogleMapsOptions extends google.maps.MapOptions {
|
|
71
|
+
attribution?: boolean;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export declare class GoogleMapsProvider implements MapProvider {
|
|
75
|
+
private MapClass;
|
|
76
|
+
private MapMarkerClass;
|
|
77
|
+
private map;
|
|
78
|
+
private options;
|
|
79
|
+
private attributionObserver;
|
|
80
|
+
private attributionElement;
|
|
81
|
+
constructor(mapClass: GoogleMapsClass, mapMarkerClass: GoogleMapsMarkerClass, container: HTMLElement, options: GoogleMapsOptions);
|
|
82
|
+
private insertAttributionElement;
|
|
83
|
+
private updateAttributionElement;
|
|
84
|
+
getParameters(): MapProviderParameters;
|
|
85
|
+
getMap(): google.maps.Map;
|
|
86
|
+
getContainer(): HTMLElement;
|
|
87
|
+
getZoom(): number;
|
|
88
|
+
getBounds(): MapBounds;
|
|
89
|
+
panBy(x: number, y: number): undefined;
|
|
90
|
+
createMarker(element: HTMLElement, lat: number, lng: number, zIndex: number): MapProviderMarker;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export { }
|
package/dist/main.es.js
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
typeof window < "u" && ((window.__svelte ??= {}).v ??= /* @__PURE__ */ new Set()).add("5");
|
|
2
|
+
var u;
|
|
3
|
+
((l) => {
|
|
4
|
+
function i(e, s, t) {
|
|
5
|
+
const n = e / 2, a = s / 2, r = Math.sqrt(n * n + a * a), h = Math.atan(a / n) * (180 / Math.PI), o = t * (Math.PI / 180);
|
|
6
|
+
return t < 180 ? t < 90 ? t < h ? {
|
|
7
|
+
x: 0,
|
|
8
|
+
y: r * Math.sin(o) - a
|
|
9
|
+
} : {
|
|
10
|
+
x: r * Math.cos(o) - n,
|
|
11
|
+
y: 0
|
|
12
|
+
} : t < 180 - h ? {
|
|
13
|
+
x: r * Math.cos(o) - n,
|
|
14
|
+
y: 0
|
|
15
|
+
} : {
|
|
16
|
+
x: -e,
|
|
17
|
+
y: r * Math.sin(o) - a
|
|
18
|
+
} : t < 270 ? t < 180 + h ? {
|
|
19
|
+
x: -e,
|
|
20
|
+
y: r * Math.sin(o) - a
|
|
21
|
+
} : {
|
|
22
|
+
x: r * Math.cos(o) - n,
|
|
23
|
+
y: -s
|
|
24
|
+
} : t < 360 - h ? {
|
|
25
|
+
x: r * Math.cos(o) - n,
|
|
26
|
+
y: -s
|
|
27
|
+
} : {
|
|
28
|
+
x: 0,
|
|
29
|
+
y: r * Math.sin(o) - a
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
l.getOffsets = i;
|
|
33
|
+
})(u || (u = {}));
|
|
34
|
+
var m;
|
|
35
|
+
((l) => {
|
|
36
|
+
async function i(s, t) {
|
|
37
|
+
const n = await fetch(s, t);
|
|
38
|
+
if (!n.ok) throw new Error(n.statusText);
|
|
39
|
+
return n.json();
|
|
40
|
+
}
|
|
41
|
+
l.get = i;
|
|
42
|
+
async function e(s, t, n) {
|
|
43
|
+
const a = await fetch(s, {
|
|
44
|
+
method: "POST",
|
|
45
|
+
body: JSON.stringify(t),
|
|
46
|
+
headers: {
|
|
47
|
+
"Content-Type": "application/json",
|
|
48
|
+
...n?.headers
|
|
49
|
+
},
|
|
50
|
+
...n
|
|
51
|
+
});
|
|
52
|
+
if (!a.ok) throw new Error(a.statusText);
|
|
53
|
+
return a.json();
|
|
54
|
+
}
|
|
55
|
+
l.post = e;
|
|
56
|
+
})(m || (m = {}));
|
|
57
|
+
var p;
|
|
58
|
+
((l) => {
|
|
59
|
+
function i(r, h, o) {
|
|
60
|
+
return {
|
|
61
|
+
x: s(h) * o,
|
|
62
|
+
y: t(r) * o
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
l.project = i;
|
|
66
|
+
function e(r, h, o) {
|
|
67
|
+
return {
|
|
68
|
+
lat: a(h / o),
|
|
69
|
+
lng: n(r / o)
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
l.unproject = e;
|
|
73
|
+
function s(r) {
|
|
74
|
+
return (180 + r) / 360;
|
|
75
|
+
}
|
|
76
|
+
function t(r) {
|
|
77
|
+
return (180 - 180 / Math.PI * Math.log(Math.tan(Math.PI / 4 + r * Math.PI / 360))) / 360;
|
|
78
|
+
}
|
|
79
|
+
function n(r) {
|
|
80
|
+
return r * 360 - 180;
|
|
81
|
+
}
|
|
82
|
+
function a(r) {
|
|
83
|
+
return 360 / Math.PI * Math.atan(Math.exp((180 - r * 360) * Math.PI / 180)) - 90;
|
|
84
|
+
}
|
|
85
|
+
})(p || (p = {}));
|
|
86
|
+
var c;
|
|
87
|
+
((l) => {
|
|
88
|
+
l.COUNT = 12, l.DEGREES = [0, 30, 60, 90, 120, 150, 180, 210, 240, 270, 300, 330], l.DEGREES_DEFAULT = 270;
|
|
89
|
+
})(c || (c = {}));
|
|
90
|
+
const d = () => '<img src="https://arenarium.dev/favicon.svg" alt="Arenarium Maps" style="height: 1.25em; vertical-align: middle;" />', y = () => `<a href="https://arenarium.dev" target="_blank" style="color: inherit;">${d()}<span> @arenarium/maps</span></a>`;
|
|
91
|
+
class g {
|
|
92
|
+
constructor(i, e, s, t) {
|
|
93
|
+
this.MapClass = i, this.MapMarkerClass = e, this.options = t, this.map = new this.MapClass(s, {
|
|
94
|
+
...t
|
|
95
|
+
}), (t.attribution || t.attribution == null) && (this.map.addListener("idle", () => {
|
|
96
|
+
this.attributionObserver || (this.attributionObserver = new MutationObserver((n, a) => {
|
|
97
|
+
this.insertAttributionElement(), this.attributionElement != null && (this.updateAttributionElement(), a.disconnect());
|
|
98
|
+
}), this.attributionObserver.observe(s, { childList: !0, subtree: !0 }));
|
|
99
|
+
}), this.map.addListener("bounds_changed", () => {
|
|
100
|
+
this.updateAttributionElement();
|
|
101
|
+
}));
|
|
102
|
+
}
|
|
103
|
+
insertAttributionElement() {
|
|
104
|
+
const i = this.map.getDiv();
|
|
105
|
+
if (i == null) return;
|
|
106
|
+
const e = i.getElementsByClassName("gmnoprint")[0];
|
|
107
|
+
if (e == null || e.parentElement == null) return;
|
|
108
|
+
const s = e.cloneNode(!0), t = s.childNodes.item(0)?.childNodes.item(1)?.childNodes.item(0);
|
|
109
|
+
t != null && (t.title = "", t.innerHTML = y(), e.parentElement.insertBefore(s, e), this.attributionElement = t);
|
|
110
|
+
}
|
|
111
|
+
updateAttributionElement() {
|
|
112
|
+
const i = this.map.getDiv();
|
|
113
|
+
if (i == null) return;
|
|
114
|
+
const e = this.attributionElement?.childNodes.item(0)?.childNodes.item(1);
|
|
115
|
+
e != null && (e.style.display = i.clientWidth > 500 ? "initial" : "none");
|
|
116
|
+
}
|
|
117
|
+
getParameters() {
|
|
118
|
+
return {
|
|
119
|
+
mapSize: 256,
|
|
120
|
+
zoomMin: this.options.minZoom ?? 0,
|
|
121
|
+
zoomMax: this.options.maxZoom ?? 24,
|
|
122
|
+
zoomScale: 10
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
getMap() {
|
|
126
|
+
return this.map;
|
|
127
|
+
}
|
|
128
|
+
getContainer() {
|
|
129
|
+
return this.map.getDiv();
|
|
130
|
+
}
|
|
131
|
+
getZoom() {
|
|
132
|
+
return this.map.getZoom() ?? NaN;
|
|
133
|
+
}
|
|
134
|
+
getBounds() {
|
|
135
|
+
const i = this.map.getBounds();
|
|
136
|
+
if (i == null) return { sw: { lat: NaN, lng: NaN }, ne: { lat: NaN, lng: NaN } };
|
|
137
|
+
const e = i.getSouthWest(), s = i.getNorthEast();
|
|
138
|
+
return { sw: { lat: e.lat(), lng: e.lng() }, ne: { lat: s.lat(), lng: s.lng() } };
|
|
139
|
+
}
|
|
140
|
+
panBy(i, e) {
|
|
141
|
+
this.map.panBy(i, e);
|
|
142
|
+
}
|
|
143
|
+
createMarker(i, e, s, t) {
|
|
144
|
+
const n = new this.MapMarkerClass({ position: { lat: e, lng: s }, content: i, zIndex: t });
|
|
145
|
+
return {
|
|
146
|
+
inserted: () => n.map != null && n.map == this.map,
|
|
147
|
+
insert: () => n.map = this.map,
|
|
148
|
+
remove: () => n.map = void 0,
|
|
149
|
+
update: (a) => n.zIndex = a
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
const f = [
|
|
154
|
+
{
|
|
155
|
+
elementType: "labels.icon",
|
|
156
|
+
stylers: [
|
|
157
|
+
{
|
|
158
|
+
visibility: "off"
|
|
159
|
+
}
|
|
160
|
+
]
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
stylers: [
|
|
164
|
+
{
|
|
165
|
+
saturation: -100
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
lightness: -10
|
|
169
|
+
}
|
|
170
|
+
]
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
featureType: "landscape",
|
|
174
|
+
stylers: [
|
|
175
|
+
{
|
|
176
|
+
lightness: 30
|
|
177
|
+
}
|
|
178
|
+
]
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
featureType: "road",
|
|
182
|
+
elementType: "geometry",
|
|
183
|
+
stylers: [
|
|
184
|
+
{
|
|
185
|
+
saturation: -100
|
|
186
|
+
}
|
|
187
|
+
]
|
|
188
|
+
}
|
|
189
|
+
], M = [
|
|
190
|
+
{
|
|
191
|
+
elementType: "labels.icon",
|
|
192
|
+
stylers: [
|
|
193
|
+
{
|
|
194
|
+
visibility: "off"
|
|
195
|
+
}
|
|
196
|
+
]
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
stylers: [
|
|
200
|
+
{
|
|
201
|
+
saturation: -100
|
|
202
|
+
}
|
|
203
|
+
]
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
elementType: "geometry",
|
|
207
|
+
stylers: [
|
|
208
|
+
{
|
|
209
|
+
lightness: -45
|
|
210
|
+
}
|
|
211
|
+
]
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
elementType: "labels.text.fill",
|
|
215
|
+
stylers: [
|
|
216
|
+
{
|
|
217
|
+
lightness: -100
|
|
218
|
+
}
|
|
219
|
+
]
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
elementType: "labels.text.stroke",
|
|
223
|
+
stylers: [
|
|
224
|
+
{
|
|
225
|
+
lightness: -15
|
|
226
|
+
}
|
|
227
|
+
]
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
featureType: "water",
|
|
231
|
+
elementType: "geometry",
|
|
232
|
+
stylers: [
|
|
233
|
+
{
|
|
234
|
+
lightness: -50
|
|
235
|
+
}
|
|
236
|
+
]
|
|
237
|
+
}
|
|
238
|
+
];
|
|
239
|
+
export {
|
|
240
|
+
M as GoogleMapDarkStyle,
|
|
241
|
+
f as GoogleMapLightStyle,
|
|
242
|
+
g as GoogleMapsProvider
|
|
243
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@arenarium/maps-integration-google",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"author": "arenarium.dev",
|
|
6
|
+
"description": "@arenarium/maps integration with Google Maps.",
|
|
7
|
+
"homepage": "https://arenarium.dev",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"arenarium",
|
|
10
|
+
"maps",
|
|
11
|
+
"google",
|
|
12
|
+
"google maps"
|
|
13
|
+
],
|
|
14
|
+
"type": "module",
|
|
15
|
+
"main": "./dist/main.cjs.js",
|
|
16
|
+
"module": "./dist/main.es.js",
|
|
17
|
+
"svelte": "./dist/main.es.js",
|
|
18
|
+
"types": "./dist/main.d.ts",
|
|
19
|
+
"unpkg": "./dist/main.js",
|
|
20
|
+
"jsdelivr": "./dist/main.js",
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"types": "./dist/main.d.ts",
|
|
24
|
+
"svelte": "./dist/main.es.js",
|
|
25
|
+
"import": "./dist/main.es.js",
|
|
26
|
+
"require": "./dist/main.cjs.js"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/node": "^24.5.2",
|
|
31
|
+
"vite": "^7.1.7",
|
|
32
|
+
"vite-plugin-dts": "^4.5.4",
|
|
33
|
+
"@arenarium/maps": "1.2.0",
|
|
34
|
+
"@arenarium/maps-shared": "1.0.0"
|
|
35
|
+
},
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"@googlemaps/js-api-loader": "^1.16.10",
|
|
38
|
+
"@types/google.maps": "^3.58.1"
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"lib_google_build": "vite build",
|
|
42
|
+
"lib_google_patch": "pnpm version patch --no-git-tag-version",
|
|
43
|
+
"lib_google_publish": "pnpm publish --access public"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { getAttributionHtml } from '@arenarium/maps';
|
|
2
|
+
import type { MapProvider, MapProviderParameters, MapProviderMarker, MapBounds } from '@arenarium/maps';
|
|
3
|
+
|
|
4
|
+
interface GoogleMapsClass {
|
|
5
|
+
new (container: HTMLElement, options: google.maps.MapOptions): google.maps.Map;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
interface GoogleMapsMarkerClass {
|
|
9
|
+
new (options: google.maps.marker.AdvancedMarkerElementOptions): google.maps.marker.AdvancedMarkerElement;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface GoogleMapsOptions extends google.maps.MapOptions {
|
|
13
|
+
attribution?: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export class GoogleMapsProvider implements MapProvider {
|
|
17
|
+
private MapClass: GoogleMapsClass;
|
|
18
|
+
private MapMarkerClass: GoogleMapsMarkerClass;
|
|
19
|
+
|
|
20
|
+
private map: google.maps.Map;
|
|
21
|
+
private options: google.maps.MapOptions;
|
|
22
|
+
|
|
23
|
+
private attributionObserver: MutationObserver | undefined;
|
|
24
|
+
private attributionElement: HTMLElement | undefined;
|
|
25
|
+
|
|
26
|
+
constructor(mapClass: GoogleMapsClass, mapMarkerClass: GoogleMapsMarkerClass, container: HTMLElement, options: GoogleMapsOptions) {
|
|
27
|
+
this.MapClass = mapClass;
|
|
28
|
+
this.MapMarkerClass = mapMarkerClass;
|
|
29
|
+
|
|
30
|
+
this.options = options;
|
|
31
|
+
this.map = new this.MapClass(container, {
|
|
32
|
+
...options
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
if (options.attribution || options.attribution == undefined) {
|
|
36
|
+
// Add attribution element
|
|
37
|
+
this.map.addListener('idle', () => {
|
|
38
|
+
if (this.attributionObserver) return;
|
|
39
|
+
|
|
40
|
+
this.attributionObserver = new MutationObserver((_, observer) => {
|
|
41
|
+
// Try to insert attribution element
|
|
42
|
+
this.insertAttributionElement();
|
|
43
|
+
// If insertion failed, return
|
|
44
|
+
if (this.attributionElement == undefined) return;
|
|
45
|
+
// Update attribution element
|
|
46
|
+
this.updateAttributionElement();
|
|
47
|
+
// Disconnect observer
|
|
48
|
+
observer.disconnect();
|
|
49
|
+
});
|
|
50
|
+
this.attributionObserver.observe(container, { childList: true, subtree: true });
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
this.map.addListener('bounds_changed', () => {
|
|
54
|
+
// Update attribution element
|
|
55
|
+
this.updateAttributionElement();
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
private insertAttributionElement() {
|
|
61
|
+
// Get map container
|
|
62
|
+
const container = this.map.getDiv();
|
|
63
|
+
if (container == undefined) return;
|
|
64
|
+
|
|
65
|
+
// Find bottom right attribution elements first child
|
|
66
|
+
const attributionElementsFirstChild = container.getElementsByClassName('gmnoprint')[0];
|
|
67
|
+
if (attributionElementsFirstChild == undefined) return;
|
|
68
|
+
if (attributionElementsFirstChild.parentElement == undefined) return;
|
|
69
|
+
|
|
70
|
+
// Clone attribution element
|
|
71
|
+
const attributionWrapper = attributionElementsFirstChild.cloneNode(true) as HTMLElement;
|
|
72
|
+
|
|
73
|
+
// Find attribution wrapper target child
|
|
74
|
+
const attributionWrapperTargetChild = attributionWrapper.childNodes.item(0)?.childNodes.item(1)?.childNodes.item(0) as HTMLElement;
|
|
75
|
+
if (attributionWrapperTargetChild == undefined) return;
|
|
76
|
+
|
|
77
|
+
// Set attribution wrapper target child inner HTML
|
|
78
|
+
attributionWrapperTargetChild.title = '';
|
|
79
|
+
attributionWrapperTargetChild.innerHTML = getAttributionHtml();
|
|
80
|
+
|
|
81
|
+
// Insert attribution wrapper before attribution elements first child
|
|
82
|
+
attributionElementsFirstChild.parentElement.insertBefore(attributionWrapper, attributionElementsFirstChild);
|
|
83
|
+
|
|
84
|
+
// Assign attribution element
|
|
85
|
+
this.attributionElement = attributionWrapperTargetChild;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
private updateAttributionElement() {
|
|
89
|
+
// Get map container
|
|
90
|
+
const container = this.map.getDiv();
|
|
91
|
+
if (container == undefined) return;
|
|
92
|
+
|
|
93
|
+
// Get attribution element span
|
|
94
|
+
const attributionElementSpan = this.attributionElement?.childNodes.item(0)?.childNodes.item(1) as HTMLElement;
|
|
95
|
+
if (attributionElementSpan == undefined) return;
|
|
96
|
+
|
|
97
|
+
// Set attribution element span display
|
|
98
|
+
attributionElementSpan.style.display = container.clientWidth > 500 ? 'initial' : 'none';
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
public getParameters(): MapProviderParameters {
|
|
102
|
+
return {
|
|
103
|
+
mapSize: 256,
|
|
104
|
+
zoomMin: this.options.minZoom ?? 0,
|
|
105
|
+
zoomMax: this.options.maxZoom ?? 24,
|
|
106
|
+
zoomScale: 10
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
public getMap(): google.maps.Map {
|
|
111
|
+
return this.map;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
public getContainer(): HTMLElement {
|
|
115
|
+
return this.map.getDiv();
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
public getZoom(): number {
|
|
119
|
+
return this.map.getZoom() ?? NaN;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
public getBounds(): MapBounds {
|
|
123
|
+
const bounds = this.map.getBounds();
|
|
124
|
+
if (bounds == undefined) return { sw: { lat: NaN, lng: NaN }, ne: { lat: NaN, lng: NaN } };
|
|
125
|
+
|
|
126
|
+
const sw = bounds.getSouthWest();
|
|
127
|
+
const ne = bounds.getNorthEast();
|
|
128
|
+
return { sw: { lat: sw.lat(), lng: sw.lng() }, ne: { lat: ne.lat(), lng: ne.lng() } };
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
public panBy(x: number, y: number): undefined {
|
|
132
|
+
this.map.panBy(x, y);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
public createMarker(element: HTMLElement, lat: number, lng: number, zIndex: number): MapProviderMarker {
|
|
136
|
+
const marker = new this.MapMarkerClass({ position: { lat, lng }, content: element, zIndex });
|
|
137
|
+
return {
|
|
138
|
+
inserted: () => marker.map != undefined && marker.map == this.map,
|
|
139
|
+
insert: () => (marker.map = this.map),
|
|
140
|
+
remove: () => (marker.map = undefined),
|
|
141
|
+
update: (zIndex: number) => (marker.zIndex = zIndex)
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
export const GoogleMapLightStyle = [
|
|
2
|
+
{
|
|
3
|
+
elementType: 'labels.icon',
|
|
4
|
+
stylers: [
|
|
5
|
+
{
|
|
6
|
+
visibility: 'off'
|
|
7
|
+
}
|
|
8
|
+
]
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
stylers: [
|
|
12
|
+
{
|
|
13
|
+
saturation: -100
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
lightness: -10
|
|
17
|
+
}
|
|
18
|
+
]
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
featureType: 'landscape',
|
|
22
|
+
stylers: [
|
|
23
|
+
{
|
|
24
|
+
lightness: 30
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
featureType: 'road',
|
|
30
|
+
elementType: 'geometry',
|
|
31
|
+
stylers: [
|
|
32
|
+
{
|
|
33
|
+
saturation: -100
|
|
34
|
+
}
|
|
35
|
+
]
|
|
36
|
+
}
|
|
37
|
+
];
|
|
38
|
+
|
|
39
|
+
export const GoogleMapDarkStyle = [
|
|
40
|
+
{
|
|
41
|
+
elementType: 'labels.icon',
|
|
42
|
+
stylers: [
|
|
43
|
+
{
|
|
44
|
+
visibility: 'off'
|
|
45
|
+
}
|
|
46
|
+
]
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
stylers: [
|
|
50
|
+
{
|
|
51
|
+
saturation: -100
|
|
52
|
+
}
|
|
53
|
+
]
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
elementType: 'geometry',
|
|
57
|
+
stylers: [
|
|
58
|
+
{
|
|
59
|
+
lightness: -45
|
|
60
|
+
}
|
|
61
|
+
]
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
elementType: 'labels.text.fill',
|
|
65
|
+
stylers: [
|
|
66
|
+
{
|
|
67
|
+
lightness: -100
|
|
68
|
+
}
|
|
69
|
+
]
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
elementType: 'labels.text.stroke',
|
|
73
|
+
stylers: [
|
|
74
|
+
{
|
|
75
|
+
lightness: -15
|
|
76
|
+
}
|
|
77
|
+
]
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
featureType: 'water',
|
|
81
|
+
elementType: 'geometry',
|
|
82
|
+
stylers: [
|
|
83
|
+
{
|
|
84
|
+
lightness: -50
|
|
85
|
+
}
|
|
86
|
+
]
|
|
87
|
+
}
|
|
88
|
+
];
|
package/src/main.ts
ADDED
package/tsconfig.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"allowJs": true,
|
|
4
|
+
"checkJs": true,
|
|
5
|
+
"esModuleInterop": true,
|
|
6
|
+
"forceConsistentCasingInFileNames": true,
|
|
7
|
+
"resolveJsonModule": true,
|
|
8
|
+
"skipLibCheck": true,
|
|
9
|
+
"sourceMap": true,
|
|
10
|
+
"strict": true,
|
|
11
|
+
"outDir": "dist",
|
|
12
|
+
"declaration": true,
|
|
13
|
+
"declarationDir": "dist",
|
|
14
|
+
"emitDeclarationOnly": true,
|
|
15
|
+
"module": "NodeNext",
|
|
16
|
+
"moduleResolution": "NodeNext",
|
|
17
|
+
"types": ["vite/client", "./node_modules/@types/google.maps/index.d.ts"]
|
|
18
|
+
}
|
|
19
|
+
}
|
package/vite.config.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { defineConfig } from 'vite';
|
|
2
|
+
import dts from 'vite-plugin-dts';
|
|
3
|
+
|
|
4
|
+
export default defineConfig({
|
|
5
|
+
plugins: [
|
|
6
|
+
dts({
|
|
7
|
+
rollupTypes: true,
|
|
8
|
+
insertTypesEntry: true,
|
|
9
|
+
entryRoot: './src',
|
|
10
|
+
copyDtsFiles: true,
|
|
11
|
+
exclude: ['**/node_modules/**']
|
|
12
|
+
})
|
|
13
|
+
],
|
|
14
|
+
build: {
|
|
15
|
+
lib: {
|
|
16
|
+
entry: './src/main.ts',
|
|
17
|
+
name: 'ArenariumMapsIntegrationGoogle',
|
|
18
|
+
formats: ['es', 'cjs'],
|
|
19
|
+
fileName: (format, entryName) => `${entryName}.${format}.js`,
|
|
20
|
+
cssFileName: 'style'
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
});
|