react-bkoi-gl 1.0.1
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 +96 -0
- package/bkoi-gl/package.json +6 -0
- package/dist/components/attribution-control.d.ts +11 -0
- package/dist/components/attribution-control.js +19 -0
- package/dist/components/attribution-control.js.map +1 -0
- package/dist/components/fullscreen-control.d.ts +14 -0
- package/dist/components/fullscreen-control.js +21 -0
- package/dist/components/fullscreen-control.js.map +1 -0
- package/dist/components/geolocate-control.d.ts +37 -0
- package/dist/components/geolocate-control.js +51 -0
- package/dist/components/geolocate-control.js.map +1 -0
- package/dist/components/layer.d.ts +17 -0
- package/dist/components/layer.js +99 -0
- package/dist/components/layer.js.map +1 -0
- package/dist/components/map.d.ts +23 -0
- package/dist/components/map.js +102 -0
- package/dist/components/map.js.map +1 -0
- package/dist/components/marker.d.ts +41 -0
- package/dist/components/marker.js +102 -0
- package/dist/components/marker.js.map +1 -0
- package/dist/components/navigation-control.d.ts +11 -0
- package/dist/components/navigation-control.js +19 -0
- package/dist/components/navigation-control.js.map +1 -0
- package/dist/components/popup.d.ts +33 -0
- package/dist/components/popup.js +81 -0
- package/dist/components/popup.js.map +1 -0
- package/dist/components/scale-control.d.ts +13 -0
- package/dist/components/scale-control.js +31 -0
- package/dist/components/scale-control.js.map +1 -0
- package/dist/components/source.d.ts +7 -0
- package/dist/components/source.js +98 -0
- package/dist/components/source.js.map +1 -0
- package/dist/components/use-control.d.ts +9 -0
- package/dist/components/use-control.js +31 -0
- package/dist/components/use-control.js.map +1 -0
- package/dist/components/use-map.d.ts +20 -0
- package/dist/components/use-map.js +55 -0
- package/dist/components/use-map.js.map +1 -0
- package/dist/exports-bkoi-gl.cjs +1512 -0
- package/dist/exports-bkoi-gl.d.ts +89 -0
- package/dist/exports-bkoi-gl.js +36 -0
- package/dist/exports-bkoi-gl.js.map +1 -0
- package/dist/exports-mapbox.d.ts +139 -0
- package/dist/exports-mapbox.js +36 -0
- package/dist/exports-mapbox.js.map +1 -0
- package/dist/index.cjs +1514 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/mapbox/create-ref.d.ts +9 -0
- package/dist/mapbox/create-ref.js +64 -0
- package/dist/mapbox/create-ref.js.map +1 -0
- package/dist/mapbox/mapbox.d.ts +81 -0
- package/dist/mapbox/mapbox.js +477 -0
- package/dist/mapbox/mapbox.js.map +1 -0
- package/dist/styles/react-bkoi-gl.css +1 -0
- package/dist/types/common.d.ts +78 -0
- package/dist/types/common.js +2 -0
- package/dist/types/common.js.map +1 -0
- package/dist/types/events-bkoi-gl.d.ts +49 -0
- package/dist/types/events-bkoi-gl.js +2 -0
- package/dist/types/events-bkoi-gl.js.map +1 -0
- package/dist/types/events-mapbox.d.ts +49 -0
- package/dist/types/events-mapbox.js +2 -0
- package/dist/types/events-mapbox.js.map +1 -0
- package/dist/types/events.d.ts +39 -0
- package/dist/types/events.js +2 -0
- package/dist/types/events.js.map +1 -0
- package/dist/types/index.d.ts +70 -0
- package/dist/types/index.js +5 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/lib.d.ts +224 -0
- package/dist/types/lib.js +2 -0
- package/dist/types/lib.js.map +1 -0
- package/dist/types/public.d.ts +2 -0
- package/dist/types/public.js +2 -0
- package/dist/types/public.js.map +1 -0
- package/dist/types/style-spec-bkoi-gl.d.ts +9 -0
- package/dist/types/style-spec-bkoi-gl.js +2 -0
- package/dist/types/style-spec-bkoi-gl.js.map +1 -0
- package/dist/types/style-spec-mapbox.d.ts +7 -0
- package/dist/types/style-spec-mapbox.js +2 -0
- package/dist/types/style-spec-mapbox.js.map +1 -0
- package/dist/utils/apply-react-style.d.ts +2 -0
- package/dist/utils/apply-react-style.js +16 -0
- package/dist/utils/apply-react-style.js.map +1 -0
- package/dist/utils/assert.d.ts +1 -0
- package/dist/utils/assert.js +6 -0
- package/dist/utils/assert.js.map +1 -0
- package/dist/utils/deep-equal.d.ts +15 -0
- package/dist/utils/deep-equal.js +46 -0
- package/dist/utils/deep-equal.js.map +1 -0
- package/dist/utils/set-globals.d.ts +22 -0
- package/dist/utils/set-globals.js +19 -0
- package/dist/utils/set-globals.js.map +1 -0
- package/dist/utils/style-utils.d.ts +2 -0
- package/dist/utils/style-utils.js +42 -0
- package/dist/utils/style-utils.js.map +1 -0
- package/dist/utils/transform.d.ts +26 -0
- package/dist/utils/transform.js +56 -0
- package/dist/utils/transform.js.map +1 -0
- package/dist/utils/use-isomorphic-layout-effect.d.ts +3 -0
- package/dist/utils/use-isomorphic-layout-effect.js +4 -0
- package/dist/utils/use-isomorphic-layout-effect.js.map +1 -0
- package/package.json +78 -0
- package/src/components/attribution-control.ts +32 -0
- package/src/components/fullscreen-control.tsx +37 -0
- package/src/components/geolocate-control.ts +90 -0
- package/src/components/layer.ts +133 -0
- package/src/components/map.tsx +155 -0
- package/src/components/marker.ts +137 -0
- package/src/components/navigation-control.ts +29 -0
- package/src/components/popup.ts +116 -0
- package/src/components/scale-control.ts +46 -0
- package/src/components/source.ts +158 -0
- package/src/components/use-control.ts +64 -0
- package/src/components/use-map.tsx +69 -0
- package/src/exports-bkoi-gl.ts +156 -0
- package/src/exports-mapbox.ts +159 -0
- package/src/index.ts +2 -0
- package/src/mapbox/create-ref.ts +118 -0
- package/src/mapbox/mapbox.ts +742 -0
- package/src/types/common.ts +94 -0
- package/src/types/events-bkoi-gl.ts +78 -0
- package/src/types/events-mapbox.ts +76 -0
- package/src/types/events.ts +73 -0
- package/src/types/index.ts +93 -0
- package/src/types/lib.ts +279 -0
- package/src/types/public.ts +9 -0
- package/src/types/style-spec-bkoi-gl.ts +81 -0
- package/src/types/style-spec-mapbox.ts +80 -0
- package/src/utils/apply-react-style.ts +20 -0
- package/src/utils/assert.ts +5 -0
- package/src/utils/deep-equal.ts +61 -0
- package/src/utils/set-globals.ts +57 -0
- package/src/utils/style-utils.ts +59 -0
- package/src/utils/transform.ts +86 -0
- package/src/utils/use-isomorphic-layout-effect.ts +7 -0
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["default"],"sources":["../src/index.ts"],"sourcesContent":["export * from './exports-mapbox';\nexport {default as default} from './exports-mapbox';\n"],"mappings":";SACQA,OAAkB","ignoreList":[]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { MapInstance, MapStyle, Callbacks } from '../types';
|
|
2
|
+
import type Mapbox from './mapbox';
|
|
3
|
+
/** These methods may break the react binding if called directly */
|
|
4
|
+
declare const skipMethods: readonly ["setMaxBounds", "setMinZoom", "setMaxZoom", "setMinPitch", "setMaxPitch", "setRenderWorldCopies", "setProjection", "setStyle", "addSource", "removeSource", "addLayer", "removeLayer", "setLayerZoomRange", "setFilter", "setPaintProperty", "setLayoutProperty", "setLight", "setTerrain", "setFog", "remove"];
|
|
5
|
+
export declare type MapRef<MapT extends MapInstance> = {
|
|
6
|
+
getMap(): MapT;
|
|
7
|
+
} & Omit<MapT, typeof skipMethods[number]>;
|
|
8
|
+
export default function createRef<StyleT extends MapStyle, CallbacksT extends Callbacks, MapT extends MapInstance>(mapInstance: Mapbox<StyleT, CallbacksT, MapT>): MapRef<MapT> | null;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
const skipMethods = ['setMaxBounds', 'setMinZoom', 'setMaxZoom', 'setMinPitch', 'setMaxPitch', 'setRenderWorldCopies', 'setProjection', 'setStyle', 'addSource', 'removeSource', 'addLayer', 'removeLayer', 'setLayerZoomRange', 'setFilter', 'setPaintProperty', 'setLayoutProperty', 'setLight', 'setTerrain', 'setFog', 'remove'];
|
|
2
|
+
export default function createRef(mapInstance) {
|
|
3
|
+
if (!mapInstance) {
|
|
4
|
+
return null;
|
|
5
|
+
}
|
|
6
|
+
const map = mapInstance.map;
|
|
7
|
+
const result = {
|
|
8
|
+
getMap: () => map,
|
|
9
|
+
getCenter: () => mapInstance.transform.center,
|
|
10
|
+
getZoom: () => mapInstance.transform.zoom,
|
|
11
|
+
getBearing: () => mapInstance.transform.bearing,
|
|
12
|
+
getPitch: () => mapInstance.transform.pitch,
|
|
13
|
+
getPadding: () => mapInstance.transform.padding,
|
|
14
|
+
getBounds: () => mapInstance.transform.getBounds(),
|
|
15
|
+
project: lnglat => {
|
|
16
|
+
const tr = map.transform;
|
|
17
|
+
map.transform = mapInstance.transform;
|
|
18
|
+
const result = map.project(lnglat);
|
|
19
|
+
map.transform = tr;
|
|
20
|
+
return result;
|
|
21
|
+
},
|
|
22
|
+
unproject: point => {
|
|
23
|
+
const tr = map.transform;
|
|
24
|
+
map.transform = mapInstance.transform;
|
|
25
|
+
const result = map.unproject(point);
|
|
26
|
+
map.transform = tr;
|
|
27
|
+
return result;
|
|
28
|
+
},
|
|
29
|
+
queryTerrainElevation: (lnglat, options) => {
|
|
30
|
+
const tr = map.transform;
|
|
31
|
+
map.transform = mapInstance.transform;
|
|
32
|
+
const result = map.queryTerrainElevation(lnglat, options);
|
|
33
|
+
map.transform = tr;
|
|
34
|
+
return result;
|
|
35
|
+
},
|
|
36
|
+
queryRenderedFeatures: (geometry, options) => {
|
|
37
|
+
const tr = map.transform;
|
|
38
|
+
map.transform = mapInstance.transform;
|
|
39
|
+
const result = map.queryRenderedFeatures(geometry, options);
|
|
40
|
+
map.transform = tr;
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
for (const key of getMethodNames(map)) {
|
|
45
|
+
if (!(key in result) && !skipMethods.includes(key)) {
|
|
46
|
+
result[key] = map[key].bind(map);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
function getMethodNames(obj) {
|
|
52
|
+
const result = new Set();
|
|
53
|
+
let proto = obj;
|
|
54
|
+
while (proto) {
|
|
55
|
+
for (const key of Object.getOwnPropertyNames(proto)) {
|
|
56
|
+
if (key[0] !== '_' && typeof obj[key] === 'function' && key !== 'fire' && key !== 'setEventedParent') {
|
|
57
|
+
result.add(key);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
proto = Object.getPrototypeOf(proto);
|
|
61
|
+
}
|
|
62
|
+
return Array.from(result);
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=create-ref.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-ref.js","names":["skipMethods","createRef","mapInstance","map","result","getMap","getCenter","transform","center","getZoom","zoom","getBearing","bearing","getPitch","pitch","getPadding","padding","getBounds","project","lnglat","tr","unproject","point","queryTerrainElevation","options","queryRenderedFeatures","geometry","key","getMethodNames","includes","bind","obj","Set","proto","Object","getOwnPropertyNames","add","getPrototypeOf","Array","from"],"sources":["../../src/mapbox/create-ref.ts"],"sourcesContent":["import type {\n MapInstance,\n MapInstanceInternal,\n MapStyle,\n Callbacks,\n LngLatLike,\n PointLike\n} from '../types';\nimport type Mapbox from './mapbox';\n\n/** These methods may break the react binding if called directly */\nconst skipMethods = [\n 'setMaxBounds',\n 'setMinZoom',\n 'setMaxZoom',\n 'setMinPitch',\n 'setMaxPitch',\n 'setRenderWorldCopies',\n 'setProjection',\n 'setStyle',\n 'addSource',\n 'removeSource',\n 'addLayer',\n 'removeLayer',\n 'setLayerZoomRange',\n 'setFilter',\n 'setPaintProperty',\n 'setLayoutProperty',\n 'setLight',\n 'setTerrain',\n 'setFog',\n 'remove'\n] as const;\n\nexport type MapRef<MapT extends MapInstance> = {\n getMap(): MapT;\n} & Omit<MapT, typeof skipMethods[number]>;\n\nexport default function createRef<\n StyleT extends MapStyle,\n CallbacksT extends Callbacks,\n MapT extends MapInstance\n>(mapInstance: Mapbox<StyleT, CallbacksT, MapT>): MapRef<MapT> | null {\n if (!mapInstance) {\n return null;\n }\n\n const map = mapInstance.map as MapInstanceInternal<MapT>;\n const result: any = {\n getMap: () => map,\n\n // Overwrite getters to use our shadow transform\n getCenter: () => mapInstance.transform.center,\n getZoom: () => mapInstance.transform.zoom,\n getBearing: () => mapInstance.transform.bearing,\n getPitch: () => mapInstance.transform.pitch,\n getPadding: () => mapInstance.transform.padding,\n getBounds: () => mapInstance.transform.getBounds(),\n project: (lnglat: LngLatLike) => {\n const tr = map.transform;\n map.transform = mapInstance.transform;\n const result = map.project(lnglat);\n map.transform = tr;\n return result;\n },\n unproject: (point: PointLike) => {\n const tr = map.transform;\n map.transform = mapInstance.transform;\n const result = map.unproject(point);\n map.transform = tr;\n return result;\n },\n // options diverge between mapbox and maplibre\n queryTerrainElevation: (lnglat: LngLatLike, options?: any) => {\n const tr = map.transform;\n map.transform = mapInstance.transform;\n const result = map.queryTerrainElevation(lnglat, options);\n map.transform = tr;\n return result;\n },\n queryRenderedFeatures: (geometry?: any, options?: any) => {\n const tr = map.transform;\n map.transform = mapInstance.transform;\n const result = map.queryRenderedFeatures(geometry, options);\n map.transform = tr;\n return result;\n }\n };\n\n for (const key of getMethodNames(map)) {\n // @ts-expect-error\n if (!(key in result) && !skipMethods.includes(key)) {\n result[key] = map[key].bind(map);\n }\n }\n\n return result;\n}\n\nfunction getMethodNames(obj: Object) {\n const result = new Set<string>();\n\n let proto = obj;\n while (proto) {\n for (const key of Object.getOwnPropertyNames(proto)) {\n if (\n key[0] !== '_' &&\n typeof obj[key] === 'function' &&\n key !== 'fire' &&\n key !== 'setEventedParent'\n ) {\n result.add(key);\n }\n }\n proto = Object.getPrototypeOf(proto);\n }\n return Array.from(result);\n}\n"],"mappings":"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","ignoreList":[]}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { Transform, ViewState, ViewStateChangeEvent, PointLike, PaddingOptions, MapStyle, ImmutableLike, LngLatBoundsLike, Callbacks, MapEvent, MapMouseEvent, MapInstance, MapInstanceInternal } from '../types';
|
|
2
|
+
export declare type MapboxProps<StyleT extends MapStyle = MapStyle, CallbacksT extends Callbacks = {}> = Partial<ViewState> & CallbacksT & {
|
|
3
|
+
mapboxAccessToken?: string;
|
|
4
|
+
/** Camera options used when constructing the Map instance */
|
|
5
|
+
initialViewState?: Partial<ViewState> & {
|
|
6
|
+
/** The initial bounds of the map. If bounds is specified, it overrides longitude, latitude and zoom options. */
|
|
7
|
+
bounds?: LngLatBoundsLike;
|
|
8
|
+
/** A fitBounds options object to use only when setting the bounds option. */
|
|
9
|
+
fitBoundsOptions?: {
|
|
10
|
+
offset?: PointLike;
|
|
11
|
+
minZoom?: number;
|
|
12
|
+
maxZoom?: number;
|
|
13
|
+
padding?: number | PaddingOptions;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
/** If provided, render into an external WebGL context */
|
|
17
|
+
gl?: WebGLRenderingContext;
|
|
18
|
+
/** For external controller to override the camera state */
|
|
19
|
+
viewState?: ViewState & {
|
|
20
|
+
width: number;
|
|
21
|
+
height: number;
|
|
22
|
+
};
|
|
23
|
+
/** Mapbox style */
|
|
24
|
+
mapStyle?: string | StyleT | ImmutableLike<StyleT>;
|
|
25
|
+
/** Enable diffing when the map style changes
|
|
26
|
+
* @default true
|
|
27
|
+
*/
|
|
28
|
+
styleDiffing?: boolean;
|
|
29
|
+
/** The fog property of the style. Must conform to the Fog Style Specification .
|
|
30
|
+
* If `undefined` is provided, removes the fog from the map. */
|
|
31
|
+
fog?: StyleT['fog'];
|
|
32
|
+
/** Light properties of the map. */
|
|
33
|
+
light?: StyleT['light'];
|
|
34
|
+
/** Terrain property of the style. Must conform to the Terrain Style Specification .
|
|
35
|
+
* If `undefined` is provided, removes terrain from the map. */
|
|
36
|
+
terrain?: StyleT['terrain'];
|
|
37
|
+
/** Default layers to query on pointer events */
|
|
38
|
+
interactiveLayerIds?: string[];
|
|
39
|
+
/** CSS cursor */
|
|
40
|
+
cursor?: string;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* A wrapper for mapbox-gl's Map class
|
|
44
|
+
*/
|
|
45
|
+
export default class Mapbox<StyleT extends MapStyle = MapStyle, CallbacksT extends Callbacks = {}, MapT extends MapInstance = MapInstance> {
|
|
46
|
+
private _MapClass;
|
|
47
|
+
private _map;
|
|
48
|
+
props: MapboxProps<StyleT, CallbacksT>;
|
|
49
|
+
private _renderTransform;
|
|
50
|
+
private _internalUpdate;
|
|
51
|
+
private _inRender;
|
|
52
|
+
private _hoveredFeatures;
|
|
53
|
+
private _deferredEvents;
|
|
54
|
+
static savedMaps: Mapbox[];
|
|
55
|
+
constructor(MapClass: {
|
|
56
|
+
new (options: any): MapInstance;
|
|
57
|
+
}, props: MapboxProps<StyleT, CallbacksT>, container: HTMLDivElement);
|
|
58
|
+
get map(): MapT;
|
|
59
|
+
get transform(): Transform;
|
|
60
|
+
setProps(props: MapboxProps<StyleT, CallbacksT>): void;
|
|
61
|
+
static reuse<StyleT extends MapStyle, CallbacksT extends Callbacks, MapT extends MapInstance>(props: MapboxProps<StyleT, CallbacksT>, container: HTMLDivElement): Mapbox<StyleT, CallbacksT, MapT>;
|
|
62
|
+
_initialize(container: HTMLDivElement): void;
|
|
63
|
+
recycle(): void;
|
|
64
|
+
destroy(): void;
|
|
65
|
+
redraw(): void;
|
|
66
|
+
_createShadowTransform(map: any): void;
|
|
67
|
+
_updateSize(nextProps: MapboxProps<StyleT>): boolean;
|
|
68
|
+
_updateViewState(nextProps: MapboxProps<StyleT>, triggerEvents: boolean): boolean;
|
|
69
|
+
_updateSettings(nextProps: MapboxProps<StyleT>, currProps: MapboxProps<StyleT>): boolean;
|
|
70
|
+
_updateStyle(nextProps: MapboxProps<StyleT>, currProps: MapboxProps<StyleT>): boolean;
|
|
71
|
+
_updateStyleComponents(nextProps: MapboxProps<StyleT>, currProps: MapboxProps<StyleT>): boolean;
|
|
72
|
+
_updateHandlers(nextProps: MapboxProps<StyleT>, currProps: MapboxProps<StyleT>): boolean;
|
|
73
|
+
_onEvent: (e: MapEvent<MapT>) => void;
|
|
74
|
+
private _queryRenderedFeatures;
|
|
75
|
+
_updateHover(e: MapMouseEvent<MapT>): void;
|
|
76
|
+
_onPointerEvent: (e: MapMouseEvent<MapT> | MapMouseEvent<MapT>) => void;
|
|
77
|
+
_onCameraEvent: (e: ViewStateChangeEvent<MapT>) => void;
|
|
78
|
+
_fireEvent(baseFire: Function, event: string | MapEvent<MapT>, properties?: object): MapInstanceInternal<MapT>;
|
|
79
|
+
_onBeforeRepaint(): void;
|
|
80
|
+
_onAfterRepaint: () => void;
|
|
81
|
+
}
|
|
@@ -0,0 +1,477 @@
|
|
|
1
|
+
import { transformToViewState, applyViewStateToTransform, cloneTransform, syncProjection } from "../utils/transform.js";
|
|
2
|
+
import { normalizeStyle } from "../utils/style-utils.js";
|
|
3
|
+
import { deepEqual } from "../utils/deep-equal.js";
|
|
4
|
+
const DEFAULT_STYLE = {
|
|
5
|
+
version: 8,
|
|
6
|
+
sources: {},
|
|
7
|
+
layers: []
|
|
8
|
+
};
|
|
9
|
+
const pointerEvents = {
|
|
10
|
+
mousedown: 'onMouseDown',
|
|
11
|
+
mouseup: 'onMouseUp',
|
|
12
|
+
mouseover: 'onMouseOver',
|
|
13
|
+
mousemove: 'onMouseMove',
|
|
14
|
+
click: 'onClick',
|
|
15
|
+
dblclick: 'onDblClick',
|
|
16
|
+
mouseenter: 'onMouseEnter',
|
|
17
|
+
mouseleave: 'onMouseLeave',
|
|
18
|
+
mouseout: 'onMouseOut',
|
|
19
|
+
contextmenu: 'onContextMenu',
|
|
20
|
+
touchstart: 'onTouchStart',
|
|
21
|
+
touchend: 'onTouchEnd',
|
|
22
|
+
touchmove: 'onTouchMove',
|
|
23
|
+
touchcancel: 'onTouchCancel'
|
|
24
|
+
};
|
|
25
|
+
const cameraEvents = {
|
|
26
|
+
movestart: 'onMoveStart',
|
|
27
|
+
move: 'onMove',
|
|
28
|
+
moveend: 'onMoveEnd',
|
|
29
|
+
dragstart: 'onDragStart',
|
|
30
|
+
drag: 'onDrag',
|
|
31
|
+
dragend: 'onDragEnd',
|
|
32
|
+
zoomstart: 'onZoomStart',
|
|
33
|
+
zoom: 'onZoom',
|
|
34
|
+
zoomend: 'onZoomEnd',
|
|
35
|
+
rotatestart: 'onRotateStart',
|
|
36
|
+
rotate: 'onRotate',
|
|
37
|
+
rotateend: 'onRotateEnd',
|
|
38
|
+
pitchstart: 'onPitchStart',
|
|
39
|
+
pitch: 'onPitch',
|
|
40
|
+
pitchend: 'onPitchEnd'
|
|
41
|
+
};
|
|
42
|
+
const otherEvents = {
|
|
43
|
+
wheel: 'onWheel',
|
|
44
|
+
boxzoomstart: 'onBoxZoomStart',
|
|
45
|
+
boxzoomend: 'onBoxZoomEnd',
|
|
46
|
+
boxzoomcancel: 'onBoxZoomCancel',
|
|
47
|
+
resize: 'onResize',
|
|
48
|
+
load: 'onLoad',
|
|
49
|
+
render: 'onRender',
|
|
50
|
+
idle: 'onIdle',
|
|
51
|
+
remove: 'onRemove',
|
|
52
|
+
data: 'onData',
|
|
53
|
+
styledata: 'onStyleData',
|
|
54
|
+
sourcedata: 'onSourceData',
|
|
55
|
+
error: 'onError'
|
|
56
|
+
};
|
|
57
|
+
const settingNames = ['minZoom', 'maxZoom', 'minPitch', 'maxPitch', 'maxBounds', 'projection', 'renderWorldCopies'];
|
|
58
|
+
const handlerNames = ['scrollZoom', 'boxZoom', 'dragRotate', 'dragPan', 'keyboard', 'doubleClickZoom', 'touchZoomRotate', 'touchPitch'];
|
|
59
|
+
export default class Mapbox {
|
|
60
|
+
_map = null;
|
|
61
|
+
_internalUpdate = false;
|
|
62
|
+
_inRender = false;
|
|
63
|
+
_hoveredFeatures = null;
|
|
64
|
+
_deferredEvents = {
|
|
65
|
+
move: false,
|
|
66
|
+
zoom: false,
|
|
67
|
+
pitch: false,
|
|
68
|
+
rotate: false
|
|
69
|
+
};
|
|
70
|
+
static savedMaps = [];
|
|
71
|
+
constructor(MapClass, props, container) {
|
|
72
|
+
this._MapClass = MapClass;
|
|
73
|
+
this.props = props;
|
|
74
|
+
this._initialize(container);
|
|
75
|
+
}
|
|
76
|
+
get map() {
|
|
77
|
+
return this._map;
|
|
78
|
+
}
|
|
79
|
+
get transform() {
|
|
80
|
+
return this._renderTransform;
|
|
81
|
+
}
|
|
82
|
+
setProps(props) {
|
|
83
|
+
const oldProps = this.props;
|
|
84
|
+
this.props = props;
|
|
85
|
+
const settingsChanged = this._updateSettings(props, oldProps);
|
|
86
|
+
if (settingsChanged) {
|
|
87
|
+
this._createShadowTransform(this._map);
|
|
88
|
+
}
|
|
89
|
+
const sizeChanged = this._updateSize(props);
|
|
90
|
+
const viewStateChanged = this._updateViewState(props, true);
|
|
91
|
+
this._updateStyle(props, oldProps);
|
|
92
|
+
this._updateStyleComponents(props, oldProps);
|
|
93
|
+
this._updateHandlers(props, oldProps);
|
|
94
|
+
if (settingsChanged || sizeChanged || viewStateChanged && !this._map.isMoving()) {
|
|
95
|
+
this.redraw();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
static reuse(props, container) {
|
|
99
|
+
const that = Mapbox.savedMaps.pop();
|
|
100
|
+
if (!that) {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
const map = that.map;
|
|
104
|
+
const oldContainer = map.getContainer();
|
|
105
|
+
container.className = oldContainer.className;
|
|
106
|
+
while (oldContainer.childNodes.length > 0) {
|
|
107
|
+
container.appendChild(oldContainer.childNodes[0]);
|
|
108
|
+
}
|
|
109
|
+
map._container = container;
|
|
110
|
+
const resizeObserver = map._resizeObserver;
|
|
111
|
+
if (resizeObserver) {
|
|
112
|
+
resizeObserver.disconnect();
|
|
113
|
+
resizeObserver.observe(container);
|
|
114
|
+
}
|
|
115
|
+
that.setProps({
|
|
116
|
+
...props,
|
|
117
|
+
styleDiffing: false
|
|
118
|
+
});
|
|
119
|
+
map.resize();
|
|
120
|
+
const {
|
|
121
|
+
initialViewState
|
|
122
|
+
} = props;
|
|
123
|
+
if (initialViewState) {
|
|
124
|
+
if (initialViewState.bounds) {
|
|
125
|
+
map.fitBounds(initialViewState.bounds, {
|
|
126
|
+
...initialViewState.fitBoundsOptions,
|
|
127
|
+
duration: 0
|
|
128
|
+
});
|
|
129
|
+
} else {
|
|
130
|
+
that._updateViewState(initialViewState, false);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (map.isStyleLoaded()) {
|
|
134
|
+
map.fire('load');
|
|
135
|
+
} else {
|
|
136
|
+
map.once('styledata', () => map.fire('load'));
|
|
137
|
+
}
|
|
138
|
+
map._update();
|
|
139
|
+
return that;
|
|
140
|
+
}
|
|
141
|
+
_initialize(container) {
|
|
142
|
+
const {
|
|
143
|
+
props
|
|
144
|
+
} = this;
|
|
145
|
+
const {
|
|
146
|
+
mapStyle = DEFAULT_STYLE
|
|
147
|
+
} = props;
|
|
148
|
+
const mapOptions = {
|
|
149
|
+
...props,
|
|
150
|
+
...props.initialViewState,
|
|
151
|
+
accessToken: props.mapboxAccessToken || getAccessTokenFromEnv() || null,
|
|
152
|
+
container,
|
|
153
|
+
style: normalizeStyle(mapStyle)
|
|
154
|
+
};
|
|
155
|
+
const viewState = mapOptions.initialViewState || mapOptions.viewState || mapOptions;
|
|
156
|
+
Object.assign(mapOptions, {
|
|
157
|
+
center: [viewState.longitude || 0, viewState.latitude || 0],
|
|
158
|
+
zoom: viewState.zoom || 0,
|
|
159
|
+
pitch: viewState.pitch || 0,
|
|
160
|
+
bearing: viewState.bearing || 0
|
|
161
|
+
});
|
|
162
|
+
if (props.gl) {
|
|
163
|
+
const getContext = HTMLCanvasElement.prototype.getContext;
|
|
164
|
+
HTMLCanvasElement.prototype.getContext = () => {
|
|
165
|
+
HTMLCanvasElement.prototype.getContext = getContext;
|
|
166
|
+
return props.gl;
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
const map = new this._MapClass(mapOptions);
|
|
170
|
+
if (viewState.padding) {
|
|
171
|
+
map.setPadding(viewState.padding);
|
|
172
|
+
}
|
|
173
|
+
if (props.cursor) {
|
|
174
|
+
map.getCanvas().style.cursor = props.cursor;
|
|
175
|
+
}
|
|
176
|
+
this._createShadowTransform(map);
|
|
177
|
+
const renderMap = map._render;
|
|
178
|
+
map._render = arg => {
|
|
179
|
+
this._inRender = true;
|
|
180
|
+
renderMap.call(map, arg);
|
|
181
|
+
this._inRender = false;
|
|
182
|
+
};
|
|
183
|
+
const runRenderTaskQueue = map._renderTaskQueue.run;
|
|
184
|
+
map._renderTaskQueue.run = arg => {
|
|
185
|
+
runRenderTaskQueue.call(map._renderTaskQueue, arg);
|
|
186
|
+
this._onBeforeRepaint();
|
|
187
|
+
};
|
|
188
|
+
map.on('render', () => this._onAfterRepaint());
|
|
189
|
+
const fireEvent = map.fire;
|
|
190
|
+
map.fire = this._fireEvent.bind(this, fireEvent);
|
|
191
|
+
map.on('resize', () => {
|
|
192
|
+
this._renderTransform.resize(map.transform.width, map.transform.height);
|
|
193
|
+
});
|
|
194
|
+
map.on('styledata', () => {
|
|
195
|
+
this._updateStyleComponents(this.props, {});
|
|
196
|
+
syncProjection(map.transform, this._renderTransform);
|
|
197
|
+
});
|
|
198
|
+
map.on('sourcedata', () => this._updateStyleComponents(this.props, {}));
|
|
199
|
+
for (const eventName in pointerEvents) {
|
|
200
|
+
map.on(eventName, this._onPointerEvent);
|
|
201
|
+
}
|
|
202
|
+
for (const eventName in cameraEvents) {
|
|
203
|
+
map.on(eventName, this._onCameraEvent);
|
|
204
|
+
}
|
|
205
|
+
for (const eventName in otherEvents) {
|
|
206
|
+
map.on(eventName, this._onEvent);
|
|
207
|
+
}
|
|
208
|
+
this._map = map;
|
|
209
|
+
}
|
|
210
|
+
recycle() {
|
|
211
|
+
const container = this.map.getContainer();
|
|
212
|
+
const children = container.querySelector('[mapboxgl-children]');
|
|
213
|
+
children === null || children === void 0 ? void 0 : children.remove();
|
|
214
|
+
Mapbox.savedMaps.push(this);
|
|
215
|
+
}
|
|
216
|
+
destroy() {
|
|
217
|
+
this._map.remove();
|
|
218
|
+
}
|
|
219
|
+
redraw() {
|
|
220
|
+
const map = this._map;
|
|
221
|
+
if (!this._inRender && map.style) {
|
|
222
|
+
if (map._frame) {
|
|
223
|
+
map._frame.cancel();
|
|
224
|
+
map._frame = null;
|
|
225
|
+
}
|
|
226
|
+
map._render();
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
_createShadowTransform(map) {
|
|
230
|
+
const renderTransform = cloneTransform(map.transform);
|
|
231
|
+
map.painter.transform = renderTransform;
|
|
232
|
+
this._renderTransform = renderTransform;
|
|
233
|
+
}
|
|
234
|
+
_updateSize(nextProps) {
|
|
235
|
+
const {
|
|
236
|
+
viewState
|
|
237
|
+
} = nextProps;
|
|
238
|
+
if (viewState) {
|
|
239
|
+
const map = this._map;
|
|
240
|
+
if (viewState.width !== map.transform.width || viewState.height !== map.transform.height) {
|
|
241
|
+
map.resize();
|
|
242
|
+
return true;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return false;
|
|
246
|
+
}
|
|
247
|
+
_updateViewState(nextProps, triggerEvents) {
|
|
248
|
+
if (this._internalUpdate) {
|
|
249
|
+
return false;
|
|
250
|
+
}
|
|
251
|
+
const map = this._map;
|
|
252
|
+
const tr = this._renderTransform;
|
|
253
|
+
const {
|
|
254
|
+
zoom,
|
|
255
|
+
pitch,
|
|
256
|
+
bearing
|
|
257
|
+
} = tr;
|
|
258
|
+
const isMoving = map.isMoving();
|
|
259
|
+
if (isMoving) {
|
|
260
|
+
tr.cameraElevationReference = 'sea';
|
|
261
|
+
}
|
|
262
|
+
const changed = applyViewStateToTransform(tr, {
|
|
263
|
+
...transformToViewState(map.transform),
|
|
264
|
+
...nextProps
|
|
265
|
+
});
|
|
266
|
+
if (isMoving) {
|
|
267
|
+
tr.cameraElevationReference = 'ground';
|
|
268
|
+
}
|
|
269
|
+
if (changed && triggerEvents) {
|
|
270
|
+
const deferredEvents = this._deferredEvents;
|
|
271
|
+
deferredEvents.move = true;
|
|
272
|
+
deferredEvents.zoom ||= zoom !== tr.zoom;
|
|
273
|
+
deferredEvents.rotate ||= bearing !== tr.bearing;
|
|
274
|
+
deferredEvents.pitch ||= pitch !== tr.pitch;
|
|
275
|
+
}
|
|
276
|
+
if (!isMoving) {
|
|
277
|
+
applyViewStateToTransform(map.transform, nextProps);
|
|
278
|
+
}
|
|
279
|
+
return changed;
|
|
280
|
+
}
|
|
281
|
+
_updateSettings(nextProps, currProps) {
|
|
282
|
+
const map = this._map;
|
|
283
|
+
let changed = false;
|
|
284
|
+
for (const propName of settingNames) {
|
|
285
|
+
if (propName in nextProps && !deepEqual(nextProps[propName], currProps[propName])) {
|
|
286
|
+
changed = true;
|
|
287
|
+
const setter = map[`set${propName[0].toUpperCase()}${propName.slice(1)}`];
|
|
288
|
+
setter === null || setter === void 0 ? void 0 : setter.call(map, nextProps[propName]);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
return changed;
|
|
292
|
+
}
|
|
293
|
+
_updateStyle(nextProps, currProps) {
|
|
294
|
+
if (nextProps.cursor !== currProps.cursor) {
|
|
295
|
+
this._map.getCanvas().style.cursor = nextProps.cursor || '';
|
|
296
|
+
}
|
|
297
|
+
if (nextProps.mapStyle !== currProps.mapStyle) {
|
|
298
|
+
const {
|
|
299
|
+
mapStyle = DEFAULT_STYLE,
|
|
300
|
+
styleDiffing = true
|
|
301
|
+
} = nextProps;
|
|
302
|
+
const options = {
|
|
303
|
+
diff: styleDiffing
|
|
304
|
+
};
|
|
305
|
+
if ('localIdeographFontFamily' in nextProps) {
|
|
306
|
+
options.localIdeographFontFamily = nextProps.localIdeographFontFamily;
|
|
307
|
+
}
|
|
308
|
+
this._map.setStyle(normalizeStyle(mapStyle), options);
|
|
309
|
+
return true;
|
|
310
|
+
}
|
|
311
|
+
return false;
|
|
312
|
+
}
|
|
313
|
+
_updateStyleComponents(nextProps, currProps) {
|
|
314
|
+
const map = this._map;
|
|
315
|
+
let changed = false;
|
|
316
|
+
if (map.isStyleLoaded()) {
|
|
317
|
+
if ('light' in nextProps && map.setLight && !deepEqual(nextProps.light, currProps.light)) {
|
|
318
|
+
changed = true;
|
|
319
|
+
map.setLight(nextProps.light);
|
|
320
|
+
}
|
|
321
|
+
if ('fog' in nextProps && map.setFog && !deepEqual(nextProps.fog, currProps.fog)) {
|
|
322
|
+
changed = true;
|
|
323
|
+
map.setFog(nextProps.fog);
|
|
324
|
+
}
|
|
325
|
+
if ('terrain' in nextProps && map.setTerrain && !deepEqual(nextProps.terrain, currProps.terrain)) {
|
|
326
|
+
if (!nextProps.terrain || map.getSource(nextProps.terrain.source)) {
|
|
327
|
+
changed = true;
|
|
328
|
+
map.setTerrain(nextProps.terrain);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
return changed;
|
|
333
|
+
}
|
|
334
|
+
_updateHandlers(nextProps, currProps) {
|
|
335
|
+
const map = this._map;
|
|
336
|
+
let changed = false;
|
|
337
|
+
for (const propName of handlerNames) {
|
|
338
|
+
const newValue = nextProps[propName] ?? true;
|
|
339
|
+
const oldValue = currProps[propName] ?? true;
|
|
340
|
+
if (!deepEqual(newValue, oldValue)) {
|
|
341
|
+
changed = true;
|
|
342
|
+
if (newValue) {
|
|
343
|
+
map[propName].enable(newValue);
|
|
344
|
+
} else {
|
|
345
|
+
map[propName].disable();
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
return changed;
|
|
350
|
+
}
|
|
351
|
+
_onEvent = e => {
|
|
352
|
+
const cb = this.props[otherEvents[e.type]];
|
|
353
|
+
if (cb) {
|
|
354
|
+
cb(e);
|
|
355
|
+
} else if (e.type === 'error') {
|
|
356
|
+
console.error(e.error);
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
_queryRenderedFeatures(point) {
|
|
360
|
+
const map = this._map;
|
|
361
|
+
const tr = map.transform;
|
|
362
|
+
const {
|
|
363
|
+
interactiveLayerIds = []
|
|
364
|
+
} = this.props;
|
|
365
|
+
try {
|
|
366
|
+
map.transform = this._renderTransform;
|
|
367
|
+
return map.queryRenderedFeatures(point, {
|
|
368
|
+
layers: interactiveLayerIds.filter(map.getLayer.bind(map))
|
|
369
|
+
});
|
|
370
|
+
} catch {
|
|
371
|
+
return [];
|
|
372
|
+
} finally {
|
|
373
|
+
map.transform = tr;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
_updateHover(e) {
|
|
377
|
+
const {
|
|
378
|
+
props
|
|
379
|
+
} = this;
|
|
380
|
+
const shouldTrackHoveredFeatures = props.interactiveLayerIds && (props.onMouseMove || props.onMouseEnter || props.onMouseLeave);
|
|
381
|
+
if (shouldTrackHoveredFeatures) {
|
|
382
|
+
var _this$_hoveredFeature;
|
|
383
|
+
const eventType = e.type;
|
|
384
|
+
const wasHovering = ((_this$_hoveredFeature = this._hoveredFeatures) === null || _this$_hoveredFeature === void 0 ? void 0 : _this$_hoveredFeature.length) > 0;
|
|
385
|
+
const features = this._queryRenderedFeatures(e.point);
|
|
386
|
+
const isHovering = features.length > 0;
|
|
387
|
+
if (!isHovering && wasHovering) {
|
|
388
|
+
e.type = 'mouseleave';
|
|
389
|
+
this._onPointerEvent(e);
|
|
390
|
+
}
|
|
391
|
+
this._hoveredFeatures = features;
|
|
392
|
+
if (isHovering && !wasHovering) {
|
|
393
|
+
e.type = 'mouseenter';
|
|
394
|
+
this._onPointerEvent(e);
|
|
395
|
+
}
|
|
396
|
+
e.type = eventType;
|
|
397
|
+
} else {
|
|
398
|
+
this._hoveredFeatures = null;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
_onPointerEvent = e => {
|
|
402
|
+
if (e.type === 'mousemove' || e.type === 'mouseout') {
|
|
403
|
+
this._updateHover(e);
|
|
404
|
+
}
|
|
405
|
+
const cb = this.props[pointerEvents[e.type]];
|
|
406
|
+
if (cb) {
|
|
407
|
+
if (this.props.interactiveLayerIds && e.type !== 'mouseover' && e.type !== 'mouseout') {
|
|
408
|
+
e.features = this._hoveredFeatures || this._queryRenderedFeatures(e.point);
|
|
409
|
+
}
|
|
410
|
+
cb(e);
|
|
411
|
+
delete e.features;
|
|
412
|
+
}
|
|
413
|
+
};
|
|
414
|
+
_onCameraEvent = e => {
|
|
415
|
+
if (!this._internalUpdate) {
|
|
416
|
+
const cb = this.props[cameraEvents[e.type]];
|
|
417
|
+
if (cb) {
|
|
418
|
+
cb(e);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
if (e.type in this._deferredEvents) {
|
|
422
|
+
this._deferredEvents[e.type] = false;
|
|
423
|
+
}
|
|
424
|
+
};
|
|
425
|
+
_fireEvent(baseFire, event, properties) {
|
|
426
|
+
const map = this._map;
|
|
427
|
+
const tr = map.transform;
|
|
428
|
+
const eventType = typeof event === 'string' ? event : event.type;
|
|
429
|
+
if (eventType === 'move') {
|
|
430
|
+
this._updateViewState(this.props, false);
|
|
431
|
+
}
|
|
432
|
+
if (eventType in cameraEvents) {
|
|
433
|
+
if (typeof event === 'object') {
|
|
434
|
+
event.viewState = transformToViewState(tr);
|
|
435
|
+
}
|
|
436
|
+
if (this._map.isMoving()) {
|
|
437
|
+
map.transform = this._renderTransform;
|
|
438
|
+
baseFire.call(map, event, properties);
|
|
439
|
+
map.transform = tr;
|
|
440
|
+
return map;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
baseFire.call(map, event, properties);
|
|
444
|
+
return map;
|
|
445
|
+
}
|
|
446
|
+
_onBeforeRepaint() {
|
|
447
|
+
const map = this._map;
|
|
448
|
+
this._internalUpdate = true;
|
|
449
|
+
for (const eventType in this._deferredEvents) {
|
|
450
|
+
if (this._deferredEvents[eventType]) {
|
|
451
|
+
map.fire(eventType);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
this._internalUpdate = false;
|
|
455
|
+
const tr = this._map.transform;
|
|
456
|
+
map.transform = this._renderTransform;
|
|
457
|
+
this._onAfterRepaint = () => {
|
|
458
|
+
syncProjection(this._renderTransform, tr);
|
|
459
|
+
map.transform = tr;
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
function getAccessTokenFromEnv() {
|
|
464
|
+
let accessToken = null;
|
|
465
|
+
if (typeof location !== 'undefined') {
|
|
466
|
+
const match = /access_token=([^&\/]*)/.exec(location.search);
|
|
467
|
+
accessToken = match && match[1];
|
|
468
|
+
}
|
|
469
|
+
try {
|
|
470
|
+
accessToken = accessToken || process.env.MapboxAccessToken;
|
|
471
|
+
} catch {}
|
|
472
|
+
try {
|
|
473
|
+
accessToken = accessToken || process.env.REACT_APP_MAPBOX_ACCESS_TOKEN;
|
|
474
|
+
} catch {}
|
|
475
|
+
return accessToken;
|
|
476
|
+
}
|
|
477
|
+
//# sourceMappingURL=mapbox.js.map
|