travels-map 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.md +20 -0
- package/README.md +112 -0
- package/dist/travels-map/TravelsMapElement.d.ts +34 -0
- package/dist/travels-map/index.d.ts +3 -0
- package/dist/travels-map/legends.d.ts +8 -0
- package/dist/travels-map/map.d.ts +17 -0
- package/dist/travels-map/types.d.ts +8 -0
- package/dist/travels-map/utils.d.ts +6 -0
- package/dist/travels-map.js +6532 -0
- package/package.json +60 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017-2026 Robert Marsal
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
7
|
+
the Software without restriction, including without limitation the rights to
|
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
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, FITNESS
|
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# Travels
|
|
2
|
+
|
|
3
|
+
[](https://opensource.org/licenses/MIT)
|
|
4
|
+
|
|
5
|
+
Reusable travel map web component for any website.
|
|
6
|
+
|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
See a live demo here: [https://robertmarsal.com/travels/](https://robertmarsal.com/travels/)
|
|
10
|
+
|
|
11
|
+
## What it is
|
|
12
|
+
|
|
13
|
+
This package exposes a custom element:
|
|
14
|
+
|
|
15
|
+
```html
|
|
16
|
+
<travels-map></travels-map>
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
It is framework-agnostic, so it can be used in plain HTML, React, Vue, Svelte,
|
|
20
|
+
Astro, or any other frontend that can load a browser module.
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
```sh
|
|
25
|
+
npm install travels-map
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Local development
|
|
29
|
+
|
|
30
|
+
```sh
|
|
31
|
+
git clone https://github.com/robertmarsal/travels.git
|
|
32
|
+
cd travels
|
|
33
|
+
npm install
|
|
34
|
+
npm run dev
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Demo
|
|
38
|
+
|
|
39
|
+
The repository includes a local demo app for development and manual testing.
|
|
40
|
+
|
|
41
|
+
Run it with:
|
|
42
|
+
|
|
43
|
+
```sh
|
|
44
|
+
npm run dev
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Then edit [`src/demo/data.ts`](./src/demo/data.ts) to change the sample points
|
|
48
|
+
shown in the demo.
|
|
49
|
+
|
|
50
|
+
## Usage
|
|
51
|
+
|
|
52
|
+
### Plain HTML with remote JSON
|
|
53
|
+
|
|
54
|
+
```html
|
|
55
|
+
<travels-map
|
|
56
|
+
data-src="/travels.json"
|
|
57
|
+
theme="dark-monochrome"
|
|
58
|
+
marker-color="#ff0066"
|
|
59
|
+
center="38.957083,-39.074225"
|
|
60
|
+
zoom="3"
|
|
61
|
+
show-legends="true"
|
|
62
|
+
></travels-map>
|
|
63
|
+
|
|
64
|
+
<script type="module" src="/dist/travels-map.js"></script>
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Your JSON can be either:
|
|
68
|
+
|
|
69
|
+
```json
|
|
70
|
+
{
|
|
71
|
+
"points": [
|
|
72
|
+
{ "lat": 51.500736, "lng": -0.124625, "title": "London - United Kingdom" }
|
|
73
|
+
]
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
or a raw array of point objects.
|
|
78
|
+
|
|
79
|
+
### JavaScript property API
|
|
80
|
+
|
|
81
|
+
```js
|
|
82
|
+
import "travels-map";
|
|
83
|
+
|
|
84
|
+
const map = document.querySelector("travels-map");
|
|
85
|
+
map.markerColor = "#00d1b2";
|
|
86
|
+
map.points = [
|
|
87
|
+
{ lat: 51.500736, lng: -0.124625, title: "London - United Kingdom" },
|
|
88
|
+
];
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Public API
|
|
92
|
+
|
|
93
|
+
Attributes:
|
|
94
|
+
|
|
95
|
+
- `data-src`: URL returning JSON data
|
|
96
|
+
- `theme`: currently `dark-monochrome`
|
|
97
|
+
- `marker-color`: optional CSS color for the dots
|
|
98
|
+
- `center`: fallback map center as `"lat,lng"`
|
|
99
|
+
- `zoom`: fallback zoom level when there are no points
|
|
100
|
+
- `show-legends`: set to `"false"` to hide legends
|
|
101
|
+
- `tiles-url`: optional custom tile URL template
|
|
102
|
+
|
|
103
|
+
Properties:
|
|
104
|
+
|
|
105
|
+
- `points`: array of `{ lat, lng, title }`
|
|
106
|
+
- `markerColor`: optional color string for the dots
|
|
107
|
+
|
|
108
|
+
Styling:
|
|
109
|
+
|
|
110
|
+
- The component uses shadow DOM.
|
|
111
|
+
- You can theme it with CSS custom properties on `travels-map`, such as
|
|
112
|
+
`--travels-marker`, `--travels-panel-bg`, and `--travels-map-bg`.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { TravelPoint } from "./types";
|
|
2
|
+
export declare class TravelsMapElement extends HTMLElement {
|
|
3
|
+
static get observedAttributes(): string[];
|
|
4
|
+
private map;
|
|
5
|
+
private tileLayer;
|
|
6
|
+
private tileUrl;
|
|
7
|
+
private markerLayer;
|
|
8
|
+
private legendControls;
|
|
9
|
+
private resizeObserver;
|
|
10
|
+
private pointsValue;
|
|
11
|
+
private dataRequestId;
|
|
12
|
+
private readonly mapElement;
|
|
13
|
+
private readonly locationsLegendElement;
|
|
14
|
+
private readonly countriesLegendElement;
|
|
15
|
+
constructor();
|
|
16
|
+
connectedCallback(): void;
|
|
17
|
+
disconnectedCallback(): void;
|
|
18
|
+
attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void;
|
|
19
|
+
get points(): TravelPoint[];
|
|
20
|
+
set points(value: unknown);
|
|
21
|
+
get markerColor(): string | null;
|
|
22
|
+
set markerColor(value: string | null);
|
|
23
|
+
private loadConfiguredData;
|
|
24
|
+
private ensureMap;
|
|
25
|
+
private setupResizeObserver;
|
|
26
|
+
private getTheme;
|
|
27
|
+
private applyTheme;
|
|
28
|
+
private applyMarkerColor;
|
|
29
|
+
private getCenter;
|
|
30
|
+
private getZoom;
|
|
31
|
+
private getShowLegends;
|
|
32
|
+
private getTileUrl;
|
|
33
|
+
private render;
|
|
34
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type Control, type Map } from "leaflet";
|
|
2
|
+
import type { TravelPoint } from "./types";
|
|
3
|
+
type LegendElements = {
|
|
4
|
+
countries: HTMLDivElement;
|
|
5
|
+
locations: HTMLDivElement;
|
|
6
|
+
};
|
|
7
|
+
export declare function updateLegends(map: Map, points: TravelPoint[], showLegends: boolean, legendElements: LegendElements, existingControls: Control[]): Control[];
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type LayerGroup, type Map, type TileLayer } from "leaflet";
|
|
2
|
+
import type { TravelPoint } from "./types";
|
|
3
|
+
export declare const DEFAULT_CENTER: [number, number];
|
|
4
|
+
export declare const DEFAULT_ZOOM = 3;
|
|
5
|
+
export declare const DEFAULT_TILE_URL = "https://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}{r}.png";
|
|
6
|
+
export declare const DEFAULT_TILE_OPTIONS: {
|
|
7
|
+
maxZoom: number;
|
|
8
|
+
subdomains: string;
|
|
9
|
+
attribution: string;
|
|
10
|
+
};
|
|
11
|
+
export declare function createMap(element: HTMLElement): {
|
|
12
|
+
map: Map;
|
|
13
|
+
markerLayer: LayerGroup;
|
|
14
|
+
};
|
|
15
|
+
export declare function updateTileLayer(map: Map, tileLayer: TileLayer | null, currentTileUrl: string | null, tileUrl: string): TileLayer;
|
|
16
|
+
export declare function updateMarkers(markerLayer: LayerGroup, points: TravelPoint[]): void;
|
|
17
|
+
export declare function updateViewport(map: Map, points: TravelPoint[], center: [number, number], zoom: number): void;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { TravelPoint } from "./types";
|
|
2
|
+
export declare function parseBooleanAttribute(value: string | null, defaultValue?: boolean): boolean;
|
|
3
|
+
export declare function parseNumberAttribute(value: string | null, fallback: number): number;
|
|
4
|
+
export declare function parseCenterAttribute(value: string | null): [number, number];
|
|
5
|
+
export declare function normalizePoints(points: unknown): TravelPoint[];
|
|
6
|
+
export declare function countCountries(points: TravelPoint[]): number;
|