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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform.js","names":["deepEqual","
|
|
1
|
+
{"version":3,"file":"transform.js","names":["deepEqual","transformToViewState","tr","longitude","center","lng","latitude","lat","zoom","pitch","bearing","padding","applyViewStateToTransform","props","v","viewState","changes","LngLat","constructor"],"sources":["../../src/utils/transform.ts"],"sourcesContent":["import type { MaplibreProps } from \"../maplibre/maplibre\";\nimport type { ViewState } from \"../types/common\";\nimport type { TransformLike } from \"../types/internal\";\nimport { deepEqual } from \"./deep-equal\";\n\n/**\n * Capture a transform's current state\n * @param transform\n * @returns descriptor of the view state\n */\nexport function transformToViewState(tr: TransformLike): ViewState {\n return {\n longitude: tr.center.lng,\n latitude: tr.center.lat,\n zoom: tr.zoom,\n pitch: tr.pitch,\n bearing: tr.bearing,\n padding: tr.padding,\n };\n}\n\n/* eslint-disable complexity */\n/**\n * Applies requested view state to a transform\n * @returns an object containing detected changes\n */\nexport function applyViewStateToTransform(\n /** An object that describes Maplibre's camera state */\n tr: TransformLike,\n /** Props from Map component */\n props: MaplibreProps,\n): Partial<TransformLike> {\n const v: Partial<ViewState> = props.viewState || props;\n const changes: Partial<TransformLike> = {};\n\n if (\n \"longitude\" in v &&\n \"latitude\" in v &&\n (v.longitude !== tr.center.lng || v.latitude !== tr.center.lat)\n ) {\n const LngLat = tr.center.constructor;\n // @ts-expect-error we should not import LngLat class from maplibre-gl because we don't know the source of mapLib\n changes.center = new LngLat(v.longitude, v.latitude);\n }\n if (\"zoom\" in v && v.zoom !== tr.zoom) {\n changes.zoom = v.zoom;\n }\n if (\"bearing\" in v && v.bearing !== tr.bearing) {\n changes.bearing = v.bearing;\n }\n if (\"pitch\" in v && v.pitch !== tr.pitch) {\n changes.pitch = v.pitch;\n }\n if (v.padding && tr.padding && !deepEqual(v.padding, tr.padding)) {\n changes.padding = v.padding;\n }\n return changes;\n}\n"],"mappings":"SAGSA,SAAS;AAOlB,OAAO,SAASC,oBAAoBA,CAACC,EAAiB,EAAa;EACjE,OAAO;IACLC,SAAS,EAAED,EAAE,CAACE,MAAM,CAACC,GAAG;IACxBC,QAAQ,EAAEJ,EAAE,CAACE,MAAM,CAACG,GAAG;IACvBC,IAAI,EAAEN,EAAE,CAACM,IAAI;IACbC,KAAK,EAAEP,EAAE,CAACO,KAAK;IACfC,OAAO,EAAER,EAAE,CAACQ,OAAO;IACnBC,OAAO,EAAET,EAAE,CAACS;EACd,CAAC;AACH;AAOA,OAAO,SAASC,yBAAyBA,CAEvCV,EAAiB,EAEjBW,KAAoB,EACI;EACxB,MAAMC,CAAqB,GAAGD,KAAK,CAACE,SAAS,IAAIF,KAAK;EACtD,MAAMG,OAA+B,GAAG,CAAC,CAAC;EAE1C,IACE,WAAW,IAAIF,CAAC,IAChB,UAAU,IAAIA,CAAC,KACdA,CAAC,CAACX,SAAS,KAAKD,EAAE,CAACE,MAAM,CAACC,GAAG,IAAIS,CAAC,CAACR,QAAQ,KAAKJ,EAAE,CAACE,MAAM,CAACG,GAAG,CAAC,EAC/D;IACA,MAAMU,MAAM,GAAGf,EAAE,CAACE,MAAM,CAACc,WAAW;IAEpCF,OAAO,CAACZ,MAAM,GAAG,IAAIa,MAAM,CAACH,CAAC,CAACX,SAAS,EAAEW,CAAC,CAACR,QAAQ,CAAC;EACtD;EACA,IAAI,MAAM,IAAIQ,CAAC,IAAIA,CAAC,CAACN,IAAI,KAAKN,EAAE,CAACM,IAAI,EAAE;IACrCQ,OAAO,CAACR,IAAI,GAAGM,CAAC,CAACN,IAAI;EACvB;EACA,IAAI,SAAS,IAAIM,CAAC,IAAIA,CAAC,CAACJ,OAAO,KAAKR,EAAE,CAACQ,OAAO,EAAE;IAC9CM,OAAO,CAACN,OAAO,GAAGI,CAAC,CAACJ,OAAO;EAC7B;EACA,IAAI,OAAO,IAAII,CAAC,IAAIA,CAAC,CAACL,KAAK,KAAKP,EAAE,CAACO,KAAK,EAAE;IACxCO,OAAO,CAACP,KAAK,GAAGK,CAAC,CAACL,KAAK;EACzB;EACA,IAAIK,CAAC,CAACH,OAAO,IAAIT,EAAE,CAACS,OAAO,IAAI,CAACX,SAAS,CAACc,CAAC,CAACH,OAAO,EAAET,EAAE,CAACS,OAAO,CAAC,EAAE;IAChEK,OAAO,CAACL,OAAO,GAAGG,CAAC,CAACH,OAAO;EAC7B;EACA,OAAOK,OAAO;AAChB","ignoreList":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useEffect, useLayoutEffect } from
|
|
2
|
-
const useIsomorphicLayoutEffect = typeof document !==
|
|
1
|
+
import { useEffect, useLayoutEffect } from "react";
|
|
2
|
+
const useIsomorphicLayoutEffect = typeof document !== "undefined" ? useLayoutEffect : useEffect;
|
|
3
3
|
export default useIsomorphicLayoutEffect;
|
|
4
4
|
//# sourceMappingURL=use-isomorphic-layout-effect.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-isomorphic-layout-effect.js","names":["useEffect","useLayoutEffect","useIsomorphicLayoutEffect","document"],"sources":["../../src/utils/use-isomorphic-layout-effect.ts"],"sourcesContent":["// From https://github.com/streamich/react-use/blob/master/src/useIsomorphicLayoutEffect.ts\n// useLayoutEffect but does not trigger warning in server-side rendering\nimport {useEffect, useLayoutEffect} from
|
|
1
|
+
{"version":3,"file":"use-isomorphic-layout-effect.js","names":["useEffect","useLayoutEffect","useIsomorphicLayoutEffect","document"],"sources":["../../src/utils/use-isomorphic-layout-effect.ts"],"sourcesContent":["// From https://github.com/streamich/react-use/blob/master/src/useIsomorphicLayoutEffect.ts\n// useLayoutEffect but does not trigger warning in server-side rendering\nimport { useEffect, useLayoutEffect } from \"react\";\n\nconst useIsomorphicLayoutEffect =\n typeof document !== \"undefined\" ? useLayoutEffect : useEffect;\n\nexport default useIsomorphicLayoutEffect;\n"],"mappings":"AAEA,SAASA,SAAS,EAAEC,eAAe,QAAQ,OAAO;AAElD,MAAMC,yBAAyB,GAC7B,OAAOC,QAAQ,KAAK,WAAW,GAAGF,eAAe,GAAGD,SAAS;AAE/D,eAAeE,yBAAyB","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,51 +1,49 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-bkoi-gl",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"updatedAt": "12-05-2025 5:19:02 PM",
|
|
5
|
+
"engines": {
|
|
6
|
+
"node": ">=18.13.0"
|
|
7
|
+
},
|
|
4
8
|
"description": "React components for Barikoi GL JS",
|
|
5
9
|
"type": "module",
|
|
6
10
|
"types": "dist/index.d.ts",
|
|
7
11
|
"main": "dist/index.cjs",
|
|
8
12
|
"module": "dist/index.js",
|
|
9
|
-
"author": "barikoi",
|
|
10
|
-
"readme": "README.md",
|
|
11
|
-
"license": "MIT",
|
|
12
|
-
"homepage": "https://docs.barikoi.com/docs/maps-api",
|
|
13
13
|
"exports": {
|
|
14
14
|
".": {
|
|
15
15
|
"types": "./dist/index.d.ts",
|
|
16
16
|
"require": "./dist/index.cjs",
|
|
17
|
-
"import": "./dist/index.js"
|
|
18
|
-
|
|
19
|
-
"./bkoi-gl": {
|
|
20
|
-
"types": "./dist/exports-bkoi-gl.d.ts",
|
|
21
|
-
"require": "./dist/exports-bkoi-gl.cjs",
|
|
22
|
-
"import": "./dist/exports-bkoi-gl.js"
|
|
17
|
+
"import": "./dist/index.js",
|
|
18
|
+
"default": "./dist/index.cjs"
|
|
23
19
|
},
|
|
24
20
|
"./styles": {
|
|
21
|
+
"types": "./dist/styles/index.d.ts",
|
|
25
22
|
"import": "./dist/styles/react-bkoi-gl.css",
|
|
26
23
|
"default": "./dist/styles/react-bkoi-gl.css"
|
|
27
24
|
}
|
|
28
25
|
},
|
|
26
|
+
"author": "barikoi",
|
|
27
|
+
"readme": "README.md",
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"homepage": "https://docs.barikoi.com/docs/maps-api",
|
|
29
30
|
"files": [
|
|
30
31
|
"src",
|
|
31
32
|
"dist",
|
|
32
|
-
"bkoi-gl",
|
|
33
33
|
"README.md"
|
|
34
34
|
],
|
|
35
35
|
"scripts": {
|
|
36
|
-
"typecheck": "tsc -p tsconfig.build.json
|
|
36
|
+
"typecheck": "tsc -p tsconfig.build.json",
|
|
37
|
+
"clean": "rm -rf dist && mkdir -p dist",
|
|
37
38
|
"build": "ocular-clean && ocular-build && node scripts/modify-css.js",
|
|
38
|
-
"lint": "
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"metrics": "ocular-metrics"
|
|
39
|
+
"lint": "eslint src/ --ext .js,.jsx,.ts,.tsx",
|
|
40
|
+
"test": "npm run typecheck && jest",
|
|
41
|
+
"coverage": "jest --coverage --passWithNoTests",
|
|
42
|
+
"update-version": "node scripts/update-version.cjs"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@maplibre/maplibre-gl-style-spec": "^
|
|
46
|
-
"
|
|
47
|
-
"bkoi-gl": ">=2.0.0",
|
|
48
|
-
"mapbox-gl": "^1.13.0"
|
|
45
|
+
"@maplibre/maplibre-gl-style-spec": "^23.2.1",
|
|
46
|
+
"maplibre-gl": "^5.4.0"
|
|
49
47
|
},
|
|
50
48
|
"peerDependencies": {
|
|
51
49
|
"react": ">=16.3.0",
|
|
@@ -54,13 +52,24 @@
|
|
|
54
52
|
"devDependencies": {
|
|
55
53
|
"@commitlint/cli": "^19.4.1",
|
|
56
54
|
"@commitlint/config-conventional": "^19.4.1",
|
|
57
|
-
"@
|
|
55
|
+
"@testing-library/jest-dom": "^6.4.2",
|
|
56
|
+
"@testing-library/react": "^14.2.1",
|
|
57
|
+
"@testing-library/react-hooks": "8.0.1",
|
|
58
|
+
"@types/jest": "^29.5.12",
|
|
59
|
+
"@types/node": "^22.0.0",
|
|
58
60
|
"@types/react": "^16.0.0",
|
|
59
|
-
"
|
|
61
|
+
"babel-jest": "^29.7.0",
|
|
62
|
+
"identity-obj-proxy": "^3.0.0",
|
|
63
|
+
"jest": "^29.7.0",
|
|
64
|
+
"jest-environment-jsdom": "^29.7.0",
|
|
60
65
|
"ocular-dev-tools": "2.0.0-alpha.15",
|
|
66
|
+
"puppeteer": "^22.4.0",
|
|
61
67
|
"react": "^18.0.0",
|
|
62
68
|
"react-dom": "^18.0.0",
|
|
63
|
-
"
|
|
69
|
+
"react-test-renderer": "^18.0.0",
|
|
70
|
+
"tape-promise": "^4.0.0",
|
|
71
|
+
"ts-jest": "^29.1.2",
|
|
72
|
+
"typescript": "^5.0.0"
|
|
64
73
|
},
|
|
65
74
|
"keywords": [
|
|
66
75
|
"barikoi",
|
|
@@ -72,5 +81,12 @@
|
|
|
72
81
|
"repository": {
|
|
73
82
|
"type": "git",
|
|
74
83
|
"url": "https://github.com/barikoi/react-bkoi-gl.git"
|
|
84
|
+
},
|
|
85
|
+
"overrides": {
|
|
86
|
+
"@testing-library/react-hooks": {
|
|
87
|
+
"react": "$react",
|
|
88
|
+
"react-dom": "$react-dom",
|
|
89
|
+
"react-test-renderer": "$react-test-renderer"
|
|
90
|
+
}
|
|
75
91
|
}
|
|
76
|
-
}
|
|
92
|
+
}
|
|
@@ -1,32 +1,56 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
import
|
|
1
|
+
/* eslint-disable max-statements */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-unnecessary-type-assertion */
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { useEffect, memo } from "react";
|
|
5
|
+
import { applyReactStyle } from "../utils/apply-react-style";
|
|
6
|
+
import { useControl } from "./use-control";
|
|
5
7
|
|
|
6
|
-
import type {ControlPosition,
|
|
8
|
+
import type { ControlPosition, AttributionControlOptions } from "../types/lib";
|
|
7
9
|
|
|
8
|
-
export type AttributionControlProps
|
|
10
|
+
export type AttributionControlProps = AttributionControlOptions & {
|
|
9
11
|
/** Placement of the control relative to the map. */
|
|
10
12
|
position?: ControlPosition;
|
|
11
13
|
/** CSS style override, applied to the control's container */
|
|
12
14
|
style?: React.CSSProperties;
|
|
13
15
|
};
|
|
14
16
|
|
|
15
|
-
function
|
|
16
|
-
|
|
17
|
-
)
|
|
18
|
-
|
|
19
|
-
({mapLib}) => new mapLib.AttributionControl(props) as ControlT,
|
|
20
|
-
{
|
|
21
|
-
position: props.position
|
|
22
|
-
}
|
|
17
|
+
function _AttributionControl(props: AttributionControlProps) {
|
|
18
|
+
const ctrl = useControl(
|
|
19
|
+
({ mapLib }) => new mapLib.AttributionControl(props),
|
|
20
|
+
{ position: props.position },
|
|
23
21
|
);
|
|
24
22
|
|
|
25
23
|
useEffect(() => {
|
|
26
24
|
applyReactStyle(ctrl._container, props.style);
|
|
27
|
-
|
|
25
|
+
|
|
26
|
+
// Ensure the container is available
|
|
27
|
+
if (!ctrl._container) return;
|
|
28
|
+
|
|
29
|
+
// Create and append the custom attribution control
|
|
30
|
+
// const customAttribution = document.createElement('details');
|
|
31
|
+
// customAttribution.className = 'maplibregl-ctrl maplibregl-ctrl-attrib maplibregl-compact maplibregl-compact-show';
|
|
32
|
+
// customAttribution.setAttribute('open', '');
|
|
33
|
+
|
|
34
|
+
// const summary = document.createElement('summary');
|
|
35
|
+
// summary.className = 'maplibregl-ctrl-attrib-button';
|
|
36
|
+
// summary.setAttribute('title', 'Toggle attribution');
|
|
37
|
+
// summary.setAttribute('aria-label', 'Toggle attribution');
|
|
38
|
+
// customAttribution.appendChild(summary);
|
|
39
|
+
|
|
40
|
+
// const innerDiv = document.createElement('div');
|
|
41
|
+
// innerDiv.className = 'maplibregl-ctrl-attrib-inner';
|
|
42
|
+
// innerDiv.innerHTML = `
|
|
43
|
+
// <a href="https://barikoi.com/" target="_blank">© Barikoi</a> |
|
|
44
|
+
// <a href="https://www.openmaptiles.org/" target="_blank">© OpenMapTiles</a> |
|
|
45
|
+
// <a href="https://www.openstreetmap.org/copyright" target="_blank">© OpenStreetMap contributors</a>
|
|
46
|
+
// `;
|
|
47
|
+
// customAttribution.appendChild(innerDiv);
|
|
48
|
+
|
|
49
|
+
// ctrl._container.appendChild(customAttribution);
|
|
50
|
+
}, [props.style, ctrl._container]);
|
|
28
51
|
|
|
29
52
|
return null;
|
|
30
53
|
}
|
|
31
54
|
|
|
32
|
-
export
|
|
55
|
+
export const AttributionControl: React.FC<AttributionControlProps> =
|
|
56
|
+
memo(_AttributionControl);
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/* global document */
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { useEffect, memo } from "react";
|
|
4
|
+
import { applyReactStyle } from "../utils/apply-react-style";
|
|
5
|
+
import { useControl } from "./use-control";
|
|
6
|
+
|
|
7
|
+
import type { ControlPosition, FullscreenControlOptions } from "../types/lib";
|
|
8
|
+
|
|
9
|
+
export type FullscreenControlProps = Omit<
|
|
10
|
+
FullscreenControlOptions,
|
|
11
|
+
"container"
|
|
12
|
+
> & {
|
|
13
|
+
/** Id of the DOM element which should be made full screen. By default, the map container
|
|
14
|
+
* element will be made full screen. */
|
|
15
|
+
containerId?: string;
|
|
16
|
+
/** Placement of the control relative to the map. */
|
|
17
|
+
position?: ControlPosition;
|
|
18
|
+
/** CSS style override, applied to the control's container */
|
|
19
|
+
style?: React.CSSProperties;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
function _FullscreenControl(props: FullscreenControlProps) {
|
|
23
|
+
const ctrl = useControl(
|
|
24
|
+
({ mapLib }) =>
|
|
25
|
+
new mapLib.FullscreenControl({
|
|
26
|
+
container:
|
|
27
|
+
props.containerId && document.getElementById(props.containerId),
|
|
28
|
+
}),
|
|
29
|
+
{ position: props.position },
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
applyReactStyle(ctrl._controlContainer, props.style);
|
|
34
|
+
}, [props.style]);
|
|
35
|
+
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export const FullscreenControl: React.FC<FullscreenControlProps> =
|
|
40
|
+
memo(_FullscreenControl);
|
|
@@ -1,79 +1,83 @@
|
|
|
1
|
-
import * as React from
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import {
|
|
3
|
+
useImperativeHandle,
|
|
4
|
+
useRef,
|
|
5
|
+
useEffect,
|
|
6
|
+
forwardRef,
|
|
7
|
+
memo,
|
|
8
|
+
} from "react";
|
|
9
|
+
import { applyReactStyle } from "../utils/apply-react-style";
|
|
10
|
+
import { useControl } from "./use-control";
|
|
5
11
|
|
|
6
12
|
import type {
|
|
7
13
|
ControlPosition,
|
|
8
|
-
GeolocateControlInstance,
|
|
14
|
+
GeolocateControl as GeolocateControlInstance,
|
|
15
|
+
GeolocateControlOptions,
|
|
16
|
+
} from "../types/lib";
|
|
17
|
+
import type {
|
|
9
18
|
GeolocateEvent,
|
|
10
19
|
GeolocateResultEvent,
|
|
11
|
-
GeolocateErrorEvent
|
|
12
|
-
} from
|
|
20
|
+
GeolocateErrorEvent,
|
|
21
|
+
} from "../types/events";
|
|
13
22
|
|
|
14
|
-
export type GeolocateControlProps
|
|
15
|
-
OptionsT,
|
|
16
|
-
ControlT extends GeolocateControlInstance
|
|
17
|
-
> = OptionsT & {
|
|
23
|
+
export type GeolocateControlProps = GeolocateControlOptions & {
|
|
18
24
|
/** Placement of the control relative to the map. */
|
|
19
25
|
position?: ControlPosition;
|
|
20
26
|
/** CSS style override, applied to the control's container */
|
|
21
27
|
style?: React.CSSProperties;
|
|
22
28
|
|
|
23
29
|
/** Called on each Geolocation API position update that returned as success. */
|
|
24
|
-
onGeolocate?: (e: GeolocateResultEvent
|
|
30
|
+
onGeolocate?: (e: GeolocateResultEvent) => void;
|
|
25
31
|
/** Called on each Geolocation API position update that returned as an error. */
|
|
26
|
-
onError?: (e: GeolocateErrorEvent
|
|
32
|
+
onError?: (e: GeolocateErrorEvent) => void;
|
|
27
33
|
/** Called on each Geolocation API position update that returned as success but user position
|
|
28
34
|
* is out of map `maxBounds`. */
|
|
29
|
-
onOutOfMaxBounds?: (e: GeolocateResultEvent
|
|
35
|
+
onOutOfMaxBounds?: (e: GeolocateResultEvent) => void;
|
|
30
36
|
/** Called when the GeolocateControl changes to the active lock state. */
|
|
31
|
-
onTrackUserLocationStart?: (e: GeolocateEvent
|
|
37
|
+
onTrackUserLocationStart?: (e: GeolocateEvent) => void;
|
|
32
38
|
/** Called when the GeolocateControl changes to the background state. */
|
|
33
|
-
onTrackUserLocationEnd?: (e: GeolocateEvent
|
|
39
|
+
onTrackUserLocationEnd?: (e: GeolocateEvent) => void;
|
|
34
40
|
};
|
|
35
41
|
|
|
36
|
-
function
|
|
37
|
-
props: GeolocateControlProps
|
|
38
|
-
ref: React.Ref<
|
|
42
|
+
function _GeolocateControl(
|
|
43
|
+
props: GeolocateControlProps,
|
|
44
|
+
ref: React.Ref<GeolocateControlInstance>,
|
|
39
45
|
) {
|
|
40
|
-
const thisRef = useRef({props});
|
|
46
|
+
const thisRef = useRef({ props });
|
|
41
47
|
|
|
42
|
-
const ctrl = useControl
|
|
43
|
-
({mapLib}) => {
|
|
44
|
-
const gc = new mapLib.GeolocateControl(props)
|
|
48
|
+
const ctrl = useControl(
|
|
49
|
+
({ mapLib }) => {
|
|
50
|
+
const gc = new mapLib.GeolocateControl(props);
|
|
45
51
|
|
|
46
52
|
// Hack: fix GeolocateControl reuse
|
|
47
53
|
// When using React strict mode, the component is mounted twice.
|
|
48
54
|
// GeolocateControl's UI creation is asynchronous. Removing and adding it back causes the UI to be initialized twice.
|
|
49
|
-
// @ts-expect-error private method
|
|
50
55
|
const setupUI = gc._setupUI;
|
|
51
|
-
|
|
52
|
-
gc._setupUI = args => {
|
|
56
|
+
gc._setupUI = () => {
|
|
53
57
|
if (!gc._container.hasChildNodes()) {
|
|
54
|
-
setupUI(
|
|
58
|
+
setupUI();
|
|
55
59
|
}
|
|
56
60
|
};
|
|
57
61
|
|
|
58
|
-
gc.on(
|
|
59
|
-
thisRef.current.props.onGeolocate?.(e as GeolocateResultEvent
|
|
62
|
+
gc.on("geolocate", (e) => {
|
|
63
|
+
thisRef.current.props.onGeolocate?.(e as GeolocateResultEvent);
|
|
60
64
|
});
|
|
61
|
-
gc.on(
|
|
62
|
-
thisRef.current.props.onError?.(e as GeolocateErrorEvent
|
|
65
|
+
gc.on("error", (e) => {
|
|
66
|
+
thisRef.current.props.onError?.(e as GeolocateErrorEvent);
|
|
63
67
|
});
|
|
64
|
-
gc.on(
|
|
65
|
-
thisRef.current.props.onOutOfMaxBounds?.(e as GeolocateResultEvent
|
|
68
|
+
gc.on("outofmaxbounds", (e) => {
|
|
69
|
+
thisRef.current.props.onOutOfMaxBounds?.(e as GeolocateResultEvent);
|
|
66
70
|
});
|
|
67
|
-
gc.on(
|
|
68
|
-
thisRef.current.props.onTrackUserLocationStart?.(e as GeolocateEvent
|
|
71
|
+
gc.on("trackuserlocationstart", (e) => {
|
|
72
|
+
thisRef.current.props.onTrackUserLocationStart?.(e as GeolocateEvent);
|
|
69
73
|
});
|
|
70
|
-
gc.on(
|
|
71
|
-
thisRef.current.props.onTrackUserLocationEnd?.(e as GeolocateEvent
|
|
74
|
+
gc.on("trackuserlocationend", (e) => {
|
|
75
|
+
thisRef.current.props.onTrackUserLocationEnd?.(e as GeolocateEvent);
|
|
72
76
|
});
|
|
73
77
|
|
|
74
78
|
return gc;
|
|
75
79
|
},
|
|
76
|
-
{position: props.position}
|
|
80
|
+
{ position: props.position },
|
|
77
81
|
);
|
|
78
82
|
|
|
79
83
|
thisRef.current.props = props;
|
|
@@ -87,4 +91,6 @@ function GeolocateControl<GeolocateControlOptions, ControlT extends GeolocateCon
|
|
|
87
91
|
return null;
|
|
88
92
|
}
|
|
89
93
|
|
|
90
|
-
export
|
|
94
|
+
export const GeolocateControl: React.FC<GeolocateControlProps> = memo(
|
|
95
|
+
forwardRef(_GeolocateControl),
|
|
96
|
+
);
|
package/src/components/layer.ts
CHANGED
|
@@ -1,35 +1,44 @@
|
|
|
1
|
-
import {useContext, useEffect, useMemo, useState, useRef} from
|
|
2
|
-
import {MapContext} from
|
|
3
|
-
import assert from
|
|
4
|
-
import {deepEqual} from
|
|
1
|
+
import { useContext, useEffect, useMemo, useState, useRef } from "react";
|
|
2
|
+
import { MapContext } from "./map";
|
|
3
|
+
import assert from "../utils/assert";
|
|
4
|
+
import { deepEqual } from "../utils/deep-equal";
|
|
5
5
|
|
|
6
|
-
import type {MapInstance, CustomLayerInterface
|
|
6
|
+
import type { Map as MapInstance, CustomLayerInterface } from "../types/lib";
|
|
7
|
+
import type { LayerSpecification } from "../types/style-spec";
|
|
7
8
|
|
|
8
9
|
// Omiting property from a union type, see
|
|
9
10
|
// https://github.com/microsoft/TypeScript/issues/39556#issuecomment-656925230
|
|
10
|
-
type OptionalId<T> = T extends {id: string
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
type OptionalId<T> = T extends { id: string }
|
|
12
|
+
? Omit<T, "id"> & { id?: string }
|
|
13
|
+
: T;
|
|
14
|
+
type OptionalSource<T> = T extends { source: string }
|
|
15
|
+
? Omit<T, "source"> & { source?: string }
|
|
16
|
+
: T;
|
|
17
|
+
|
|
18
|
+
export type LayerProps = (
|
|
19
|
+
| OptionalSource<OptionalId<LayerSpecification>>
|
|
20
|
+
| CustomLayerInterface
|
|
21
|
+
) & {
|
|
14
22
|
/** If set, the layer will be inserted before the specified layer */
|
|
15
23
|
beforeId?: string;
|
|
16
24
|
};
|
|
17
25
|
|
|
18
26
|
/* eslint-disable complexity, max-statements */
|
|
19
|
-
function updateLayer
|
|
27
|
+
function updateLayer(
|
|
20
28
|
map: MapInstance,
|
|
21
29
|
id: string,
|
|
22
|
-
props: LayerProps
|
|
23
|
-
prevProps: LayerProps
|
|
30
|
+
props: LayerProps,
|
|
31
|
+
prevProps: LayerProps,
|
|
24
32
|
) {
|
|
25
|
-
assert(props.id === prevProps.id,
|
|
26
|
-
assert(props.type === prevProps.type,
|
|
33
|
+
assert(props.id === prevProps.id, "layer id changed");
|
|
34
|
+
assert(props.type === prevProps.type, "layer type changed");
|
|
27
35
|
|
|
28
|
-
if (props.type ===
|
|
36
|
+
if (props.type === "custom" || prevProps.type === "custom") {
|
|
29
37
|
return;
|
|
30
38
|
}
|
|
31
39
|
|
|
32
|
-
|
|
40
|
+
// @ts-ignore filter does not exist in some Layer types
|
|
41
|
+
const { layout = {}, paint = {}, filter, minzoom, maxzoom, beforeId } = props;
|
|
33
42
|
|
|
34
43
|
if (beforeId !== prevProps.beforeId) {
|
|
35
44
|
map.moveLayer(id, beforeId);
|
|
@@ -61,6 +70,7 @@ function updateLayer<LayerT extends ILayer>(
|
|
|
61
70
|
}
|
|
62
71
|
}
|
|
63
72
|
|
|
73
|
+
// @ts-ignore filter does not exist in some Layer types
|
|
64
74
|
if (!deepEqual(filter, prevProps.filter)) {
|
|
65
75
|
map.setFilter(id, filter);
|
|
66
76
|
}
|
|
@@ -69,14 +79,14 @@ function updateLayer<LayerT extends ILayer>(
|
|
|
69
79
|
}
|
|
70
80
|
}
|
|
71
81
|
|
|
72
|
-
function createLayer
|
|
73
|
-
map: MapInstance,
|
|
74
|
-
id: string,
|
|
75
|
-
props: LayerProps<LayerT>
|
|
76
|
-
) {
|
|
82
|
+
function createLayer(map: MapInstance, id: string, props: LayerProps) {
|
|
77
83
|
// @ts-ignore
|
|
78
|
-
if (
|
|
79
|
-
|
|
84
|
+
if (
|
|
85
|
+
map.style &&
|
|
86
|
+
map.style._loaded &&
|
|
87
|
+
(!("source" in props) || map.getSource(props.source))
|
|
88
|
+
) {
|
|
89
|
+
const options: LayerProps = { ...props, id };
|
|
80
90
|
delete options.beforeId;
|
|
81
91
|
|
|
82
92
|
// @ts-ignore
|
|
@@ -88,7 +98,7 @@ function createLayer<LayerT extends ILayer>(
|
|
|
88
98
|
|
|
89
99
|
let layerCounter = 0;
|
|
90
100
|
|
|
91
|
-
function Layer
|
|
101
|
+
export function Layer(props: LayerProps) {
|
|
92
102
|
const map = useContext(MapContext).map.getMap();
|
|
93
103
|
const propsRef = useRef(props);
|
|
94
104
|
const [, setStyleLoaded] = useState(0);
|
|
@@ -97,12 +107,12 @@ function Layer<LayerT extends ILayer>(props: LayerProps<LayerT | CustomLayerInte
|
|
|
97
107
|
|
|
98
108
|
useEffect(() => {
|
|
99
109
|
if (map) {
|
|
100
|
-
const forceUpdate = () => setStyleLoaded(version => version + 1);
|
|
101
|
-
map.on(
|
|
110
|
+
const forceUpdate = () => setStyleLoaded((version) => version + 1);
|
|
111
|
+
map.on("styledata", forceUpdate);
|
|
102
112
|
forceUpdate();
|
|
103
113
|
|
|
104
114
|
return () => {
|
|
105
|
-
map.off(
|
|
115
|
+
map.off("styledata", forceUpdate);
|
|
106
116
|
// @ts-ignore
|
|
107
117
|
if (map.style && map.style._loaded && map.getLayer(id)) {
|
|
108
118
|
map.removeLayer(id);
|
|
@@ -129,5 +139,3 @@ function Layer<LayerT extends ILayer>(props: LayerProps<LayerT | CustomLayerInte
|
|
|
129
139
|
|
|
130
140
|
return null;
|
|
131
141
|
}
|
|
132
|
-
|
|
133
|
-
export default Layer;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unnecessary-type-assertion */
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { useEffect, memo } from "react";
|
|
4
|
+
import { applyReactStyle } from "../utils/apply-react-style";
|
|
5
|
+
import { useControl } from "./use-control";
|
|
6
|
+
|
|
7
|
+
import type { ControlPosition, LogoControlOptions } from "../types/lib";
|
|
8
|
+
|
|
9
|
+
export type LogoControlProps = LogoControlOptions & {
|
|
10
|
+
/** Placement of the control relative to the map. */
|
|
11
|
+
position?: ControlPosition;
|
|
12
|
+
/** CSS style override, applied to the control's container */
|
|
13
|
+
style?: React.CSSProperties;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
function _LogoControl(props: LogoControlProps) {
|
|
17
|
+
const ctrl = useControl(({ mapLib }) => new mapLib.LogoControl(props), {
|
|
18
|
+
position: props.position,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
applyReactStyle(ctrl._container, props.style);
|
|
23
|
+
|
|
24
|
+
// Update the DOM structure and attributes directly
|
|
25
|
+
const logoElement = ctrl._container?.querySelector(
|
|
26
|
+
".maplibregl-ctrl-logo",
|
|
27
|
+
) as HTMLAnchorElement | null;
|
|
28
|
+
if (logoElement) {
|
|
29
|
+
// Update the link attributes
|
|
30
|
+
logoElement.href = "https://barikoi.com/";
|
|
31
|
+
logoElement.setAttribute("aria-label", "Barikoi logo");
|
|
32
|
+
logoElement.target = "_blank";
|
|
33
|
+
logoElement.rel = "noopener nofollow";
|
|
34
|
+
logoElement.style.cursor = "pointer";
|
|
35
|
+
|
|
36
|
+
// Remove any existing click handlers
|
|
37
|
+
logoElement.replaceWith(logoElement.cloneNode(true));
|
|
38
|
+
}
|
|
39
|
+
}, [props.style, ctrl._container]);
|
|
40
|
+
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export const LogoControl: React.FC<LogoControlProps> = memo(_LogoControl);
|