maplibre-gl-inspect 0.0.6 → 0.0.8

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,216 +1,204 @@
1
- # Maplibre GL Inspect
1
+ # maplibre-gl-inspect
2
2
 
3
- <!-- Badges -->
4
- [![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/geoql/maplibre-gl-inspect/pipeline.yml?logo=github-actions)](https://github.com/geoql/maplibre-gl-inspect/actions/workflows/pipeline.yml)
5
- [![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/geoql/maplibre-gl-inspect/codeql.yml?logo=lgtm&logoWidth=18)](https://github.com/geoql/maplibre-gl-inspect/actions/workflows/codeql.yml)
6
- [![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/geoql/maplibre-gl-inspect/shipjs-trigger.yml?label=⛴%20Ship.js%20trigger)](https://github.com/geoql/maplibre-gl-inspect/actions/workflows/shipjs-trigger.yml)
7
- [![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/geoql/maplibre-gl-inspect?sort=semver&logo=github)](https://github.com/geoql/maplibre-gl-inspect/releases)
3
+ [![CI](https://img.shields.io/github/actions/workflow/status/geoql/maplibre-gl-inspect/ci.yml?logo=github-actions)](https://github.com/geoql/maplibre-gl-inspect/actions/workflows/ci.yml)
8
4
  [![npm](https://img.shields.io/npm/v/maplibre-gl-inspect?logo=npm)](https://www.npmjs.com/package/maplibre-gl-inspect)
9
- [![DeepScan grade](https://deepscan.io/api/teams/15032/projects/24288/branches/745727/badge/grade.svg)](https://deepscan.io/dashboard#view=project&tid=15032&pid=24288&bid=745727)
10
- [![GitHub contributors](https://img.shields.io/github/contributors/geoql/maplibre-gl-inspect)](https://github.com/geoql/maplibre-gl-inspect/graphs/contributors)
11
- [![npm type definitions](https://img.shields.io/npm/types/maplibre-gl-inspect?logo=typescript)](https://github.com/vinayakkulkarni/maplibre-gl-inspect/blob/main/package.json)
12
- [![npm](https://img.shields.io/npm/dt/maplibre-gl-inspect?logo=npm)](http://npm-stat.com/charts.html?package=maplibre-gl-inspect)
13
- [![npm](https://img.shields.io/npm/dw/maplibre-gl-inspect?logo=npm)](http://npm-stat.com/charts.html?package=maplibre-gl-inspect)
14
- [![npm bundle size (version)](https://img.shields.io/bundlephobia/minzip/maplibre-gl-inspect)](https://bundlephobia.com/package/maplibre-gl-inspect@latest)
5
+ [![JSR](https://jsr.io/badges/@geoql/maplibre-gl-inspect)](https://jsr.io/@geoql/maplibre-gl-inspect)
6
+ [![npm bundle size](https://img.shields.io/bundlephobia/minzip/maplibre-gl-inspect)](https://bundlephobia.com/package/maplibre-gl-inspect@latest)
7
+ [![npm type definitions](https://img.shields.io/npm/types/maplibre-gl-inspect?logo=typescript)](https://github.com/geoql/maplibre-gl-inspect/blob/main/package.json)
8
+ [![GitHub release](https://img.shields.io/github/v/release/geoql/maplibre-gl-inspect?sort=semver&logo=github)](https://github.com/geoql/maplibre-gl-inspect/releases)
15
9
 
16
- [![vite](https://img.shields.io/github/package-json/dependency-version/geoql/maplibre-gl-inspect/dev/vite?logo=vite)](https://vitejs.dev)
17
- [![maplibre-gl](https://img.shields.io/github/package-json/dependency-version/geoql/maplibre-gl-inspect/dev/maplibre-gl)](https://maplibre.org/maplibre-gl-js-docs/api/)
18
- [![husky](https://img.shields.io/github/package-json/dependency-version/geoql/maplibre-gl-inspect/dev/vite?label=🐶%20dependency)](https://typicode.github.io/husky/#/)
19
- [![eslint](https://img.shields.io/github/package-json/dependency-version/geoql/maplibre-gl-inspect/dev/eslint?logo=eslint)](https://eslint.org/)
20
- [![prettier](https://img.shields.io/github/package-json/dependency-version/geoql/maplibre-gl-inspect/dev/prettier?logo=prettier)](https://prettier.io/)
21
- [![typescript](https://img.shields.io/github/package-json/dependency-version/geoql/maplibre-gl-inspect/dev/typescript?logo=TypeScript)](https://www.typescriptlang.org/)
10
+ Add an inspect control to [maplibre-gl-js](https://github.com/maplibre/maplibre-gl-js) to view all features of the vector sources and allows hovering over features to see their properties.
22
11
 
23
- Maplibre GL Inspect is a fork of [@acalcutt's Maplibre GL Inspect](https://github.com/acalcutt/maplibre-gl-inspect) which is a fork of [@lukasmartinelli Mapbox GL Inspect](https://github.com/lukasmartinelli/mapbox-gl-inspect). This fork is typescriptified along with strict ESLint & Prettier rule(s) in place for code standardisation 🕺
24
-
25
- Add an inspect control to [maplibre-gl-js](https://github.com/maplibre/maplibre-gl-js) to view all features
26
- of the vector sources and allows hovering over features to see their properties.
27
-
28
- **Requires [maplibre-gl-js](https://github.com/maplibre/maplibre-gl-js) (min version 1.15).**
12
+ **Requires [maplibre-gl-js](https://github.com/maplibre/maplibre-gl-js) >= 5.0.0**
29
13
 
30
14
  ![Maplibre GL Inspect Preview](https://cloud.githubusercontent.com/assets/1288339/21744637/11759412-d51a-11e6-9581-f26741fcd182.gif)
31
15
 
32
- ## Usage
33
-
34
- **maplibre-gl-inspect** is a Maplibre GL JS plugin that you can easily add on top of your map. Check `index.html` for a complete example.
35
-
36
- Make sure to include the CSS and JS files.
37
-
38
- **When using a CDN**
39
-
40
- ```html
41
- <script src='https://unpkg.com/maplibre-gl-inspect@latest/dist/maplibre-gl-inspect.js'></script>
42
- <link href='https://unpkg.com/maplibre-gl-inspect@latest/dist/maplibre-gl-inspect.css' rel='stylesheet' />
43
- ```
44
-
45
- **When using modules**
16
+ ## Install
46
17
 
47
- ```js
48
- require('maplibre-gl-inspect/dist/maplibre-gl-inspect.css');
49
- var maplibregl = require('maplibre-gl');
50
- var MaplibreInspect = require('maplibre-gl-inspect');
18
+ ```bash
19
+ # npm
20
+ npm install maplibre-gl-inspect maplibre-gl
51
21
 
52
- // Pass an initialized popup to Maplibre GL
53
- map.addControl(new MaplibreInspect({
54
- popup: new maplibregl.Popup({
55
- closeButton: false,
56
- closeOnClick: false
57
- })
58
- }));
22
+ # bun
23
+ bun add maplibre-gl-inspect maplibre-gl
59
24
  ```
60
25
 
26
+ ## Usage
61
27
 
62
- ### Add Inspect Control
28
+ ```ts
29
+ import maplibregl from 'maplibre-gl';
30
+ import { MaplibreInspect } from 'maplibre-gl-inspect';
31
+ import 'maplibre-gl-inspect/dist/style.css';
63
32
 
64
- Add the inspect control to your map.
33
+ const map = new maplibregl.Map({
34
+ container: 'map',
35
+ style: 'https://demotiles.maplibre.org/style.json',
36
+ });
65
37
 
66
- ```javascript
67
38
  map.addControl(new MaplibreInspect());
68
39
  ```
69
40
 
41
+ ### Show Inspection Map by Default
70
42
 
71
- ### Show Inspection Map
72
-
73
- Switch to the inspection map by default.
74
-
75
- ```javascript
76
- map.addControl(new MaplibreInspect({
77
- showInspectMap: true
78
- }));
43
+ ```ts
44
+ map.addControl(
45
+ new MaplibreInspect({
46
+ showInspectMap: true,
47
+ }),
48
+ );
79
49
  ```
80
50
 
81
- ### Show only Inspection Mode
82
-
83
- Switch to the inspection map by default and hide the inspect button to switch back to the normal map. Check `examples/inspect-only.html`
84
-
51
+ ### Inspect Only Mode
85
52
 
86
- ```javascript
87
- map.addControl(new MaplibreInspect({
88
- showInspectMap: true,
89
- showInspectButton: false
90
- }));
53
+ ```ts
54
+ map.addControl(
55
+ new MaplibreInspect({
56
+ showInspectMap: true,
57
+ showInspectButton: false,
58
+ }),
59
+ );
91
60
  ```
92
61
 
93
62
  ### Disable Popup
94
63
 
95
- Disable the feature Popup in inspection mode and in map mode. Check `examples/no-popup.html`
96
-
97
- ```javascript
98
- map.addControl(new MaplibreInspect({
99
- showInspectMapPopup: false,
100
- showMapPopup: false
101
- }));
64
+ ```ts
65
+ map.addControl(
66
+ new MaplibreInspect({
67
+ showInspectMapPopup: false,
68
+ showMapPopup: false,
69
+ }),
70
+ );
102
71
  ```
103
72
 
104
- ### Custom Popup Function
105
-
106
- You can also control the Popup output. Check `examples/custom-popup.html`
73
+ ### Custom Popup
107
74
 
108
- ```javascript
109
- map.addControl(new MaplibreInspect({
110
- renderPopup: function(features) {
111
- return '<h1>' + features.length + '</h1>';
112
- }
113
- }));
75
+ ```ts
76
+ map.addControl(
77
+ new MaplibreInspect({
78
+ renderPopup(features) {
79
+ return `<h1>${features.length}</h1>`;
80
+ },
81
+ }),
82
+ );
114
83
  ```
115
84
 
116
- ### Custom Color Function
117
-
118
- You are able to control the generated colors and background of the inspection style.
119
- Check `examples/custom-color-1.html` and `examples/custom-color-2.html`.
120
-
121
- ```javascript
122
- var colors = ['#FC49A3', '#CC66FF', '#66CCFF', '#66FFCC'];
123
- map.addControl(new MaplibreInspect({
124
- backgroundColor: '#000',
125
- assignLayerColor: function(layerId, alpha) {
126
- var randomNumber = parseInt(Math.random() * colors.length);
127
- return colors[randomNumber];
128
- }
129
- }));
85
+ ### Custom Colors
86
+
87
+ ```ts
88
+ const colors = ['#FC49A3', '#CC66FF', '#66CCFF', '#66FFCC'];
89
+ map.addControl(
90
+ new MaplibreInspect({
91
+ backgroundColor: '#000',
92
+ assignLayerColor(_layerId, _alpha) {
93
+ return colors[Math.floor(Math.random() * colors.length)];
94
+ },
95
+ }),
96
+ );
130
97
  ```
131
98
 
132
- ### Show just Popup but no Inspect Style
99
+ ### Popup on Click Only
133
100
 
134
- You can also hide the inspect button and enable the popup on the map if just want the popup hovering feature in your normal map but no inspect style.
135
- Check `examples/no-inspect-style.html`.
136
-
137
-
138
- ```js
139
- map.addControl(new MaplibreInspect({
140
- showInspectButton: false,
141
- showMapPopup: true
142
- }));
101
+ ```ts
102
+ map.addControl(
103
+ new MaplibreInspect({
104
+ showMapPopup: true,
105
+ showMapPopupOnHover: false,
106
+ showInspectMapPopupOnHover: false,
107
+ }),
108
+ );
143
109
  ```
144
110
 
145
- ### Show Popup only for certain Features
146
-
147
- You can pass a `queryParameters` object structured like the parameters object documented for `map.queryRenderedFeatures`](https://maplibre.org/maplibre-gl-js-docs/api/map/#map#queryrenderedfeatures).
148
- This let's you show the inspect popup for only certain layers.
149
- Check `examples/query-params.html`.
111
+ ### Query Parameters
150
112
 
113
+ Filter which layers show in the popup using [`queryRenderedFeatures` parameters](https://maplibre.org/maplibre-gl-js/docs/API/classes/Map/#queryrenderedfeatures).
151
114
 
152
- ```js
153
- map.addControl(new MaplibreInspect({
154
- queryParameters: {
155
- layers: ['composite_road_line']
156
- }
157
- }));
115
+ ```ts
116
+ map.addControl(
117
+ new MaplibreInspect({
118
+ queryParameters: {
119
+ layers: ['road_line'],
120
+ },
121
+ }),
122
+ );
158
123
  ```
159
124
 
160
- You can also use this feature to do custom layer [filtering](https://maplibre.org/maplibre-gl-js-docs/style-spec/types/).
125
+ ### Toggle Callback
161
126
 
162
- ```js
163
- map.addControl(new MaplibreInspect({
164
- queryParameters: {
165
- filter: ['>', 'height', 10]
166
- }
167
- }));
127
+ ```ts
128
+ map.addControl(
129
+ new MaplibreInspect({
130
+ toggleCallback(showInspectMap) {
131
+ console.log(`Inspect mode: ${showInspectMap}`);
132
+ },
133
+ }),
134
+ );
168
135
  ```
169
136
 
170
- ### Less Fidly Popup
137
+ ### Theming
171
138
 
172
- If inspecting features is too fiddly for thin lines you can optionally set a custom pixel buffer around the pointer when querying for features to make inspection a bit more forgiving.
173
- Check `examples/less-fidly.html`.
139
+ Supports `light`, `dark`, and `system` (auto-detect) themes. By default, the theme is `system` which follows `prefers-color-scheme`.
174
140
 
141
+ ```ts
142
+ // Use dark theme
143
+ const inspect = new MaplibreInspect({
144
+ theme: 'dark',
145
+ });
146
+ map.addControl(inspect);
175
147
 
176
- ```js
177
- map.addControl(new MaplibreInspect({
178
- selectThreshold: 50
179
- }));
148
+ // Switch theme at runtime
149
+ inspect.setTheme('light');
180
150
  ```
181
151
 
182
- ### Show Popup only on Click not on Hovering
152
+ ### Custom Theme Colors
153
+
154
+ ```ts
155
+ import type { ThemeColors } from 'maplibre-gl-inspect';
156
+
157
+ const inspect = new MaplibreInspect({
158
+ theme: 'system',
159
+ lightColors: {
160
+ popupText: '#1a1a1a',
161
+ popupBorder: '#e0e0e0',
162
+ buttonIcon: '#1a1a1a',
163
+ inspectBackground: '#fafafa',
164
+ },
165
+ darkColors: {
166
+ popupText: '#f0f0f0',
167
+ popupBorder: '#555555',
168
+ buttonIcon: '#f0f0f0',
169
+ inspectBackground: '#111827',
170
+ },
171
+ });
172
+ ```
183
173
 
184
- Do not show the inspect popup when hovering over the map but only when clicking on the map.
185
- Check `examples/popup-on-click.html`.
174
+ The following CSS custom properties are available for manual override:
186
175
 
176
+ | Variable | Description |
177
+ | ------------------------ | ----------------------------- |
178
+ | `--inspect-popup-text` | Popup text color |
179
+ | `--inspect-popup-border` | Popup feature border color |
180
+ | `--inspect-button-icon` | Toggle button icon color |
181
+ | `--inspect-background` | Inspect mode background color |
187
182
 
188
- ```js
189
- map.addControl(new MaplibreInspect({
190
- showMapPopup: true,
191
- showMapPopupOnHover: false,
192
- showInspectMapPopupOnHover: false
193
- }));
194
- ```
183
+ ## Develop
195
184
 
196
- ### Add a Callback for Inspect Toggle Events
185
+ ```bash
186
+ bun install
187
+ bun run build
188
+ ```
197
189
 
198
- Call a function whenever the user toggles the inpect map on or off. Useful for adding inspect state to URL hash.
199
- Check `examples/url-hash-toggle-callback.html`.
190
+ Run the example locally:
200
191
 
201
- ```js
202
- map.addControl(new MaplibreInspect({
203
- toggleCallback: function(showInspectMap) {
204
- console.log(`showInspectMap is ${showInspectMap}`);
205
- }
206
- }));
192
+ ```bash
193
+ cd example
194
+ bun install
195
+ bun run dev
207
196
  ```
208
197
 
209
- ## Develop
198
+ ## Credits
210
199
 
211
- Create a minified standalone build.
200
+ Fork of [@acalcutt's maplibre-gl-inspect](https://github.com/acalcutt/maplibre-gl-inspect), which is a fork of [@lukasmartinelli's mapbox-gl-inspect](https://github.com/lukasmartinelli/mapbox-gl-inspect).
212
201
 
213
- ```
214
- npm install
215
- npm run build
216
- ```
202
+ ## License
203
+
204
+ [MIT](LICENSE)
@@ -0,0 +1,96 @@
1
+ import { LayerSpecification, Map, Popup, SourceSpecification, StyleSpecification } from "maplibre-gl";
2
+
3
+ //#region src/types.d.ts
4
+ type RenderPopupProperty = {
5
+ [x: string]: null | undefined | string | number | object | Date;
6
+ };
7
+ type RenderPopupFeature = {
8
+ source: string;
9
+ sourceLayer?: string;
10
+ layer: {
11
+ [x: string]: string;
12
+ source: string;
13
+ };
14
+ geometry: {
15
+ type: string;
16
+ };
17
+ properties: RenderPopupProperty;
18
+ };
19
+ type Theme = 'light' | 'dark' | 'system';
20
+ interface ThemeColors {
21
+ /** Popup text color */
22
+ popupText: string;
23
+ /** Popup background color */
24
+ popupBg: string;
25
+ /** Popup feature border color */
26
+ popupBorder: string;
27
+ /** Button icon fill color */
28
+ buttonIcon: string;
29
+ /** Control group background color */
30
+ ctrlBg: string;
31
+ /** Inspect mode background color */
32
+ inspectBackground: string;
33
+ }
34
+ type Options = {
35
+ showInspectMap: boolean;
36
+ showInspectButton: boolean;
37
+ showInspectMapPopup: boolean;
38
+ showMapPopup: boolean;
39
+ showMapPopupOnHover: boolean;
40
+ showInspectMapPopupOnHover: boolean;
41
+ blockHoverPopupOnClick: boolean;
42
+ backgroundColor: string;
43
+ assignLayerColor(layerId: string, alpha?: number): string;
44
+ buildInspectStyle(originalMapStyle: StyleSpecification, coloredLayers: LayerSpecification[], opts: any): StyleSpecification;
45
+ renderPopup(features: RenderPopupFeature[]): string;
46
+ popup: Popup | null;
47
+ selectThreshold: number;
48
+ useInspectStyle: boolean;
49
+ queryParameters: Record<string, string>;
50
+ sources: {
51
+ [_: string]: SourceSpecification | string[];
52
+ };
53
+ toggleCallback(showInspectMap?: boolean): void;
54
+ theme?: Theme;
55
+ lightColors?: Partial<ThemeColors>;
56
+ darkColors?: Partial<ThemeColors>;
57
+ };
58
+ //#endregion
59
+ //#region src/maplibre-gl-inspect.d.ts
60
+ declare class MaplibreInspect {
61
+ private _map;
62
+ private _popup;
63
+ private _popupBlocked;
64
+ private _showInspectMap;
65
+ private _originalStyle;
66
+ private _toggle;
67
+ options: Options;
68
+ sources: Options['sources'];
69
+ assignLayerColor: Options['assignLayerColor'];
70
+ private _currentTheme;
71
+ private readonly _mediaQuery;
72
+ private readonly _lightColors;
73
+ private readonly _darkColors;
74
+ constructor(options?: Partial<Options>);
75
+ private _inspectStyle;
76
+ private _onSourceChange;
77
+ private _onStyleChange;
78
+ private _onRightClick;
79
+ private _onMouseMove;
80
+ toggleInspector(): void;
81
+ get theme(): Theme;
82
+ setTheme(theme: Theme): void;
83
+ private _onSystemThemeChange;
84
+ private _getResolvedTheme;
85
+ private _applyTheme;
86
+ render(): void;
87
+ onAdd(map: Map): HTMLDivElement;
88
+ onRemove(): void;
89
+ }
90
+ //#endregion
91
+ //#region src/theme-colors.d.ts
92
+ declare const DEFAULT_LIGHT_COLORS: ThemeColors;
93
+ declare const DEFAULT_DARK_COLORS: ThemeColors;
94
+ //#endregion
95
+ export { DEFAULT_DARK_COLORS, DEFAULT_LIGHT_COLORS, MaplibreInspect, MaplibreInspect as default, type Options, type RenderPopupFeature, type RenderPopupProperty, type Theme, type ThemeColors };
96
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/maplibre-gl-inspect.ts","../src/theme-colors.ts"],"mappings":";;;KAOY,mBAAA;EAAA,CACT,CAAA,yDAA0D,IAAA;AAAA;AAAA,KAGjD,kBAAA;EACV,MAAA;EACA,WAAA;EACA,KAAA;IAAA,CAAU,CAAA;IAAoB,MAAA;EAAA;EAC9B,QAAA;IAAY,IAAA;EAAA;EACZ,UAAA,EAAY,mBAAA;AAAA;AAAA,KAGF,KAAA;AAAA,UAEK,WAAA;EANH;EAQZ,SAAA;EAPY;EASZ,OAAA;EAT+B;EAW/B,WAAA;EARe;EAUf,UAAA;EAVe;EAYf,MAAA;EAVe;EAYf,iBAAA;AAAA;AAAA,KAGU,OAAA;EACV,cAAA;EACA,iBAAA;EACA,mBAAA;EACA,YAAA;EACA,mBAAA;EACA,0BAAA;EACA,sBAAA;EACA,eAAA;EACA,gBAAA,CAAiB,OAAA,UAAiB,KAAA;EAClC,iBAAA,CACE,gBAAA,EAAkB,kBAAA,EAClB,aAAA,EAAe,kBAAA,IACf,IAAA,QACC,kBAAA;EACH,WAAA,CAAY,QAAA,EAAU,kBAAA;EACtB,KAAA,EAAO,KAAA;EACP,eAAA;EACA,eAAA;EACA,eAAA,EAAiB,MAAA;EACjB,OAAA;IAAA,CAAY,CAAA,WAAY,mBAAA;EAAA;EACxB,cAAA,CAAe,cAAA;EACf,KAAA,GAAQ,KAAA;EACR,WAAA,GAAc,OAAA,CAAQ,WAAA;EACtB,UAAA,GAAa,OAAA,CAAQ,WAAA;AAAA;;;cCXjB,eAAA;EAAA,QACI,IAAA;EAAA,QACA,MAAA;EAAA,QACA,aAAA;EAAA,QACA,eAAA;EAAA,QACA,cAAA;EAAA,QACA,OAAA;EACD,OAAA,EAAS,OAAA;EACT,OAAA,EAAS,OAAA;EACT,gBAAA,EAAkB,OAAA;EAAA,QACjB,aAAA;EAAA,iBACS,WAAA;EAAA,iBACA,YAAA;EAAA,iBACA,WAAA;cAEL,OAAA,GAAU,OAAA,CAAQ,OAAA;EAAA,QAgFtB,aAAA;EAAA,QAkBA,eAAA;EAAA,QAqCA,cAAA;EAAA,QAOA,aAAA;EAAA,QAUA,YAAA;EAkED,eAAA,CAAA;EAAA,IAMH,KAAA,CAAA,GAAS,KAAA;EAIN,QAAA,CAAS,KAAA,EAAO,KAAA;EAAA,QAiBf,oBAAA;EAAA,QAMA,iBAAA;EAAA,QAUA,WAAA;EAoCD,MAAA,CAAA;EAmBA,KAAA,CAAM,GAAA,EAAK,GAAA,GAAG,cAAA;EAkBd,QAAA,CAAA;AAAA;;;cC5YI,oBAAA,EAAsB,WAAA;AAAA,cAStB,mBAAA,EAAqB,WAAA"}