@arenarium/maps 1.2.1 → 1.2.3

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/README.md CHANGED
@@ -1,309 +1,16 @@
1
- # Installation
2
-
3
- ## NPM
4
-
5
- To install the `@aranarium/maps` library using npm, run the following command in your project directory:
6
-
7
- ```
8
- npm install @arenarium/maps
9
- ```
10
-
11
- Import the necessary module and CSS file into your project to begin using the map:
12
-
13
- ```js
14
- import { MapManager } from '@arenarium/maps';
15
- import '@arenarium/maps/dist/style.css';
16
-
17
- // Initialize and mount the map manager (further configuration details follow)
18
- const mapManager = new MapManager(...);
19
- ```
20
-
21
- ## CDN
22
-
23
- To include `@aranarium/maps` directly in your HTML via a Content Delivery Network (CDN), add these script and stylesheet tags to the `<head>` or `<body>` of your HTML document:
24
-
25
- ```html
26
- <script src="https://unpkg.com/maplibre-gl@^5.6.0/dist/maplibre-gl.js"></script>
27
- <link href="https://unpkg.com/maplibre-gl@^5.6.0/dist/maplibre-gl.css" rel="stylesheet" />
28
-
29
- <script src="https://unpkg.com/@arenarium/maps@^1.0.124/dist/index.js"></script>
30
- <link href="https://unpkg.com/@arenarium/maps@^1.0.124/dist/style.css" rel="stylesheet" />
31
- ```
32
-
33
- Once included, you can access the library's functions through the global `arenarium` object to mount the map:
34
-
35
- ```js
36
- // Initialize and mount the map manager (further configuration details follow)
37
- const mapManager = new arenarium.MapManager(...);
38
- ```
39
-
40
- # Usage
41
-
42
- ## Initialization
43
-
44
- To initialize the map, first add a container element to your HTML where the map will be rendered. Then go to the [API Keys](https://arenarium.dev/keys) page and create a new API key. Then depending on the map library used there are different instructions:
45
-
46
- ```html
47
- <div id="map"></div>
48
- ```
49
-
50
- ## Maplibre GL
51
-
52
- First, install the `maplibre-gl` library:
53
-
54
- ```
55
- npm install maplibre-gl
56
- ```
57
-
58
- Next, create a `MapLibreProvider` instance which requires a `maplibre.Map` class, a `maplibre.Marker` class and a `maplibre.MapOptions` object. Use the `MapLibreProvider` instance, along with the API key, to initialize the map manager.
59
-
60
- ```js
61
- import maplibregl from 'maplibre-gl';
62
- import 'maplibre-gl/dist/maplibre-gl.css';
63
-
64
- import { MapManager } from '@arenarium/maps';
65
- import { MapLibreProvider } from '@arenarium/maps/maplibre';
66
- import '@arenarium/maps/dist/style.css';
67
-
68
- // Create a maplibre provider instance
69
- const maplibreProvider = new MapLibreProvider(maplibregl.Map, maplibregl.Marker, {
70
- container: 'map',
71
- ...
72
- });
73
-
74
- // Initialize the map manager with the provider
75
- const mapManager = new MapManager("YOUR_API_KEY", maplibreProvider);
76
-
77
- // Access the maplibre instance for direct map interactions
78
- const maplibreMap = mapLibreProvider.getMap();
79
- ```
80
-
81
- You can change the map's visual appearance by setting a predefined dark or light theme:
82
-
83
- ```js
84
- import { MaplibreDarkStyle, MaplibreLightStyle } from '@arenarium/maps/maplibre';
85
-
86
- maplibreMap.setStyle(MaplibreDarkStyle); // or MaplibreLightStyle
87
- ```
88
-
89
- Alternatively, you can apply a custom map style by providing a URL to a JSON file that adheres to the [MapLibre Style Specification](https://maplibre.org/maplibre-style-spec/). You can also override specific color properties within a custom style.
90
-
91
- ```js
92
- mapLibre.setStyle('https://tiles.openfreemap.org/styles/liberty.json');
93
- ```
94
-
95
- ## Mapbox GL
96
-
97
- First, install the `mapbox-gl` library:
98
-
99
- ```
100
- npm install mapbox-gl
101
- ```
102
-
103
- Next, create a `MapboxProvider` instance which requires a `mapbox.Map` class, a `mapbox.Marker` class and a `mapbox.MapOptions` object. Use the `MapboxProvider` instance, along with the API key, to initialize the map manager.
104
-
105
- ```js
106
- import mapbox from 'mapbox-gl';
107
- import 'mapbox-gl/dist/mapbox-gl.css';
108
-
109
- import { MapManager } from '@arenarium/maps';
110
- import { MapboxProvider } from '@arenarium/maps/mapbox';
111
- import '@arenarium/maps/dist/style.css';
112
-
113
- // Create a mapbox provider instance
114
- const mapboxProvider = new MapboxProvider(mapbox.Map, mapbox.Marker, {
115
- container: 'map',
116
- ...
117
- });
118
-
119
- // Initialize the map manager with the provider
120
- const mapManager = new MapManager("YOUR_API_KEY", mapboxProvider);
121
-
122
- // Access the mapbox instance for direct map interactions
123
- const mapboxMap = mapboxProvider.getMap();
124
- ```
125
-
126
- ## Google Maps
127
-
128
- First, install the `@googlemaps/js-api-loader` library:
129
-
130
- ```
131
- npm install @googlemaps/js-api-loader
132
- ```
133
-
134
- To use Google Maps, you'll need to load the Google Maps JavaScript API and create a Google Maps provider instance. Next, create a `GoogleMapsProvider` instance which requires a `google.maps.Map` class, a `google.maps.Marker.AdvancedMarkerElement` class, and a `google.maps.MapOptions`. Use the `GoogleMapsProvider` instance, along with the API key, to initialize the map manager.
135
-
136
- ```js
137
- import { Loader } from '@googlemaps/js-api-loader';
138
-
139
- import { MapManager } from '@arenarium/maps';
140
- import { GoogleMapsProvider } from '@arenarium/maps/google';
141
- import '@arenarium/maps/dist/style.css';
142
-
143
- // Load Google Maps API
144
- const loader = new Loader({
145
- apiKey: 'YOUR_GOOGLE_MAPS_API_KEY',
146
- version: 'weekly'
147
- });
148
-
149
- // Import required libraries
150
- const mapsLibrary = await loader.importLibrary('maps');
151
- const markerLibrary = await loader.importLibrary('marker');
152
-
153
- // Create a Google Maps provider instance
154
- const mapElement = document.getElementById('map')!;
155
- const mapGoogleProvider = new GoogleMapsProvider(mapsLibrary.Map, markerLibrary.AdvancedMarkerElement, mapElement, {
156
- mapId: 'YOUR_GOOGLE_MAPS_MAP_ID', // For enabling advanced marker elements
157
- ...
158
- });
159
-
160
- // Initialize the map manager with the provider
161
- const mapManager = new MapManager("YOUR_API_KEY", mapGoogleProvider);
162
-
163
- // Access the Google Maps instance for direct map interactions
164
- const mapGoogle = mapGoogleProvider.getMap();
165
- ```
166
-
167
- You can change the map's visual appearance by using the predefined styles in combination with custom `StyledMapType`:
168
-
169
- ```js
170
- import { GoogleMapsDarkStyle, GoogleMapsLightStyle } from '@arenarium/maps/google';
171
-
172
- const mapTypeLight = new google.maps.StyledMapType(GoogleMapsLightStyle, { name: 'Light Map' });
173
- const mapTypeDark = new google.maps.StyledMapType(GoogleMapsDarkStyle, { name: 'Dark Map' });
174
-
175
- mapGoogle.mapTypes.set('light-id', mapTypeLight);
176
- mapGoogle.mapTypes.set('dark-id', mapTypeDark);
177
-
178
- mapGoogle.setMapTypeId('light-id'); // or "dark-id" for dark theme
179
- ```
180
-
181
- ## Markers
182
-
183
- A marker consist of a pin, a tooltip and an optional popup. The pin is an element that should convey the marker's location and and basic information like an icon or a color. The tooltip is an element that should provide additional information thats needs to be readable, it could be small or large amount of information depending on the application. The popup is an element that should be displayed when the user clicks on the marker. It should contain additional information thats not necessary or too large for a tooltip.
184
-
185
- The markers toogle between the pin and the tooltip elements as the user zoom in. The pin is displayed when there is no room for the tooltip. When the user zooms in and more space is available, more tooltips are displayed. Which tooltips are displayed first is determined by the ranking of the markers. The higher the rank, the sooner the tooltip is displayed.
186
-
187
- To add markers to the map, you first need to define an array of `MapMarker` objects. Provide the base marker data and the configuration for the tooltip, pin and popup. The configurations have body callbacks which should return a `HTMLElement`.
188
-
189
- Use the `updateMarkers` method on the map manager to display or update update the markers. This method adds new markers and updates existing ones based on their IDs. Markers not present in the provided array will remain on the map. This approach is designed for continuous updates of map markers.
190
-
191
- ```js
192
- import { type MapMarker } from '@arenarium/maps';
193
-
194
- const markers: MapMarker[] = [];
195
-
196
- for (let i = 0; i < count; i++) {
197
- markers.push({
198
- // A unique identifier for the marker
199
- id: ...,
200
- // The ranking of the marker, used for prioritization
201
- rank: ..,
202
- // The latitude of the marker's location
203
- lat: ...,
204
- // The longitude of the marker's location
205
- lng: ...,
206
- // The tooltip configuration of the marker (required)
207
- tooltip: {
208
- style: {
209
- // The desired height of the marker's tooltip area
210
- height: ...,
211
- // The desired width of the marker's tooltip area
212
- width: ...,
213
- // The desired margin of the marker's tooltip area
214
- margin: ...,
215
- // The desired radius of the marker's tooltip area
216
- radius: ...,
217
- },
218
- // Callback function that returns the HTMLElement object for the tooltip body
219
- body: async (id) => { ... }
220
- },
221
- // The pin configuration of the marker (optional)
222
- pin: {
223
- style: {
224
- // The desired height of the marker's pin area
225
- height: ...,
226
- // The desired width of the marker's pin area
227
- width: ...,
228
- // The desired radius of the marker's pin area
229
- radius: ...,
230
- },
231
- // Callback function that returns the HTMLElement object for the pin body
232
- body: async (id) => { ... }
233
- },
234
- // The popup configuration of the marker (optional)
235
- popup: {
236
- style: {
237
- // The desired height of the marker's popup area
238
- height: ...,
239
- // The desired width of the marker's popup area
240
- width: ...,
241
- // The desired margin of the marker's popup area
242
- margin: ...,
243
- // The desired radius of the marker's popup area
244
- radius: ...,
245
- },
246
- // Callback function that returns the HTMLElement object for the popup body
247
- body: async (id) => { ... }
248
- }
249
- });
250
- }
251
-
252
- await mapManager.updateMarkers(markers);
253
- ```
254
-
255
- To remove all markers from the map, use the `removeMarkers` method:
256
-
257
- ```js
258
- mapManager.removeMarkers();
259
- ```
260
-
261
- To toggle the popup of a marker, use the `showPopup` and `hidePopup` methods:
262
-
263
- ```js
264
- mapManager.showPopup(id);
265
- mapManager.hidePopup(id);
266
- ```
267
-
268
- ## Style
269
-
270
- You can change the markers style by using the predefined CSS variables:
271
-
272
- ```scss
273
- --arenarium-maps-pin-background: ...;
274
- --arenarium-maps-pin-border: ...;
275
- --arenarium-maps-pin-shadow: ...;
276
-
277
- --arenarium-maps-tooltip-background: ...;
278
- --arenarium-maps-tooltip-shadow: ...;
279
- --arenarium-maps-tooltip-shadow-hover: ...;
280
- ```
1
+ # About
281
2
 
282
- # API
3
+ Visualize complex map markers clearly. A JavaScript library for effective display of map markers, compatible with MapLibre, Mapbox, and Google Maps.
283
4
 
284
- You can provide a your own backend URL to the map manager to use the API for calculating the marker states. For more information about the API, please feel free to reach out.
5
+ # Docs
285
6
 
286
- ```js
287
- const mapManager = new MapManager(mapProvider, {
288
- api: {
289
- states: {
290
- url: 'YOUR_BACKEND_URL'
291
- }
292
- }
293
- });
294
- ```
7
+ https://arenarium.dev/docs
295
8
 
296
9
  # Examples
297
10
 
298
11
  [https://github.com/arenarium-dev/arenarium-maps-svelte-kit-example](https://github.com/arenarium-dev/arenarium-maps-svelte-kit-example)
299
12
 
300
- # About
301
-
302
- **@arenarium/maps** is a library designed for the efficient visualization of a large number of ranked points of interest on your maps. It excels in scenarios where you need to present numerous location-based markers with a clear visual hierarchy based on their importance or ranking. By leveraging optimized rendering techniques and a dedicated API for managing dynamic marker states, this library ensures a smooth and informative user experience.
303
-
304
- # Docs
305
-
306
- https://arenarium.dev/docs
13
+ [https://github.com/arenarium-dev/arenarium-maps-react-example](https://github.com/arenarium-dev/arenarium-maps-react-example)
307
14
 
308
15
  # License
309
16
 
package/dist/main.css ADDED
@@ -0,0 +1,81 @@
1
+ .pin.svelte-10kxbrm {
2
+ position: absolute;
3
+ border-style: solid;
4
+ box-sizing: border-box;
5
+ transform-origin: 0% 0%;
6
+ transform: translate(-50%, -50%);
7
+ backface-visibility: hidden;
8
+ will-change: scale;
9
+ }
10
+ .pin.svelte-10kxbrm {
11
+ display: none;
12
+ content-visibility: hidden;
13
+ }
14
+ .pin.displayed.svelte-10kxbrm {
15
+ display: initial;
16
+ content-visibility: initial;
17
+ }
18
+ .pin.svelte-10kxbrm {
19
+ opacity: 1;
20
+ }
21
+ .pin.suppressed.svelte-10kxbrm {
22
+ opacity: 0.5;
23
+ box-shadow: none !important;
24
+ }
25
+
26
+ .element.svelte-1no6o2a {
27
+ box-sizing: border-box;
28
+ }
29
+ .anchor.svelte-1no6o2a {
30
+ display: block;
31
+ position: absolute;
32
+ width: 0px;
33
+ height: 0px;
34
+ transition: filter ease-in-out 125ms;
35
+ }
36
+ .anchor.svelte-1no6o2a .pointer:where(.svelte-1no6o2a) {
37
+ position: absolute;
38
+ left: 0px;
39
+ top: 0px;
40
+ border-radius: 1px;
41
+ transform-origin: 0% 0%;
42
+ }
43
+ .anchor.svelte-1no6o2a .tooltip:where(.svelte-1no6o2a) {
44
+ position: absolute;
45
+ left: 0px;
46
+ top: 0px;
47
+ }
48
+ .anchor.svelte-1no6o2a .tooltip:where(.svelte-1no6o2a) .body:where(.svelte-1no6o2a) {
49
+ cursor: pointer;
50
+ }
51
+ .anchor.svelte-1no6o2a {
52
+ opacity: 0;
53
+ will-change: opacity;
54
+ }
55
+ .anchor.svelte-1no6o2a .pointer:where(.svelte-1no6o2a) {
56
+ scale: 0;
57
+ transform-origin: 0% 0%;
58
+ will-change: transform, scale;
59
+ }
60
+ .anchor.svelte-1no6o2a .tooltip:where(.svelte-1no6o2a) {
61
+ scale: 0;
62
+ transform-origin: 0% 0%;
63
+ will-change: transform, scale;
64
+ }
65
+ .anchor.svelte-1no6o2a {
66
+ display: none;
67
+ content-visibility: hidden;
68
+ }
69
+ .anchor.displayed.svelte-1no6o2a {
70
+ display: initial;
71
+ content-visibility: initial;
72
+ }
73
+ .body.svelte-1no6o2a {
74
+ backface-visibility: initial;
75
+ transform-style: initial;
76
+ }
77
+ .body.svelte-1no6o2a:hover {
78
+ backface-visibility: hidden;
79
+ transform-style: preserve-3d;
80
+ }
81
+