react-bkoi-gl 1.0.7 → 2.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/README.md +163 -18
- package/dist/components/attribution-control.d.ts +4 -6
- package/dist/components/attribution-control.js +6 -5
- package/dist/components/attribution-control.js.map +1 -1
- package/dist/components/fullscreen-control.d.ts +4 -6
- package/dist/components/fullscreen-control.js +4 -4
- package/dist/components/fullscreen-control.js.map +1 -1
- package/dist/components/geolocate-control.d.ts +10 -26
- package/dist/components/geolocate-control.js +11 -11
- package/dist/components/geolocate-control.js.map +1 -1
- package/dist/components/layer.d.ts +7 -6
- package/dist/components/layer.js +8 -9
- package/dist/components/layer.js.map +1 -1
- package/dist/components/logo-control.d.ts +9 -0
- package/dist/components/logo-control.js +28 -0
- package/dist/components/logo-control.js.map +1 -0
- package/dist/components/map.d.ts +20 -16
- package/dist/components/map.js +38 -32
- package/dist/components/map.js.map +1 -1
- package/dist/components/marker.d.ts +10 -33
- package/dist/components/marker.js +22 -15
- package/dist/components/marker.js.map +1 -1
- package/dist/components/navigation-control.d.ts +4 -6
- package/dist/components/navigation-control.js +4 -4
- package/dist/components/navigation-control.js.map +1 -1
- package/dist/components/popup.d.ts +7 -25
- package/dist/components/popup.js +17 -28
- package/dist/components/popup.js.map +1 -1
- package/dist/components/scale-control.d.ts +4 -6
- package/dist/components/scale-control.js +4 -4
- package/dist/components/scale-control.js.map +1 -1
- package/dist/components/source.d.ts +3 -4
- package/dist/components/source.js +20 -22
- package/dist/components/source.js.map +1 -1
- package/dist/components/terrain-control.d.ts +10 -0
- package/dist/components/terrain-control.js +19 -0
- package/dist/components/terrain-control.js.map +1 -0
- package/dist/components/use-control.d.ts +6 -6
- package/dist/components/use-control.js +4 -5
- package/dist/components/use-control.js.map +1 -1
- package/dist/components/use-map.d.ts +8 -9
- package/dist/components/use-map.js +5 -5
- package/dist/components/use-map.js.map +1 -1
- package/dist/exports-maplibre-gl.d.ts +33 -0
- package/dist/exports-maplibre-gl.js +21 -0
- package/dist/exports-maplibre-gl.js.map +1 -0
- package/dist/index.cjs +590 -681
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/{mapbox → maplibre}/create-ref.d.ts +6 -6
- package/dist/maplibre/create-ref.js +30 -0
- package/dist/maplibre/create-ref.js.map +1 -0
- package/dist/maplibre/maplibre.d.ts +81 -0
- package/dist/maplibre/maplibre.js +387 -0
- package/dist/maplibre/maplibre.js.map +1 -0
- package/dist/styles/index.d.ts +4 -0
- package/dist/styles/react-bkoi-gl.css +1 -1
- package/dist/styles.d.js +2 -0
- package/dist/styles.d.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/types/common.d.ts +2 -60
- package/dist/types/common.js.map +1 -1
- package/dist/types/events.d.ts +64 -23
- package/dist/types/events.js.map +1 -1
- package/dist/types/internal.d.ts +14 -0
- package/dist/types/internal.js +2 -0
- package/dist/types/internal.js.map +1 -0
- package/dist/types/lib.d.ts +16 -200
- package/dist/types/lib.js.map +1 -1
- package/dist/types/style-spec.d.ts +1 -0
- package/dist/types/style-spec.js +2 -0
- package/dist/types/style-spec.js.map +1 -0
- package/dist/utils/apply-react-style.d.ts +1 -1
- package/dist/utils/apply-react-style.js.map +1 -1
- package/dist/utils/compare-class-names.d.ts +2 -0
- package/dist/utils/compare-class-names.js +23 -0
- package/dist/utils/compare-class-names.js.map +1 -0
- package/dist/utils/deep-equal.d.ts +1 -1
- package/dist/utils/deep-equal.js +1 -1
- package/dist/utils/deep-equal.js.map +1 -1
- package/dist/utils/set-globals.d.ts +6 -8
- package/dist/utils/set-globals.js +22 -10
- package/dist/utils/set-globals.js.map +1 -1
- package/dist/utils/style-utils.d.ts +3 -2
- package/dist/utils/style-utils.js +4 -4
- package/dist/utils/style-utils.js.map +1 -1
- package/dist/utils/transform.d.ts +11 -19
- package/dist/utils/transform.js +13 -36
- package/dist/utils/transform.js.map +1 -1
- package/dist/utils/use-isomorphic-layout-effect.d.ts +1 -1
- package/dist/utils/use-isomorphic-layout-effect.js +2 -2
- package/dist/utils/use-isomorphic-layout-effect.js.map +1 -1
- package/package.json +42 -26
- package/src/components/attribution-control.ts +40 -16
- package/src/components/fullscreen-control.ts +40 -0
- package/src/components/geolocate-control.ts +45 -39
- package/src/components/layer.ts +37 -29
- package/src/components/logo-control.ts +44 -0
- package/src/components/map.tsx +86 -75
- package/src/components/marker.ts +141 -123
- package/src/components/navigation-control.ts +11 -12
- package/src/components/popup.ts +94 -97
- package/src/components/scale-control.ts +12 -14
- package/src/components/source.ts +58 -57
- package/src/components/terrain-control.ts +29 -0
- package/src/components/use-control.ts +21 -17
- package/src/components/use-map.tsx +26 -24
- package/src/exports-maplibre-gl.ts +37 -0
- package/src/index.ts +3 -2
- package/src/maplibre/create-ref.ts +70 -0
- package/src/maplibre/maplibre.ts +624 -0
- package/src/styles.d.ts +4 -0
- package/src/types/common.ts +12 -72
- package/src/types/events.ts +102 -42
- package/src/types/internal.ts +26 -0
- package/src/types/lib.ts +65 -260
- package/src/types/style-spec.ts +34 -0
- package/src/utils/apply-react-style.ts +7 -3
- package/src/utils/compare-class-names.ts +29 -0
- package/src/utils/deep-equal.ts +2 -2
- package/src/utils/set-globals.ts +22 -28
- package/src/utils/style-utils.ts +18 -9
- package/src/utils/transform.ts +32 -60
- package/src/utils/use-isomorphic-layout-effect.ts +3 -2
- package/bkoi-gl/package.json +0 -6
- package/dist/exports-bkoi-gl.cjs +0 -1512
- package/dist/exports-bkoi-gl.d.ts +0 -89
- package/dist/exports-bkoi-gl.js +0 -36
- package/dist/exports-bkoi-gl.js.map +0 -1
- package/dist/exports-mapbox.d.ts +0 -139
- package/dist/exports-mapbox.js +0 -36
- package/dist/exports-mapbox.js.map +0 -1
- package/dist/mapbox/create-ref.js +0 -64
- package/dist/mapbox/create-ref.js.map +0 -1
- package/dist/mapbox/mapbox.d.ts +0 -81
- package/dist/mapbox/mapbox.js +0 -476
- package/dist/mapbox/mapbox.js.map +0 -1
- package/dist/types/events-bkoi-gl.d.ts +0 -49
- package/dist/types/events-bkoi-gl.js +0 -2
- package/dist/types/events-bkoi-gl.js.map +0 -1
- package/dist/types/events-mapbox.d.ts +0 -49
- package/dist/types/events-mapbox.js +0 -2
- package/dist/types/events-mapbox.js.map +0 -1
- package/dist/types/index.d.ts +0 -70
- package/dist/types/index.js +0 -5
- package/dist/types/index.js.map +0 -1
- package/dist/types/public.d.ts +0 -2
- package/dist/types/public.js +0 -2
- package/dist/types/public.js.map +0 -1
- package/dist/types/style-spec-bkoi-gl.d.ts +0 -9
- package/dist/types/style-spec-bkoi-gl.js +0 -2
- package/dist/types/style-spec-bkoi-gl.js.map +0 -1
- package/dist/types/style-spec-mapbox.d.ts +0 -7
- package/dist/types/style-spec-mapbox.js +0 -2
- package/dist/types/style-spec-mapbox.js.map +0 -1
- package/src/components/fullscreen-control.tsx +0 -37
- package/src/exports-bkoi-gl.ts +0 -156
- package/src/exports-mapbox.ts +0 -159
- package/src/mapbox/create-ref.ts +0 -118
- package/src/mapbox/mapbox.ts +0 -742
- package/src/types/events-bkoi-gl.ts +0 -78
- package/src/types/events-mapbox.ts +0 -76
- package/src/types/index.ts +0 -93
- package/src/types/public.ts +0 -9
- package/src/types/style-spec-bkoi-gl.ts +0 -81
- package/src/types/style-spec-mapbox.ts +0 -80
package/README.md
CHANGED
|
@@ -17,35 +17,44 @@ Or via yarn:
|
|
|
17
17
|
yarn add react-bkoi-gl
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
## Example
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
### JavaScript (`js`) Example
|
|
23
|
+
```jsx
|
|
23
24
|
import { useRef } from 'react';
|
|
24
|
-
import {
|
|
25
|
+
import {
|
|
26
|
+
Map,
|
|
27
|
+
Marker,
|
|
28
|
+
Popup,
|
|
29
|
+
Layer,
|
|
30
|
+
Source,
|
|
31
|
+
NavigationControl,
|
|
32
|
+
FullscreenControl,
|
|
33
|
+
GeolocateControl,
|
|
34
|
+
ScaleControl,
|
|
35
|
+
} from 'react-bkoi-gl';
|
|
25
36
|
|
|
26
37
|
// Import Styles
|
|
27
|
-
import "react-bkoi-gl/styles"
|
|
38
|
+
import "react-bkoi-gl/styles";
|
|
28
39
|
|
|
29
40
|
const App = () => {
|
|
30
|
-
const BARIKOI_API_KEY = 'YOUR_BARIKOI_API_KEY_HERE'
|
|
31
|
-
const mapStyle = `https://map.barikoi.com/styles/osm-liberty/style.json?key=${BARIKOI_API_KEY}
|
|
41
|
+
const BARIKOI_API_KEY = 'YOUR_BARIKOI_API_KEY_HERE';
|
|
42
|
+
const mapStyle = `https://map.barikoi.com/styles/osm-liberty/style.json?key=${BARIKOI_API_KEY}`;
|
|
32
43
|
const mapContainer = useRef(null);
|
|
33
44
|
const mapRef = useRef(null);
|
|
34
45
|
const initialViewState = {
|
|
35
46
|
longitude: 90.36402,
|
|
36
47
|
latitude: 23.823731,
|
|
37
48
|
minZoom: 4,
|
|
38
|
-
maxZoom:
|
|
49
|
+
maxZoom: 22,
|
|
39
50
|
zoom: 13,
|
|
40
51
|
bearing: 0,
|
|
41
52
|
pitch: 0,
|
|
42
|
-
antialias: true
|
|
43
|
-
}
|
|
53
|
+
antialias: true,
|
|
54
|
+
};
|
|
44
55
|
|
|
45
56
|
return (
|
|
46
|
-
<div
|
|
47
|
-
ref={mapContainer} style={containerStyles}
|
|
48
|
-
>
|
|
57
|
+
<div ref={mapContainer} style={containerStyles}>
|
|
49
58
|
<Map
|
|
50
59
|
ref={mapRef}
|
|
51
60
|
mapStyle={mapStyle}
|
|
@@ -53,16 +62,39 @@ const App = () => {
|
|
|
53
62
|
initialViewState={initialViewState}
|
|
54
63
|
doubleClickZoom={false}
|
|
55
64
|
dragRotate={false}
|
|
56
|
-
attributionControl={false}
|
|
57
65
|
>
|
|
58
|
-
<
|
|
59
|
-
<
|
|
66
|
+
<Marker longitude={90.36402} latitude={23.823731} color="red" />
|
|
67
|
+
<Popup longitude={90.36402} latitude={23.823731}>
|
|
68
|
+
<div>Hello, Barikoi!</div>
|
|
69
|
+
</Popup>
|
|
70
|
+
<Source
|
|
71
|
+
id="points"
|
|
72
|
+
type="geojson"
|
|
73
|
+
data={{
|
|
74
|
+
type: 'FeatureCollection',
|
|
75
|
+
features: [
|
|
76
|
+
{
|
|
77
|
+
type: 'Feature',
|
|
78
|
+
properties: {},
|
|
79
|
+
geometry: { type: 'Point', coordinates: [90.36402, 23.823731] }
|
|
80
|
+
}
|
|
81
|
+
]
|
|
82
|
+
}}
|
|
83
|
+
/>
|
|
84
|
+
<Layer
|
|
85
|
+
id="points-layer"
|
|
86
|
+
type="circle"
|
|
87
|
+
source="points"
|
|
88
|
+
paint={{ 'circle-radius': 10, 'circle-color': '#ff0000' }}
|
|
89
|
+
/>
|
|
60
90
|
<NavigationControl position="top-right" />
|
|
91
|
+
<FullscreenControl position="top-right" />
|
|
92
|
+
<GeolocateControl position="top-right" />
|
|
61
93
|
<ScaleControl position="bottom-right" />
|
|
62
94
|
</Map>
|
|
63
95
|
</div>
|
|
64
|
-
)
|
|
65
|
-
}
|
|
96
|
+
);
|
|
97
|
+
};
|
|
66
98
|
|
|
67
99
|
// JSX Styles
|
|
68
100
|
const containerStyles = {
|
|
@@ -70,11 +102,124 @@ const containerStyles = {
|
|
|
70
102
|
height: "100vh",
|
|
71
103
|
minHeight: "400px",
|
|
72
104
|
overflow: "hidden",
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export default App;
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### TypeScript (`ts`) Example
|
|
111
|
+
```tsx
|
|
112
|
+
import { useRef } from 'react';
|
|
113
|
+
import {
|
|
114
|
+
Map,
|
|
115
|
+
Marker,
|
|
116
|
+
Popup,
|
|
117
|
+
Layer,
|
|
118
|
+
Source,
|
|
119
|
+
NavigationControl,
|
|
120
|
+
FullscreenControl,
|
|
121
|
+
GeolocateControl,
|
|
122
|
+
ScaleControl,
|
|
123
|
+
MapRef
|
|
124
|
+
} from 'react-bkoi-gl';
|
|
125
|
+
|
|
126
|
+
// Import Styles
|
|
127
|
+
import "react-bkoi-gl/styles";
|
|
128
|
+
|
|
129
|
+
interface MapProps {
|
|
130
|
+
longitude: number;
|
|
131
|
+
latitude: number;
|
|
73
132
|
}
|
|
74
133
|
|
|
75
|
-
|
|
134
|
+
const App: React.FC = () => {
|
|
135
|
+
const BARIKOI_API_KEY = 'YOUR_BARIKOI_API_KEY_HERE';
|
|
136
|
+
const mapStyle = `https://map.barikoi.com/styles/osm-liberty/style.json?key=${BARIKOI_API_KEY}`;
|
|
137
|
+
const mapContainer = useRef<HTMLDivElement>(null);
|
|
138
|
+
const mapRef = useRef<MapRef>(null);
|
|
139
|
+
const initialViewState = {
|
|
140
|
+
longitude: 90.36402,
|
|
141
|
+
latitude: 23.823731,
|
|
142
|
+
minZoom: 4,
|
|
143
|
+
maxZoom: 22,
|
|
144
|
+
zoom: 13,
|
|
145
|
+
bearing: 0,
|
|
146
|
+
pitch: 0,
|
|
147
|
+
antialias: true,
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
return (
|
|
151
|
+
<div ref={mapContainer} style={containerStyles}>
|
|
152
|
+
<Map
|
|
153
|
+
ref={mapRef}
|
|
154
|
+
mapStyle={mapStyle}
|
|
155
|
+
style={{ width: "100%", height: "100%" }}
|
|
156
|
+
initialViewState={initialViewState}
|
|
157
|
+
doubleClickZoom={false}
|
|
158
|
+
dragRotate={false}
|
|
159
|
+
>
|
|
160
|
+
<Marker longitude={90.36402} latitude={23.823731} color="red" />
|
|
161
|
+
<Popup longitude={90.36402} latitude={23.823731}>
|
|
162
|
+
<div>Hello, Barikoi!</div>
|
|
163
|
+
</Popup>
|
|
164
|
+
<Source
|
|
165
|
+
id="points"
|
|
166
|
+
type="geojson"
|
|
167
|
+
data={{
|
|
168
|
+
type: 'FeatureCollection',
|
|
169
|
+
features: [
|
|
170
|
+
{
|
|
171
|
+
type: 'Feature',
|
|
172
|
+
properties: {},
|
|
173
|
+
geometry: { type: 'Point', coordinates: [90.36402, 23.823731] }
|
|
174
|
+
}
|
|
175
|
+
]
|
|
176
|
+
}}
|
|
177
|
+
/>
|
|
178
|
+
<Layer
|
|
179
|
+
id="points-layer"
|
|
180
|
+
type="circle"
|
|
181
|
+
source="points"
|
|
182
|
+
paint={{ 'circle-radius': 10, 'circle-color': '#ff0000' }}
|
|
183
|
+
/>
|
|
184
|
+
<NavigationControl position="top-right" />
|
|
185
|
+
<FullscreenControl position="top-right" />
|
|
186
|
+
<GeolocateControl position="top-right" />
|
|
187
|
+
<ScaleControl position="bottom-right" />
|
|
188
|
+
</Map>
|
|
189
|
+
</div>
|
|
190
|
+
);
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
// JSX Styles
|
|
194
|
+
const containerStyles: React.CSSProperties = {
|
|
195
|
+
width: "100%",
|
|
196
|
+
height: "100vh",
|
|
197
|
+
minHeight: "400px",
|
|
198
|
+
overflow: "hidden",
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
export default App;
|
|
76
202
|
```
|
|
77
203
|
|
|
204
|
+
## Components
|
|
205
|
+
|
|
206
|
+
Here is a list of all available components in `react-bkoi-gl`:
|
|
207
|
+
|
|
208
|
+
| Component | Description |
|
|
209
|
+
|---------------------|-----------------------------------------------------------------------------|
|
|
210
|
+
| `Map` | The core component for rendering a Barikoi map. Must be the parent of all other components. |
|
|
211
|
+
| `Marker` | Displays a marker on the map at specified coordinates. |
|
|
212
|
+
| `Popup` | Displays a popup with custom content at specified coordinates. |
|
|
213
|
+
| `Layer` | Adds a custom layer to the map. |
|
|
214
|
+
| `Source` | Defines a data source for the map. |
|
|
215
|
+
| `NavigationControl` | Adds zoom and rotation controls. |
|
|
216
|
+
| `FullscreenControl` | Adds a button to toggle fullscreen mode. |
|
|
217
|
+
| `GeolocateControl` | Centers the map on the user's location. |
|
|
218
|
+
| `ScaleControl` | Displays a scale bar. |
|
|
219
|
+
| `TerrainControl` | Adds terrain control to the map. |
|
|
220
|
+
| `useMap` | Custom hook for managing the map instance. |
|
|
221
|
+
| `useControl` | Custom hook for managing map controls. |
|
|
222
|
+
|
|
78
223
|
## Get Barikoi API key
|
|
79
224
|
|
|
80
225
|
To access Barikoi's API services, you need to:
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import * as React from
|
|
2
|
-
import type { ControlPosition,
|
|
3
|
-
export type AttributionControlProps
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { ControlPosition, AttributionControlOptions } from "../types/lib";
|
|
3
|
+
export type AttributionControlProps = AttributionControlOptions & {
|
|
4
4
|
/** Placement of the control relative to the map. */
|
|
5
5
|
position?: ControlPosition;
|
|
6
6
|
/** CSS style override, applied to the control's container */
|
|
7
7
|
style?: React.CSSProperties;
|
|
8
8
|
};
|
|
9
|
-
declare
|
|
10
|
-
declare const _default: React.MemoExoticComponent<typeof AttributionControl>;
|
|
11
|
-
export default _default;
|
|
9
|
+
export declare const AttributionControl: React.FC<AttributionControlProps>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { useEffect, memo } from
|
|
1
|
+
import { useEffect, memo } from "react";
|
|
2
2
|
import { applyReactStyle } from "../utils/apply-react-style.js";
|
|
3
|
-
import useControl from "./use-control.js";
|
|
4
|
-
function
|
|
3
|
+
import { useControl } from "./use-control.js";
|
|
4
|
+
function _AttributionControl(props) {
|
|
5
5
|
const ctrl = useControl(_ref => {
|
|
6
6
|
let {
|
|
7
7
|
mapLib
|
|
@@ -12,8 +12,9 @@ function AttributionControl(props) {
|
|
|
12
12
|
});
|
|
13
13
|
useEffect(() => {
|
|
14
14
|
applyReactStyle(ctrl._container, props.style);
|
|
15
|
-
|
|
15
|
+
if (!ctrl._container) return;
|
|
16
|
+
}, [props.style, ctrl._container]);
|
|
16
17
|
return null;
|
|
17
18
|
}
|
|
18
|
-
export
|
|
19
|
+
export const AttributionControl = memo(_AttributionControl);
|
|
19
20
|
//# sourceMappingURL=attribution-control.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attribution-control.js","names":["useEffect","memo","applyReactStyle","useControl","
|
|
1
|
+
{"version":3,"file":"attribution-control.js","names":["useEffect","memo","applyReactStyle","useControl","_AttributionControl","props","ctrl","_ref","mapLib","AttributionControl","position","_container","style"],"sources":["../../src/components/attribution-control.ts"],"sourcesContent":["/* eslint-disable max-statements */\n/* eslint-disable @typescript-eslint/no-unnecessary-type-assertion */\nimport * as React from \"react\";\nimport { useEffect, memo } from \"react\";\nimport { applyReactStyle } from \"../utils/apply-react-style\";\nimport { useControl } from \"./use-control\";\n\nimport type { ControlPosition, AttributionControlOptions } from \"../types/lib\";\n\nexport type AttributionControlProps = AttributionControlOptions & {\n /** Placement of the control relative to the map. */\n position?: ControlPosition;\n /** CSS style override, applied to the control's container */\n style?: React.CSSProperties;\n};\n\nfunction _AttributionControl(props: AttributionControlProps) {\n const ctrl = useControl(\n ({ mapLib }) => new mapLib.AttributionControl(props),\n { position: props.position },\n );\n\n useEffect(() => {\n applyReactStyle(ctrl._container, props.style);\n\n // Ensure the container is available\n if (!ctrl._container) return;\n\n // Create and append the custom attribution control\n // const customAttribution = document.createElement('details');\n // customAttribution.className = 'maplibregl-ctrl maplibregl-ctrl-attrib maplibregl-compact maplibregl-compact-show';\n // customAttribution.setAttribute('open', '');\n\n // const summary = document.createElement('summary');\n // summary.className = 'maplibregl-ctrl-attrib-button';\n // summary.setAttribute('title', 'Toggle attribution');\n // summary.setAttribute('aria-label', 'Toggle attribution');\n // customAttribution.appendChild(summary);\n\n // const innerDiv = document.createElement('div');\n // innerDiv.className = 'maplibregl-ctrl-attrib-inner';\n // innerDiv.innerHTML = `\n // <a href=\"https://barikoi.com/\" target=\"_blank\">© Barikoi</a> |\n // <a href=\"https://www.openmaptiles.org/\" target=\"_blank\">© OpenMapTiles</a> |\n // <a href=\"https://www.openstreetmap.org/copyright\" target=\"_blank\">© OpenStreetMap contributors</a>\n // `;\n // customAttribution.appendChild(innerDiv);\n\n // ctrl._container.appendChild(customAttribution);\n }, [props.style, ctrl._container]);\n\n return null;\n}\n\nexport const AttributionControl: React.FC<AttributionControlProps> =\n memo(_AttributionControl);\n"],"mappings":"AAGA,SAASA,SAAS,EAAEC,IAAI,QAAQ,OAAO;AAAC,SAC/BC,eAAe;AAAA,SACfC,UAAU;AAWnB,SAASC,mBAAmBA,CAACC,KAA8B,EAAE;EAC3D,MAAMC,IAAI,GAAGH,UAAU,CACrBI,IAAA;IAAA,IAAC;MAAEC;IAAO,CAAC,GAAAD,IAAA;IAAA,OAAK,IAAIC,MAAM,CAACC,kBAAkB,CAACJ,KAAK,CAAC;EAAA,GACpD;IAAEK,QAAQ,EAAEL,KAAK,CAACK;EAAS,CAC7B,CAAC;EAEDV,SAAS,CAAC,MAAM;IACdE,eAAe,CAACI,IAAI,CAACK,UAAU,EAAEN,KAAK,CAACO,KAAK,CAAC;IAG7C,IAAI,CAACN,IAAI,CAACK,UAAU,EAAE;EAuBxB,CAAC,EAAE,CAACN,KAAK,CAACO,KAAK,EAAEN,IAAI,CAACK,UAAU,CAAC,CAAC;EAElC,OAAO,IAAI;AACb;AAEA,OAAO,MAAMF,kBAAqD,GAChER,IAAI,CAACG,mBAAmB,CAAC","ignoreList":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as React from
|
|
2
|
-
import type { ControlPosition,
|
|
3
|
-
export type FullscreenControlProps
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { ControlPosition, FullscreenControlOptions } from "../types/lib";
|
|
3
|
+
export type FullscreenControlProps = Omit<FullscreenControlOptions, "container"> & {
|
|
4
4
|
/** Id of the DOM element which should be made full screen. By default, the map container
|
|
5
5
|
* element will be made full screen. */
|
|
6
6
|
containerId?: string;
|
|
@@ -9,6 +9,4 @@ export type FullscreenControlProps<OptionsT> = Omit<OptionsT, 'container'> & {
|
|
|
9
9
|
/** CSS style override, applied to the control's container */
|
|
10
10
|
style?: React.CSSProperties;
|
|
11
11
|
};
|
|
12
|
-
declare
|
|
13
|
-
declare const _default: React.MemoExoticComponent<typeof FullscreenControl>;
|
|
14
|
-
export default _default;
|
|
12
|
+
export declare const FullscreenControl: React.FC<FullscreenControlProps>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { useEffect, memo } from
|
|
1
|
+
import { useEffect, memo } from "react";
|
|
2
2
|
import { applyReactStyle } from "../utils/apply-react-style.js";
|
|
3
|
-
import useControl from "./use-control.js";
|
|
4
|
-
function
|
|
3
|
+
import { useControl } from "./use-control.js";
|
|
4
|
+
function _FullscreenControl(props) {
|
|
5
5
|
const ctrl = useControl(_ref => {
|
|
6
6
|
let {
|
|
7
7
|
mapLib
|
|
@@ -17,5 +17,5 @@ function FullscreenControl(props) {
|
|
|
17
17
|
}, [props.style]);
|
|
18
18
|
return null;
|
|
19
19
|
}
|
|
20
|
-
export
|
|
20
|
+
export const FullscreenControl = memo(_FullscreenControl);
|
|
21
21
|
//# sourceMappingURL=fullscreen-control.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fullscreen-control.js","names":["useEffect","memo","applyReactStyle","useControl","
|
|
1
|
+
{"version":3,"file":"fullscreen-control.js","names":["useEffect","memo","applyReactStyle","useControl","_FullscreenControl","props","ctrl","_ref","mapLib","FullscreenControl","container","containerId","document","getElementById","position","_controlContainer","style"],"sources":["../../src/components/fullscreen-control.ts"],"sourcesContent":["/* global document */\nimport * as React from \"react\";\nimport { useEffect, memo } from \"react\";\nimport { applyReactStyle } from \"../utils/apply-react-style\";\nimport { useControl } from \"./use-control\";\n\nimport type { ControlPosition, FullscreenControlOptions } from \"../types/lib\";\n\nexport type FullscreenControlProps = Omit<\n FullscreenControlOptions,\n \"container\"\n> & {\n /** Id of the DOM element which should be made full screen. By default, the map container\n * element will be made full screen. */\n containerId?: string;\n /** Placement of the control relative to the map. */\n position?: ControlPosition;\n /** CSS style override, applied to the control's container */\n style?: React.CSSProperties;\n};\n\nfunction _FullscreenControl(props: FullscreenControlProps) {\n const ctrl = useControl(\n ({ mapLib }) =>\n new mapLib.FullscreenControl({\n container:\n props.containerId && document.getElementById(props.containerId),\n }),\n { position: props.position },\n );\n\n useEffect(() => {\n applyReactStyle(ctrl._controlContainer, props.style);\n }, [props.style]);\n\n return null;\n}\n\nexport const FullscreenControl: React.FC<FullscreenControlProps> =\n memo(_FullscreenControl);\n"],"mappings":"AAEA,SAASA,SAAS,EAAEC,IAAI,QAAQ,OAAO;AAAC,SAC/BC,eAAe;AAAA,SACfC,UAAU;AAiBnB,SAASC,kBAAkBA,CAACC,KAA6B,EAAE;EACzD,MAAMC,IAAI,GAAGH,UAAU,CACrBI,IAAA;IAAA,IAAC;MAAEC;IAAO,CAAC,GAAAD,IAAA;IAAA,OACT,IAAIC,MAAM,CAACC,iBAAiB,CAAC;MAC3BC,SAAS,EACPL,KAAK,CAACM,WAAW,IAAIC,QAAQ,CAACC,cAAc,CAACR,KAAK,CAACM,WAAW;IAClE,CAAC,CAAC;EAAA,GACJ;IAAEG,QAAQ,EAAET,KAAK,CAACS;EAAS,CAC7B,CAAC;EAEDd,SAAS,CAAC,MAAM;IACdE,eAAe,CAACI,IAAI,CAACS,iBAAiB,EAAEV,KAAK,CAACW,KAAK,CAAC;EACtD,CAAC,EAAE,CAACX,KAAK,CAACW,KAAK,CAAC,CAAC;EAEjB,OAAO,IAAI;AACb;AAEA,OAAO,MAAMP,iBAAmD,GAC9DR,IAAI,CAACG,kBAAkB,CAAC","ignoreList":[]}
|
|
@@ -1,37 +1,21 @@
|
|
|
1
|
-
import * as React from
|
|
2
|
-
import type { ControlPosition,
|
|
3
|
-
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { ControlPosition, GeolocateControlOptions } from "../types/lib";
|
|
3
|
+
import type { GeolocateEvent, GeolocateResultEvent, GeolocateErrorEvent } from "../types/events";
|
|
4
|
+
export type GeolocateControlProps = GeolocateControlOptions & {
|
|
4
5
|
/** Placement of the control relative to the map. */
|
|
5
6
|
position?: ControlPosition;
|
|
6
7
|
/** CSS style override, applied to the control's container */
|
|
7
8
|
style?: React.CSSProperties;
|
|
8
9
|
/** Called on each Geolocation API position update that returned as success. */
|
|
9
|
-
onGeolocate?: (e: GeolocateResultEvent
|
|
10
|
+
onGeolocate?: (e: GeolocateResultEvent) => void;
|
|
10
11
|
/** Called on each Geolocation API position update that returned as an error. */
|
|
11
|
-
onError?: (e: GeolocateErrorEvent
|
|
12
|
+
onError?: (e: GeolocateErrorEvent) => void;
|
|
12
13
|
/** Called on each Geolocation API position update that returned as success but user position
|
|
13
14
|
* is out of map `maxBounds`. */
|
|
14
|
-
onOutOfMaxBounds?: (e: GeolocateResultEvent
|
|
15
|
+
onOutOfMaxBounds?: (e: GeolocateResultEvent) => void;
|
|
15
16
|
/** Called when the GeolocateControl changes to the active lock state. */
|
|
16
|
-
onTrackUserLocationStart?: (e: GeolocateEvent
|
|
17
|
+
onTrackUserLocationStart?: (e: GeolocateEvent) => void;
|
|
17
18
|
/** Called when the GeolocateControl changes to the background state. */
|
|
18
|
-
onTrackUserLocationEnd?: (e: GeolocateEvent
|
|
19
|
+
onTrackUserLocationEnd?: (e: GeolocateEvent) => void;
|
|
19
20
|
};
|
|
20
|
-
declare const
|
|
21
|
-
/** Placement of the control relative to the map. */
|
|
22
|
-
position?: ControlPosition;
|
|
23
|
-
/** CSS style override, applied to the control's container */
|
|
24
|
-
style?: React.CSSProperties;
|
|
25
|
-
/** Called on each Geolocation API position update that returned as success. */
|
|
26
|
-
onGeolocate?: (e: GeolocateResultEvent<GeolocateControlInstance>) => void;
|
|
27
|
-
/** Called on each Geolocation API position update that returned as an error. */
|
|
28
|
-
onError?: (e: GeolocateErrorEvent<GeolocateControlInstance>) => void;
|
|
29
|
-
/** Called on each Geolocation API position update that returned as success but user position
|
|
30
|
-
* is out of map `maxBounds`. */
|
|
31
|
-
onOutOfMaxBounds?: (e: GeolocateResultEvent<GeolocateControlInstance>) => void;
|
|
32
|
-
/** Called when the GeolocateControl changes to the active lock state. */
|
|
33
|
-
onTrackUserLocationStart?: (e: GeolocateEvent<GeolocateControlInstance>) => void;
|
|
34
|
-
/** Called when the GeolocateControl changes to the background state. */
|
|
35
|
-
onTrackUserLocationEnd?: (e: GeolocateEvent<GeolocateControlInstance>) => void;
|
|
36
|
-
} & React.RefAttributes<GeolocateControlInstance>>>;
|
|
37
|
-
export default _default;
|
|
21
|
+
export declare const GeolocateControl: React.FC<GeolocateControlProps>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { useImperativeHandle, useRef, useEffect, forwardRef, memo } from
|
|
1
|
+
import { useImperativeHandle, useRef, useEffect, forwardRef, memo } from "react";
|
|
2
2
|
import { applyReactStyle } from "../utils/apply-react-style.js";
|
|
3
|
-
import useControl from "./use-control.js";
|
|
4
|
-
function
|
|
3
|
+
import { useControl } from "./use-control.js";
|
|
4
|
+
function _GeolocateControl(props, ref) {
|
|
5
5
|
const thisRef = useRef({
|
|
6
6
|
props
|
|
7
7
|
});
|
|
@@ -11,24 +11,24 @@ function GeolocateControl(props, ref) {
|
|
|
11
11
|
} = _ref;
|
|
12
12
|
const gc = new mapLib.GeolocateControl(props);
|
|
13
13
|
const setupUI = gc._setupUI;
|
|
14
|
-
gc._setupUI =
|
|
14
|
+
gc._setupUI = () => {
|
|
15
15
|
if (!gc._container.hasChildNodes()) {
|
|
16
|
-
setupUI(
|
|
16
|
+
setupUI();
|
|
17
17
|
}
|
|
18
18
|
};
|
|
19
|
-
gc.on(
|
|
19
|
+
gc.on("geolocate", e => {
|
|
20
20
|
thisRef.current.props.onGeolocate?.(e);
|
|
21
21
|
});
|
|
22
|
-
gc.on(
|
|
22
|
+
gc.on("error", e => {
|
|
23
23
|
thisRef.current.props.onError?.(e);
|
|
24
24
|
});
|
|
25
|
-
gc.on(
|
|
25
|
+
gc.on("outofmaxbounds", e => {
|
|
26
26
|
thisRef.current.props.onOutOfMaxBounds?.(e);
|
|
27
27
|
});
|
|
28
|
-
gc.on(
|
|
28
|
+
gc.on("trackuserlocationstart", e => {
|
|
29
29
|
thisRef.current.props.onTrackUserLocationStart?.(e);
|
|
30
30
|
});
|
|
31
|
-
gc.on(
|
|
31
|
+
gc.on("trackuserlocationend", e => {
|
|
32
32
|
thisRef.current.props.onTrackUserLocationEnd?.(e);
|
|
33
33
|
});
|
|
34
34
|
return gc;
|
|
@@ -42,5 +42,5 @@ function GeolocateControl(props, ref) {
|
|
|
42
42
|
}, [props.style]);
|
|
43
43
|
return null;
|
|
44
44
|
}
|
|
45
|
-
export
|
|
45
|
+
export const GeolocateControl = memo(forwardRef(_GeolocateControl));
|
|
46
46
|
//# sourceMappingURL=geolocate-control.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geolocate-control.js","names":["useImperativeHandle","useRef","useEffect","forwardRef","memo","applyReactStyle","useControl","
|
|
1
|
+
{"version":3,"file":"geolocate-control.js","names":["useImperativeHandle","useRef","useEffect","forwardRef","memo","applyReactStyle","useControl","_GeolocateControl","props","ref","thisRef","ctrl","_ref","mapLib","gc","GeolocateControl","setupUI","_setupUI","_container","hasChildNodes","on","e","current","onGeolocate","onError","onOutOfMaxBounds","onTrackUserLocationStart","onTrackUserLocationEnd","position","style"],"sources":["../../src/components/geolocate-control.ts"],"sourcesContent":["import * as React from \"react\";\nimport {\n useImperativeHandle,\n useRef,\n useEffect,\n forwardRef,\n memo,\n} from \"react\";\nimport { applyReactStyle } from \"../utils/apply-react-style\";\nimport { useControl } from \"./use-control\";\n\nimport type {\n ControlPosition,\n GeolocateControl as GeolocateControlInstance,\n GeolocateControlOptions,\n} from \"../types/lib\";\nimport type {\n GeolocateEvent,\n GeolocateResultEvent,\n GeolocateErrorEvent,\n} from \"../types/events\";\n\nexport type GeolocateControlProps = GeolocateControlOptions & {\n /** Placement of the control relative to the map. */\n position?: ControlPosition;\n /** CSS style override, applied to the control's container */\n style?: React.CSSProperties;\n\n /** Called on each Geolocation API position update that returned as success. */\n onGeolocate?: (e: GeolocateResultEvent) => void;\n /** Called on each Geolocation API position update that returned as an error. */\n onError?: (e: GeolocateErrorEvent) => void;\n /** Called on each Geolocation API position update that returned as success but user position\n * is out of map `maxBounds`. */\n onOutOfMaxBounds?: (e: GeolocateResultEvent) => void;\n /** Called when the GeolocateControl changes to the active lock state. */\n onTrackUserLocationStart?: (e: GeolocateEvent) => void;\n /** Called when the GeolocateControl changes to the background state. */\n onTrackUserLocationEnd?: (e: GeolocateEvent) => void;\n};\n\nfunction _GeolocateControl(\n props: GeolocateControlProps,\n ref: React.Ref<GeolocateControlInstance>,\n) {\n const thisRef = useRef({ props });\n\n const ctrl = useControl(\n ({ mapLib }) => {\n const gc = new mapLib.GeolocateControl(props);\n\n // Hack: fix GeolocateControl reuse\n // When using React strict mode, the component is mounted twice.\n // GeolocateControl's UI creation is asynchronous. Removing and adding it back causes the UI to be initialized twice.\n const setupUI = gc._setupUI;\n gc._setupUI = () => {\n if (!gc._container.hasChildNodes()) {\n setupUI();\n }\n };\n\n gc.on(\"geolocate\", (e) => {\n thisRef.current.props.onGeolocate?.(e as GeolocateResultEvent);\n });\n gc.on(\"error\", (e) => {\n thisRef.current.props.onError?.(e as GeolocateErrorEvent);\n });\n gc.on(\"outofmaxbounds\", (e) => {\n thisRef.current.props.onOutOfMaxBounds?.(e as GeolocateResultEvent);\n });\n gc.on(\"trackuserlocationstart\", (e) => {\n thisRef.current.props.onTrackUserLocationStart?.(e as GeolocateEvent);\n });\n gc.on(\"trackuserlocationend\", (e) => {\n thisRef.current.props.onTrackUserLocationEnd?.(e as GeolocateEvent);\n });\n\n return gc;\n },\n { position: props.position },\n );\n\n thisRef.current.props = props;\n\n useImperativeHandle(ref, () => ctrl, []);\n\n useEffect(() => {\n applyReactStyle(ctrl._container, props.style);\n }, [props.style]);\n\n return null;\n}\n\nexport const GeolocateControl: React.FC<GeolocateControlProps> = memo(\n forwardRef(_GeolocateControl),\n);\n"],"mappings":"AACA,SACEA,mBAAmB,EACnBC,MAAM,EACNC,S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,CAACd,KAAK,CAACmB,sBAAsB,GAAGN,CAAmB,CAAC;IACrE,CAAC,CAAC;IAEF,OAAOP,EAAE;EACX,CAAC,EACD;IAAEc,QAAQ,EAAEpB,KAAK,CAACoB;EAAS,CAC7B,CAAC;EAEDlB,OAAO,CAACY,OAAO,CAACd,KAAK,GAAGA,KAAK;EAE7BR,mBAAmB,CAACS,GAAG,EAAE,MAAME,IAAI,EAAE,EAAE,CAAC;EAExCT,SAAS,CAAC,MAAM;IACdG,eAAe,CAACM,IAAI,CAACO,UAAU,EAAEV,KAAK,CAACqB,KAAK,CAAC;EAC/C,CAAC,EAAE,CAACrB,KAAK,CAACqB,KAAK,CAAC,CAAC;EAEjB,OAAO,IAAI;AACb;AAEA,OAAO,MAAMd,gBAAiD,GAAGX,IAAI,CACnED,UAAU,CAACI,iBAAiB,CAC9B,CAAC","ignoreList":[]}
|
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
import type { CustomLayerInterface
|
|
1
|
+
import type { CustomLayerInterface } from "../types/lib";
|
|
2
|
+
import type { LayerSpecification } from "../types/style-spec";
|
|
2
3
|
type OptionalId<T> = T extends {
|
|
3
4
|
id: string;
|
|
4
|
-
} ? Omit<T,
|
|
5
|
+
} ? Omit<T, "id"> & {
|
|
5
6
|
id?: string;
|
|
6
7
|
} : T;
|
|
7
8
|
type OptionalSource<T> = T extends {
|
|
8
9
|
source: string;
|
|
9
|
-
} ? Omit<T,
|
|
10
|
+
} ? Omit<T, "source"> & {
|
|
10
11
|
source?: string;
|
|
11
12
|
} : T;
|
|
12
|
-
export type LayerProps
|
|
13
|
+
export type LayerProps = (OptionalSource<OptionalId<LayerSpecification>> | CustomLayerInterface) & {
|
|
13
14
|
/** If set, the layer will be inserted before the specified layer */
|
|
14
15
|
beforeId?: string;
|
|
15
16
|
};
|
|
16
|
-
declare function Layer
|
|
17
|
-
export
|
|
17
|
+
export declare function Layer(props: LayerProps): any;
|
|
18
|
+
export {};
|
package/dist/components/layer.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { useContext, useEffect, useMemo, useState, useRef } from
|
|
1
|
+
import { useContext, useEffect, useMemo, useState, useRef } from "react";
|
|
2
2
|
import { MapContext } from "./map.js";
|
|
3
3
|
import assert from "../utils/assert.js";
|
|
4
4
|
import { deepEqual } from "../utils/deep-equal.js";
|
|
5
5
|
function updateLayer(map, id, props, prevProps) {
|
|
6
|
-
assert(props.id === prevProps.id,
|
|
7
|
-
assert(props.type === prevProps.type,
|
|
8
|
-
if (props.type ===
|
|
6
|
+
assert(props.id === prevProps.id, "layer id changed");
|
|
7
|
+
assert(props.type === prevProps.type, "layer type changed");
|
|
8
|
+
if (props.type === "custom" || prevProps.type === "custom") {
|
|
9
9
|
return;
|
|
10
10
|
}
|
|
11
11
|
const {
|
|
@@ -53,7 +53,7 @@ function updateLayer(map, id, props, prevProps) {
|
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
function createLayer(map, id, props) {
|
|
56
|
-
if (map.style && map.style._loaded && (!(
|
|
56
|
+
if (map.style && map.style._loaded && (!("source" in props) || map.getSource(props.source))) {
|
|
57
57
|
const options = {
|
|
58
58
|
...props,
|
|
59
59
|
id
|
|
@@ -63,7 +63,7 @@ function createLayer(map, id, props) {
|
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
let layerCounter = 0;
|
|
66
|
-
function Layer(props) {
|
|
66
|
+
export function Layer(props) {
|
|
67
67
|
const map = useContext(MapContext).map.getMap();
|
|
68
68
|
const propsRef = useRef(props);
|
|
69
69
|
const [, setStyleLoaded] = useState(0);
|
|
@@ -71,10 +71,10 @@ function Layer(props) {
|
|
|
71
71
|
useEffect(() => {
|
|
72
72
|
if (map) {
|
|
73
73
|
const forceUpdate = () => setStyleLoaded(version => version + 1);
|
|
74
|
-
map.on(
|
|
74
|
+
map.on("styledata", forceUpdate);
|
|
75
75
|
forceUpdate();
|
|
76
76
|
return () => {
|
|
77
|
-
map.off(
|
|
77
|
+
map.off("styledata", forceUpdate);
|
|
78
78
|
if (map.style && map.style._loaded && map.getLayer(id)) {
|
|
79
79
|
map.removeLayer(id);
|
|
80
80
|
}
|
|
@@ -95,5 +95,4 @@ function Layer(props) {
|
|
|
95
95
|
propsRef.current = props;
|
|
96
96
|
return null;
|
|
97
97
|
}
|
|
98
|
-
export default Layer;
|
|
99
98
|
//# sourceMappingURL=layer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"layer.js","names":["useContext","useEffect","useMemo","useState","useRef","MapContext","assert","deepEqual","updateLayer","map","id","props","prevProps","type","layout","paint","filter","minzoom","maxzoom","beforeId","moveLayer","prevLayout","key","setLayoutProperty","hasOwnProperty","undefined","prevPaint","setPaintProperty","setFilter","setLayerZoomRange","createLayer","style","_loaded","getSource","source","options","addLayer","layerCounter","Layer","getMap","propsRef","setStyleLoaded","forceUpdate","version","on","off","getLayer","removeLayer","layer","current","error","console","warn"],"sources":["../../src/components/layer.ts"],"sourcesContent":["import {useContext, useEffect, useMemo, useState, useRef} from
|
|
1
|
+
{"version":3,"file":"layer.js","names":["useContext","useEffect","useMemo","useState","useRef","MapContext","assert","deepEqual","updateLayer","map","id","props","prevProps","type","layout","paint","filter","minzoom","maxzoom","beforeId","moveLayer","prevLayout","key","setLayoutProperty","hasOwnProperty","undefined","prevPaint","setPaintProperty","setFilter","setLayerZoomRange","createLayer","style","_loaded","getSource","source","options","addLayer","layerCounter","Layer","getMap","propsRef","setStyleLoaded","forceUpdate","version","on","off","getLayer","removeLayer","layer","current","error","console","warn"],"sources":["../../src/components/layer.ts"],"sourcesContent":["import { useContext, useEffect, useMemo, useState, useRef } from \"react\";\nimport { MapContext } from \"./map\";\nimport assert from \"../utils/assert\";\nimport { deepEqual } from \"../utils/deep-equal\";\n\nimport type { Map as MapInstance, CustomLayerInterface } from \"../types/lib\";\nimport type { LayerSpecification } from \"../types/style-spec\";\n\n// Omiting property from a union type, see\n// https://github.com/microsoft/TypeScript/issues/39556#issuecomment-656925230\ntype OptionalId<T> = T extends { id: string }\n ? Omit<T, \"id\"> & { id?: string }\n : T;\ntype OptionalSource<T> = T extends { source: string }\n ? Omit<T, \"source\"> & { source?: string }\n : T;\n\nexport type LayerProps = (\n | OptionalSource<OptionalId<LayerSpecification>>\n | CustomLayerInterface\n) & {\n /** If set, the layer will be inserted before the specified layer */\n beforeId?: string;\n};\n\n/* eslint-disable complexity, max-statements */\nfunction updateLayer(\n map: MapInstance,\n id: string,\n props: LayerProps,\n prevProps: LayerProps,\n) {\n assert(props.id === prevProps.id, \"layer id changed\");\n assert(props.type === prevProps.type, \"layer type changed\");\n\n if (props.type === \"custom\" || prevProps.type === \"custom\") {\n return;\n }\n\n // @ts-ignore filter does not exist in some Layer types\n const { layout = {}, paint = {}, filter, minzoom, maxzoom, beforeId } = props;\n\n if (beforeId !== prevProps.beforeId) {\n map.moveLayer(id, beforeId);\n }\n if (layout !== prevProps.layout) {\n const prevLayout = prevProps.layout || {};\n for (const key in layout) {\n if (!deepEqual(layout[key], prevLayout[key])) {\n map.setLayoutProperty(id, key, layout[key]);\n }\n }\n for (const key in prevLayout) {\n if (!layout.hasOwnProperty(key)) {\n map.setLayoutProperty(id, key, undefined);\n }\n }\n }\n if (paint !== prevProps.paint) {\n const prevPaint = prevProps.paint || {};\n for (const key in paint) {\n if (!deepEqual(paint[key], prevPaint[key])) {\n map.setPaintProperty(id, key, paint[key]);\n }\n }\n for (const key in prevPaint) {\n if (!paint.hasOwnProperty(key)) {\n map.setPaintProperty(id, key, undefined);\n }\n }\n }\n\n // @ts-ignore filter does not exist in some Layer types\n if (!deepEqual(filter, prevProps.filter)) {\n map.setFilter(id, filter);\n }\n if (minzoom !== prevProps.minzoom || maxzoom !== prevProps.maxzoom) {\n map.setLayerZoomRange(id, minzoom, maxzoom);\n }\n}\n\nfunction createLayer(map: MapInstance, id: string, props: LayerProps) {\n // @ts-ignore\n if (\n map.style &&\n map.style._loaded &&\n (!(\"source\" in props) || map.getSource(props.source))\n ) {\n const options: LayerProps = { ...props, id };\n delete options.beforeId;\n\n // @ts-ignore\n map.addLayer(options, props.beforeId);\n }\n}\n\n/* eslint-enable complexity, max-statements */\n\nlet layerCounter = 0;\n\nexport function Layer(props: LayerProps) {\n const map = useContext(MapContext).map.getMap();\n const propsRef = useRef(props);\n const [, setStyleLoaded] = useState(0);\n\n const id = useMemo(() => props.id || `jsx-layer-${layerCounter++}`, []);\n\n useEffect(() => {\n if (map) {\n const forceUpdate = () => setStyleLoaded((version) => version + 1);\n map.on(\"styledata\", forceUpdate);\n forceUpdate();\n\n return () => {\n map.off(\"styledata\", forceUpdate);\n // @ts-ignore\n if (map.style && map.style._loaded && map.getLayer(id)) {\n map.removeLayer(id);\n }\n };\n }\n return undefined;\n }, [map]);\n\n // @ts-ignore\n const layer = map && map.style && map.getLayer(id);\n if (layer) {\n try {\n updateLayer(map, id, props, propsRef.current);\n } catch (error) {\n console.warn(error); // eslint-disable-line\n }\n } else {\n createLayer(map, id, props);\n }\n\n // Store last rendered props\n propsRef.current = props;\n\n return null;\n}\n"],"mappings":"AAAA,SAASA,UAAU,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,EAAEC,MAAM,QAAQ,OAAO;AAAC,SAChEC,UAAU;AAAA,OACZC,MAAM;AAAA,SACJC,SAAS;AAuBlB,SAASC,WAAWA,CAClBC,GAAgB,EAChBC,EAAU,EACVC,KAAiB,EACjBC,SAAqB,EACrB;EACAN,MAAM,CAACK,KAAK,CAACD,EAAE,KAAKE,SAAS,CAACF,EAAE,EAAE,kBAAkB,CAAC;EACrDJ,MAAM,CAACK,KAAK,CAACE,IAAI,KAAKD,SAAS,CAACC,IAAI,EAAE,oBAAoB,CAAC;EAE3D,IAAIF,KAAK,CAACE,IAAI,KAAK,QAAQ,IAAID,SAAS,CAACC,IAAI,KAAK,QAAQ,EAAE;IAC1D;EACF;EAGA,MAAM;IAAEC,MAAM,GAAG,CAAC,CAAC;IAAEC,KAAK,GAAG,CAAC,CAAC;IAAEC,MA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C,SAAS,CAAC,MAAM;IACd,IAAIQ,GAAG,EAAE;MACP,MAAMiC,WAAW,GAAGA,CAAA,KAAMD,cAAc,CAAEE,OAAO,IAAKA,OAAO,GAAG,CAAC,CAAC;MAClElC,GAAG,CAACmC,EAAE,CAAC,WAAW,EAAEF,WAAW,CAAC;MAChCA,WAAW,CAAC,CAAC;MAEb,OAAO,MAAM;QACXjC,GAAG,CAACoC,GAAG,CAAC,WAAW,EAAEH,WAAW,CAAC;QAEjC,IAAIjC,GAAG,CAACsB,KAAK,IAAItB,GAAG,CAACsB,KAAK,CAACC,OAAO,IAAIvB,GAAG,CAACqC,QAAQ,CAACpC,EAAE,CAAC,EAAE;UACtDD,GAAG,CAACsC,WAAW,CAACrC,EAAE,CAAC;QACrB;MACF,CAAC;IACH;IACA,OAAOe,SAAS;EAClB,CAAC,EAAE,CAAChB,GAAG,CAAC,CAAC;EAGT,MAAMuC,KAAK,GAAGvC,GAAG,IAAIA,GAAG,CAACsB,KAAK,IAAItB,GAAG,CAACqC,QAAQ,CAACpC,EAAE,CAAC;EAClD,IAAIsC,KAAK,EAAE;IACT,IAAI;MACFxC,WAAW,CAACC,GAAG,EAAEC,EAAE,EAAEC,KAAK,EAAE6B,QAAQ,CAACS,OAAO,CAAC;IAC/C,CAAC,CAAC,OAAOC,KAAK,EAAE;MACdC,OAAO,CAACC,IAAI,CAACF,KAAK,CAAC;IACrB;EACF,CAAC,MAAM;IACLpB,WAAW,CAACrB,GAAG,EAAEC,EAAE,EAAEC,KAAK,CAAC;EAC7B;EAGA6B,QAAQ,CAACS,OAAO,GAAGtC,KAAK;EAExB,OAAO,IAAI;AACb","ignoreList":[]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { ControlPosition, LogoControlOptions } from "../types/lib";
|
|
3
|
+
export type LogoControlProps = LogoControlOptions & {
|
|
4
|
+
/** Placement of the control relative to the map. */
|
|
5
|
+
position?: ControlPosition;
|
|
6
|
+
/** CSS style override, applied to the control's container */
|
|
7
|
+
style?: React.CSSProperties;
|
|
8
|
+
};
|
|
9
|
+
export declare const LogoControl: React.FC<LogoControlProps>;
|