@maptiler/sdk 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +1 -0
- package/.eslintrc.cjs +10 -0
- package/.github/workflows/npm-publish.yml +23 -0
- package/LICENSE +29 -0
- package/demos/maptiler-sdk.css +147 -0
- package/demos/maptiler-sdk.umd.js +3287 -0
- package/demos/simple.html +63 -0
- package/dist/maptiler-sdk.css +147 -0
- package/dist/maptiler-sdk.d.ts +531 -0
- package/dist/maptiler-sdk.min.mjs +1 -0
- package/dist/maptiler-sdk.mjs +1128 -0
- package/dist/maptiler-sdk.mjs.map +1 -0
- package/dist/maptiler-sdk.umd.js +3287 -0
- package/dist/maptiler-sdk.umd.js.map +1 -0
- package/dist/maptiler-sdk.umd.min.js +579 -0
- package/docs/.nojekyll +1 -0
- package/docs/assets/custom.css +118 -0
- package/docs/assets/highlight.css +134 -0
- package/docs/assets/main.js +54 -0
- package/docs/assets/search.js +1 -0
- package/docs/assets/style.css +1257 -0
- package/docs/classes/Map.html +273 -0
- package/docs/classes/Point.html +549 -0
- package/docs/classes/SdkConfig.html +188 -0
- package/docs/demos/maptiler-sdk.css +147 -0
- package/docs/demos/maptiler-sdk.umd.js +3287 -0
- package/docs/demos/simple.html +63 -0
- package/docs/functions/addProtocol.html +146 -0
- package/docs/functions/clearPrewarmedResources.html +92 -0
- package/docs/functions/clearStorage.html +124 -0
- package/docs/functions/getRTLTextPluginStatus.html +92 -0
- package/docs/functions/prewarm.html +92 -0
- package/docs/functions/removeProtocol.html +106 -0
- package/docs/functions/setRTLTextPlugin.html +112 -0
- package/docs/functions/supported.html +97 -0
- package/docs/images/JS-logo.svg +4 -0
- package/docs/images/TS-logo.svg +6 -0
- package/docs/images/maptiler-logo.svg +19 -0
- package/docs/images/maptiler-sdk-logo.afdesign +0 -0
- package/docs/images/maptiler-sdk-logo.svg +66 -0
- package/docs/images/screenshots/alps.gif +0 -0
- package/docs/images/screenshots/grandcanyon.gif +0 -0
- package/docs/images/screenshots/lang-arabic.png +0 -0
- package/docs/images/screenshots/lang-hebrew.png +0 -0
- package/docs/images/screenshots/multilang.gif +0 -0
- package/docs/images/screenshots/static-bounded-europe-1024.png +0 -0
- package/docs/images/screenshots/static-bounded-europe-2048.png +0 -0
- package/docs/images/screenshots/static-bounded-portugal-1024x2048.png +0 -0
- package/docs/images/screenshots/static-bounded-portugal-2048x2048.png +0 -0
- package/docs/images/screenshots/static-with-path.png +0 -0
- package/docs/images/screenshots/style-basic-v2.png +0 -0
- package/docs/images/screenshots/style-bright.png +0 -0
- package/docs/images/screenshots/style-dataviz-dark.png +0 -0
- package/docs/images/screenshots/style-hybrid.png +0 -0
- package/docs/images/screenshots/style-osm.png +0 -0
- package/docs/images/screenshots/style-outdoor.png +0 -0
- package/docs/images/screenshots/style-pastel.png +0 -0
- package/docs/images/screenshots/style-satellite.png +0 -0
- package/docs/images/screenshots/style-streets-v2-dark.png +0 -0
- package/docs/images/screenshots/style-streets-v2-light.png +0 -0
- package/docs/images/screenshots/style-streets-v2.png +0 -0
- package/docs/images/screenshots/style-toner.png +0 -0
- package/docs/images/screenshots/style-topo.png +0 -0
- package/docs/images/screenshots/style-topographique.png +0 -0
- package/docs/images/screenshots/style-voyager.png +0 -0
- package/docs/images/screenshots/style-winter.png +0 -0
- package/docs/index.html +601 -0
- package/docs/modules.html +142 -0
- package/docs/types/LanguageKey.html +90 -0
- package/docs/types/LanguageString.html +90 -0
- package/docs/types/MapOptions.html +90 -0
- package/docs/types/Matrix2.html +90 -0
- package/docs/types/Unit.html +88 -0
- package/docs/variables/AJAXError.html +88 -0
- package/docs/variables/AttributionControl.html +88 -0
- package/docs/variables/CanvasSource.html +88 -0
- package/docs/variables/Evented.html +88 -0
- package/docs/variables/FullscreenControl.html +88 -0
- package/docs/variables/GeoJSONSource.html +88 -0
- package/docs/variables/GeolocateControl.html +88 -0
- package/docs/variables/GeolocationType.html +95 -0
- package/docs/variables/ImageSource.html +88 -0
- package/docs/variables/Language.html +249 -0
- package/docs/variables/LngLat.html +88 -0
- package/docs/variables/LngLatBounds.html +88 -0
- package/docs/variables/LogoControl.html +88 -0
- package/docs/variables/Marker.html +88 -0
- package/docs/variables/MercatorCoordinate.html +88 -0
- package/docs/variables/NavigationControl.html +88 -0
- package/docs/variables/Popup.html +88 -0
- package/docs/variables/RasterDEMTileSource.html +88 -0
- package/docs/variables/RasterTileSource.html +88 -0
- package/docs/variables/ScaleControl.html +88 -0
- package/docs/variables/Style.html +88 -0
- package/docs/variables/TerrainControl.html +88 -0
- package/docs/variables/VectorTileSource.html +88 -0
- package/docs/variables/VideoSource.html +88 -0
- package/docs/variables/config.html +88 -0
- package/docs/variables/maxParallelImageRequests.html +88 -0
- package/docs/variables/version.html +88 -0
- package/docs/variables/workerCount.html +88 -0
- package/docs/variables/workerUrl.html +88 -0
- package/docsmd/.nojekyll +1 -0
- package/docsmd/README.md +710 -0
- package/docsmd/assets/custom.css +118 -0
- package/docsmd/classes/Map.md +292 -0
- package/docsmd/classes/Point.md +603 -0
- package/docsmd/classes/SdkConfig.md +186 -0
- package/docsmd/images/JS-logo.svg +4 -0
- package/docsmd/images/TS-logo.svg +6 -0
- package/docsmd/images/maptiler-logo.svg +19 -0
- package/docsmd/images/maptiler-sdk-logo.afdesign +0 -0
- package/docsmd/images/maptiler-sdk-logo.svg +66 -0
- package/docsmd/images/screenshots/alps.gif +0 -0
- package/docsmd/images/screenshots/grandcanyon.gif +0 -0
- package/docsmd/images/screenshots/lang-arabic.png +0 -0
- package/docsmd/images/screenshots/lang-hebrew.png +0 -0
- package/docsmd/images/screenshots/multilang.gif +0 -0
- package/docsmd/images/screenshots/static-bounded-europe-1024.png +0 -0
- package/docsmd/images/screenshots/static-bounded-europe-2048.png +0 -0
- package/docsmd/images/screenshots/static-bounded-portugal-1024x2048.png +0 -0
- package/docsmd/images/screenshots/static-bounded-portugal-2048x2048.png +0 -0
- package/docsmd/images/screenshots/static-with-path.png +0 -0
- package/docsmd/images/screenshots/style-basic-v2.png +0 -0
- package/docsmd/images/screenshots/style-bright.png +0 -0
- package/docsmd/images/screenshots/style-dataviz-dark.png +0 -0
- package/docsmd/images/screenshots/style-hybrid.png +0 -0
- package/docsmd/images/screenshots/style-osm.png +0 -0
- package/docsmd/images/screenshots/style-outdoor.png +0 -0
- package/docsmd/images/screenshots/style-pastel.png +0 -0
- package/docsmd/images/screenshots/style-satellite.png +0 -0
- package/docsmd/images/screenshots/style-streets-v2-dark.png +0 -0
- package/docsmd/images/screenshots/style-streets-v2-light.png +0 -0
- package/docsmd/images/screenshots/style-streets-v2.png +0 -0
- package/docsmd/images/screenshots/style-toner.png +0 -0
- package/docsmd/images/screenshots/style-topo.png +0 -0
- package/docsmd/images/screenshots/style-topographique.png +0 -0
- package/docsmd/images/screenshots/style-voyager.png +0 -0
- package/docsmd/images/screenshots/style-winter.png +0 -0
- package/images/JS-logo.svg +4 -0
- package/images/TS-logo.svg +6 -0
- package/images/maptiler-logo.svg +19 -0
- package/images/maptiler-sdk-logo.afdesign +0 -0
- package/images/maptiler-sdk-logo.svg +66 -0
- package/images/screenshots/alps.gif +0 -0
- package/images/screenshots/grandcanyon.gif +0 -0
- package/images/screenshots/lang-arabic.png +0 -0
- package/images/screenshots/lang-hebrew.png +0 -0
- package/images/screenshots/multilang.gif +0 -0
- package/images/screenshots/static-bounded-europe-1024.png +0 -0
- package/images/screenshots/static-bounded-europe-2048.png +0 -0
- package/images/screenshots/static-bounded-portugal-1024x2048.png +0 -0
- package/images/screenshots/static-bounded-portugal-2048x2048.png +0 -0
- package/images/screenshots/static-with-path.png +0 -0
- package/images/screenshots/style-basic-v2.png +0 -0
- package/images/screenshots/style-bright.png +0 -0
- package/images/screenshots/style-dataviz-dark.png +0 -0
- package/images/screenshots/style-hybrid.png +0 -0
- package/images/screenshots/style-osm.png +0 -0
- package/images/screenshots/style-outdoor.png +0 -0
- package/images/screenshots/style-pastel.png +0 -0
- package/images/screenshots/style-satellite.png +0 -0
- package/images/screenshots/style-streets-v2-dark.png +0 -0
- package/images/screenshots/style-streets-v2-light.png +0 -0
- package/images/screenshots/style-streets-v2.png +0 -0
- package/images/screenshots/style-toner.png +0 -0
- package/images/screenshots/style-topo.png +0 -0
- package/images/screenshots/style-topographique.png +0 -0
- package/images/screenshots/style-voyager.png +0 -0
- package/images/screenshots/style-winter.png +0 -0
- package/package.json +71 -0
- package/readme.md +609 -0
- package/rollup.config.js +161 -0
- package/scripts/replace-path-with-content.js +51 -0
- package/src/CustomGeolocateControl.ts +193 -0
- package/src/CustomLogoControl.ts +59 -0
- package/src/Map.ts +897 -0
- package/src/MaptilerNavigationControl.ts +66 -0
- package/src/Point.ts +336 -0
- package/src/TerrainControl.ts +87 -0
- package/src/config.ts +92 -0
- package/src/defaults.ts +20 -0
- package/src/index.ts +171 -0
- package/src/language.ts +139 -0
- package/src/mapstyle.ts +38 -0
- package/src/style/style_template.css +146 -0
- package/src/style/svg/v6-compass.svg +12 -0
- package/src/style/svg/v6-fullscreen-off.svg +7 -0
- package/src/style/svg/v6-fullscreen.svg +7 -0
- package/src/style/svg/v6-geolocate-active-error.svg +10 -0
- package/src/style/svg/v6-geolocate-active.svg +7 -0
- package/src/style/svg/v6-geolocate-background.svg +8 -0
- package/src/style/svg/v6-geolocate-disabled.svg +10 -0
- package/src/style/svg/v6-geolocate.svg +7 -0
- package/src/style/svg/v6-terrain-on.svg +7 -0
- package/src/style/svg/v6-terrain.svg +7 -0
- package/src/style/svg/v6-zoom-minus.svg +7 -0
- package/src/style/svg/v6-zoom-plus.svg +7 -0
- package/src/tools.ts +45 -0
- package/src/unit.ts +1 -0
- package/tsconfig.json +11 -0
- package/typedoc.css +118 -0
- package/typedoc.json +13 -0
package/rollup.config.js
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import os from "os";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import dts from "rollup-plugin-dts";
|
|
4
|
+
import esbuild from "rollup-plugin-esbuild";
|
|
5
|
+
import { nodeResolve } from "@rollup/plugin-node-resolve";
|
|
6
|
+
import globals from "rollup-plugin-node-globals";
|
|
7
|
+
import commonjs from "@rollup/plugin-commonjs";
|
|
8
|
+
import copy from 'rollup-plugin-copy-merge'
|
|
9
|
+
import json from '@rollup/plugin-json';
|
|
10
|
+
import execute from "rollup-plugin-shell";
|
|
11
|
+
|
|
12
|
+
const outputName = "maptiler-sdk";
|
|
13
|
+
const externals = ["maplibre-gl", "@maptiler/client", "@mapbox/point-geometry", "uuid", "@mapbox/unitbezier", "events", "js-base64"];
|
|
14
|
+
|
|
15
|
+
const cssMaplibreFilepath = "node_modules/maplibre-gl/dist/maplibre-gl.css";
|
|
16
|
+
const cssTemplateFilepath = "src/style/style_template.css";
|
|
17
|
+
const cssIntermatdiateFilepath = path.join(os.tmpdir(), `${outputName}-style.css`);
|
|
18
|
+
const cssDistribution = `dist/${outputName}.css`;
|
|
19
|
+
|
|
20
|
+
const replaceCssPath = execute({ commands: [`node scripts/replace-path-with-content.js ${cssTemplateFilepath} ${cssIntermatdiateFilepath}`], hook: "buildStart" })
|
|
21
|
+
|
|
22
|
+
const copyCssPlugin = copy({
|
|
23
|
+
targets: [
|
|
24
|
+
{
|
|
25
|
+
src: [cssMaplibreFilepath, cssIntermatdiateFilepath],
|
|
26
|
+
file: cssDistribution,
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const copyUmdBundle = copy({
|
|
32
|
+
targets: [
|
|
33
|
+
{
|
|
34
|
+
src: `dist/${outputName}.umd.js`,
|
|
35
|
+
dest: "demos/",
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
src: `dist/${outputName}.css`,
|
|
39
|
+
dest: "demos/",
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
hook: "writeBundle"
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
const bundles = [
|
|
47
|
+
// ES module, not minified + sourcemap
|
|
48
|
+
{
|
|
49
|
+
plugins: [
|
|
50
|
+
replaceCssPath,
|
|
51
|
+
copyCssPlugin,
|
|
52
|
+
json(),
|
|
53
|
+
esbuild()
|
|
54
|
+
],
|
|
55
|
+
output: [
|
|
56
|
+
{
|
|
57
|
+
file: `dist/${outputName}.mjs`,
|
|
58
|
+
format: "es",
|
|
59
|
+
sourcemap: true,
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
input: "src/index.ts",
|
|
63
|
+
watch: {
|
|
64
|
+
include: "src/**",
|
|
65
|
+
},
|
|
66
|
+
external: externals,
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
// UMD module, not minified
|
|
70
|
+
{
|
|
71
|
+
plugins: [
|
|
72
|
+
replaceCssPath,
|
|
73
|
+
copyCssPlugin,
|
|
74
|
+
nodeResolve({
|
|
75
|
+
preferBuiltins: false,
|
|
76
|
+
}), // for the standalone UMD, we want to resolve so that the bundle contains all the dep.
|
|
77
|
+
commonjs({ include: "node_modules/**" }),
|
|
78
|
+
globals(),
|
|
79
|
+
json(),
|
|
80
|
+
esbuild(),
|
|
81
|
+
copyUmdBundle,
|
|
82
|
+
],
|
|
83
|
+
output: [
|
|
84
|
+
{
|
|
85
|
+
name: "maptilersdk",
|
|
86
|
+
file: `dist/${outputName}.umd.js`,
|
|
87
|
+
format: "umd",
|
|
88
|
+
sourcemap: true,
|
|
89
|
+
},
|
|
90
|
+
],
|
|
91
|
+
input: "src/index.ts",
|
|
92
|
+
watch: {
|
|
93
|
+
include: "src/**",
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
|
|
97
|
+
// types
|
|
98
|
+
{
|
|
99
|
+
plugins: [dts()],
|
|
100
|
+
output: {
|
|
101
|
+
file: `dist/${outputName}.d.ts`,
|
|
102
|
+
format: "es",
|
|
103
|
+
},
|
|
104
|
+
input: "src/index.ts",
|
|
105
|
+
},
|
|
106
|
+
];
|
|
107
|
+
|
|
108
|
+
if (process.env.NODE_ENV === "production") {
|
|
109
|
+
bundles.push(
|
|
110
|
+
// ES module, minified
|
|
111
|
+
{
|
|
112
|
+
plugins: [
|
|
113
|
+
replaceCssPath,
|
|
114
|
+
copyCssPlugin,
|
|
115
|
+
json(),
|
|
116
|
+
esbuild({
|
|
117
|
+
sourceMap: false,
|
|
118
|
+
minify: true,
|
|
119
|
+
}),
|
|
120
|
+
],
|
|
121
|
+
output: [
|
|
122
|
+
{
|
|
123
|
+
file: `dist/${outputName}.min.mjs`,
|
|
124
|
+
format: "es",
|
|
125
|
+
},
|
|
126
|
+
],
|
|
127
|
+
input: "src/index.ts",
|
|
128
|
+
external: externals,
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
plugins: [
|
|
132
|
+
replaceCssPath,
|
|
133
|
+
copyCssPlugin,
|
|
134
|
+
nodeResolve({
|
|
135
|
+
preferBuiltins: false,
|
|
136
|
+
}), // for the standalone UMD, we want to resolve so that the bundle contains all the dep.
|
|
137
|
+
commonjs({ include: "node_modules/**" }),
|
|
138
|
+
globals(),
|
|
139
|
+
json(),
|
|
140
|
+
esbuild({
|
|
141
|
+
sourceMap: false,
|
|
142
|
+
minify: true,
|
|
143
|
+
}),
|
|
144
|
+
],
|
|
145
|
+
output: [
|
|
146
|
+
{
|
|
147
|
+
name: "maptilersdk",
|
|
148
|
+
file: `dist/${outputName}.umd.min.js`,
|
|
149
|
+
format: "umd",
|
|
150
|
+
sourcemap: false,
|
|
151
|
+
},
|
|
152
|
+
],
|
|
153
|
+
input: "src/index.ts",
|
|
154
|
+
watch: {
|
|
155
|
+
include: "src/**",
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export default bundles;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This script takes a text file as input and a text file as output.
|
|
3
|
+
* The input text is supposed to contain occurences of filepath between
|
|
4
|
+
* square brackets such as "foo bar [some/file/path.txt] foofoo barbar".
|
|
5
|
+
*
|
|
6
|
+
* This script replaces this pattern by the actual content of the file
|
|
7
|
+
* between square brackets.
|
|
8
|
+
*
|
|
9
|
+
* The main purpose is to inject actual SVG string (URL encoded) into CSS
|
|
10
|
+
* for `background-image` properties. If need be, we could also apply the
|
|
11
|
+
* same logic for more file types such as png with base64 string.
|
|
12
|
+
*
|
|
13
|
+
* This script is used by rollup.config.js , so check there to see it in
|
|
14
|
+
* application.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import fs from 'fs';
|
|
18
|
+
import { exit } from 'process';
|
|
19
|
+
|
|
20
|
+
if (process.argv.length !== 4) {
|
|
21
|
+
console.error("This script takes 2 arguments: input_filepath.txt output_filpath.txt")
|
|
22
|
+
exit(1);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
let text = fs.readFileSync(process.argv[2], "utf8");
|
|
26
|
+
|
|
27
|
+
// replace based on file extension
|
|
28
|
+
const transforms = {
|
|
29
|
+
svg: (filepath) => {
|
|
30
|
+
const fileText = encodeURIComponent(fs.readFileSync(filepath, "utf8"));
|
|
31
|
+
return `"data:image/svg+xml;charset=utf-8,${fileText}"`;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Find all occurrences of file paths between square brackets
|
|
36
|
+
let filePaths = text.match(/\[(.*?)\]/g);
|
|
37
|
+
|
|
38
|
+
// Replace all occurrences of file paths with the actual text contained in the files
|
|
39
|
+
filePaths.forEach(filePath => {
|
|
40
|
+
let filepath = filePath.slice(1, -1); // remove the square brackets
|
|
41
|
+
const extension = filepath.split(".").pop().toLowerCase();
|
|
42
|
+
|
|
43
|
+
if (!(extension in transforms)) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
text = text.replace(filePath, transforms[extension](filepath))
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
// console.log(text);
|
|
51
|
+
fs.writeFileSync(process.argv[3], text);
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { GeolocateControl, LngLat, LngLatLike, Marker } from "maplibre-gl";
|
|
2
|
+
import { DOMcreate } from "./tools";
|
|
3
|
+
|
|
4
|
+
export class CustomGeolocateControl extends GeolocateControl {
|
|
5
|
+
private lastUpdatedCenter: LngLat;
|
|
6
|
+
private lastUpdatedZoom: number;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Update the camera location to center on the current position
|
|
10
|
+
*
|
|
11
|
+
* @param {Position} position the Geolocation API Position
|
|
12
|
+
* @private
|
|
13
|
+
*/
|
|
14
|
+
_updateCamera(position: GeolocationPosition) {
|
|
15
|
+
const center = new LngLat(
|
|
16
|
+
position.coords.longitude,
|
|
17
|
+
position.coords.latitude
|
|
18
|
+
);
|
|
19
|
+
const radius = position.coords.accuracy;
|
|
20
|
+
const bearing = this._map.getBearing();
|
|
21
|
+
const options = {
|
|
22
|
+
bearing,
|
|
23
|
+
...this.options.fitBoundsOptions,
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
console.log("moving camera");
|
|
27
|
+
|
|
28
|
+
this._map.fitBounds(center.toBounds(radius), options, {
|
|
29
|
+
geolocateSource: true, // tag this camera change so it won't cause the control to change to background state
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
let hasFittingBeenDisrupted = false;
|
|
33
|
+
|
|
34
|
+
const flagFittingDisruption = () => {
|
|
35
|
+
console.log("DISRUPTED FITTING!");
|
|
36
|
+
hasFittingBeenDisrupted = true;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
this._map.once("click", flagFittingDisruption);
|
|
40
|
+
this._map.once("dblclick", flagFittingDisruption);
|
|
41
|
+
this._map.once("dragstart", flagFittingDisruption);
|
|
42
|
+
this._map.once("mousedown", flagFittingDisruption);
|
|
43
|
+
this._map.once("touchstart", flagFittingDisruption);
|
|
44
|
+
this._map.once("wheel", flagFittingDisruption);
|
|
45
|
+
|
|
46
|
+
this._map.once("moveend", () => {
|
|
47
|
+
console.log("done moving, with disruption:", hasFittingBeenDisrupted);
|
|
48
|
+
|
|
49
|
+
// Removing the events if not used
|
|
50
|
+
this._map.off("click", flagFittingDisruption);
|
|
51
|
+
this._map.off("dblclick", flagFittingDisruption);
|
|
52
|
+
this._map.off("dragstart", flagFittingDisruption);
|
|
53
|
+
this._map.off("mousedown", flagFittingDisruption);
|
|
54
|
+
this._map.off("touchstart", flagFittingDisruption);
|
|
55
|
+
this._map.off("wheel", flagFittingDisruption);
|
|
56
|
+
|
|
57
|
+
if (hasFittingBeenDisrupted) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
this.lastUpdatedCenter = this._map.getCenter();
|
|
62
|
+
this.lastUpdatedZoom = this._map.getZoom();
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
_setupUI(supported: boolean) {
|
|
67
|
+
this.lastUpdatedCenter = this._map.getCenter();
|
|
68
|
+
this.lastUpdatedZoom = this._map.getZoom();
|
|
69
|
+
|
|
70
|
+
this._container.addEventListener("contextmenu", (e: MouseEvent) =>
|
|
71
|
+
e.preventDefault()
|
|
72
|
+
);
|
|
73
|
+
this._geolocateButton = DOMcreate(
|
|
74
|
+
"button",
|
|
75
|
+
"maplibregl-ctrl-geolocate",
|
|
76
|
+
this._container
|
|
77
|
+
);
|
|
78
|
+
DOMcreate(
|
|
79
|
+
"span",
|
|
80
|
+
"maplibregl-ctrl-icon",
|
|
81
|
+
this._geolocateButton
|
|
82
|
+
).setAttribute("aria-hidden", "true");
|
|
83
|
+
this._geolocateButton.type = "button";
|
|
84
|
+
|
|
85
|
+
if (supported === false) {
|
|
86
|
+
// warnOnce('Geolocation support is not available so the GeolocateControl will be disabled.');
|
|
87
|
+
const title = this._map._getUIString(
|
|
88
|
+
"GeolocateControl.LocationNotAvailable"
|
|
89
|
+
);
|
|
90
|
+
this._geolocateButton.disabled = true;
|
|
91
|
+
this._geolocateButton.title = title;
|
|
92
|
+
this._geolocateButton.setAttribute("aria-label", title);
|
|
93
|
+
} else {
|
|
94
|
+
const title = this._map._getUIString("GeolocateControl.FindMyLocation");
|
|
95
|
+
this._geolocateButton.title = title;
|
|
96
|
+
this._geolocateButton.setAttribute("aria-label", title);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (this.options.trackUserLocation) {
|
|
100
|
+
this._geolocateButton.setAttribute("aria-pressed", "false");
|
|
101
|
+
this._watchState = "OFF";
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// when showUserLocation is enabled, keep the Geolocate button disabled until the device location marker is setup on the map
|
|
105
|
+
if (this.options.showUserLocation) {
|
|
106
|
+
this._dotElement = DOMcreate("div", "maplibregl-user-location-dot");
|
|
107
|
+
|
|
108
|
+
this._userLocationDotMarker = new Marker(this._dotElement);
|
|
109
|
+
|
|
110
|
+
this._circleElement = DOMcreate(
|
|
111
|
+
"div",
|
|
112
|
+
"maplibregl-user-location-accuracy-circle"
|
|
113
|
+
);
|
|
114
|
+
this._accuracyCircleMarker = new Marker({
|
|
115
|
+
element: this._circleElement,
|
|
116
|
+
pitchAlignment: "map",
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
if (this.options.trackUserLocation) this._watchState = "OFF";
|
|
120
|
+
|
|
121
|
+
this._map.on("move", this._onZoom);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
this._geolocateButton.addEventListener("click", this.trigger.bind(this));
|
|
125
|
+
|
|
126
|
+
this._setup = true;
|
|
127
|
+
|
|
128
|
+
// when the camera is changed (and it's not as a result of the Geolocation Control) change
|
|
129
|
+
// the watch mode to background watch, so that the marker is updated but not the camera.
|
|
130
|
+
// Addition: Yet the status change does not occur if the ditance it has moved to is less than
|
|
131
|
+
// one meter from the last auto-updated position. This is to guarrantee that if the move
|
|
132
|
+
// is a zoom, rotation or pitch (where the center stays the same) then we can keep the ACTIVE_LOCK
|
|
133
|
+
// mode ON.
|
|
134
|
+
if (this.options.trackUserLocation) {
|
|
135
|
+
this._map.on("moveend", (event: any) => {
|
|
136
|
+
const fromResize =
|
|
137
|
+
event.originalEvent && event.originalEvent.type === "resize";
|
|
138
|
+
const movingDistance = this.lastUpdatedCenter.distanceTo(
|
|
139
|
+
this._map.getCenter()
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
if (
|
|
143
|
+
!event.geolocateSource &&
|
|
144
|
+
this._watchState === "ACTIVE_LOCK" &&
|
|
145
|
+
!fromResize &&
|
|
146
|
+
movingDistance > 1
|
|
147
|
+
) {
|
|
148
|
+
this._watchState = "BACKGROUND";
|
|
149
|
+
this._geolocateButton.classList.add(
|
|
150
|
+
"maplibregl-ctrl-geolocate-background"
|
|
151
|
+
);
|
|
152
|
+
this._geolocateButton.classList.remove(
|
|
153
|
+
"maplibregl-ctrl-geolocate-active"
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
this.fire(new Event("trackuserlocationend"));
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
_updateCircleRadius() {
|
|
163
|
+
if (
|
|
164
|
+
this._watchState !== "BACKGROUND" &&
|
|
165
|
+
this._watchState !== "ACTIVE_LOCK"
|
|
166
|
+
) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const lastKnownLocation: LngLatLike = [
|
|
171
|
+
this._lastKnownPosition.coords.longitude,
|
|
172
|
+
this._lastKnownPosition.coords.latitude,
|
|
173
|
+
];
|
|
174
|
+
|
|
175
|
+
const projectedLocation = this._map.project(lastKnownLocation);
|
|
176
|
+
const a = this._map.unproject([projectedLocation.x, projectedLocation.y]);
|
|
177
|
+
const b = this._map.unproject([
|
|
178
|
+
projectedLocation.x + 20,
|
|
179
|
+
projectedLocation.y,
|
|
180
|
+
]);
|
|
181
|
+
const metersPerPixel = a.distanceTo(b) / 20;
|
|
182
|
+
|
|
183
|
+
const circleDiameter = Math.ceil((2.0 * this._accuracy) / metersPerPixel);
|
|
184
|
+
this._circleElement.style.width = `${circleDiameter}px`;
|
|
185
|
+
this._circleElement.style.height = `${circleDiameter}px`;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
_onZoom() {
|
|
189
|
+
if (this.options.showUserLocation && this.options.showAccuracyCircle) {
|
|
190
|
+
this._updateCircleRadius();
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import maplibregl from "maplibre-gl";
|
|
2
|
+
import { defaults } from "./defaults";
|
|
3
|
+
import { Map } from "./Map";
|
|
4
|
+
|
|
5
|
+
type LogoOptions = maplibregl.LogoOptions & {
|
|
6
|
+
logoURL?: string;
|
|
7
|
+
linkURL?: string;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* This LogoControl extends the MapLibre LogoControl but instead can use any image URL and
|
|
12
|
+
* any link URL. By default this is using MapTiler logo and URL.
|
|
13
|
+
*/
|
|
14
|
+
export class CustomLogoControl extends maplibregl.LogoControl {
|
|
15
|
+
private logoURL = "";
|
|
16
|
+
private linkURL = "";
|
|
17
|
+
|
|
18
|
+
constructor(options: LogoOptions = {}) {
|
|
19
|
+
super(options);
|
|
20
|
+
|
|
21
|
+
this.logoURL = options.logoURL ?? defaults.maptilerLogoURL;
|
|
22
|
+
this.linkURL = options.linkURL ?? defaults.maptilerURL;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
onAdd(map: Map): HTMLElement {
|
|
26
|
+
this._map = map;
|
|
27
|
+
this._compact = this.options && this.options.compact;
|
|
28
|
+
this._container = window.document.createElement("div");
|
|
29
|
+
this._container.className = "maplibregl-ctrl";
|
|
30
|
+
const anchor = window.document.createElement("a");
|
|
31
|
+
anchor.style.backgroundRepeat = "no-repeat";
|
|
32
|
+
anchor.style.cursor = "pointer";
|
|
33
|
+
anchor.style.display = "block";
|
|
34
|
+
anchor.style.height = "23px";
|
|
35
|
+
anchor.style.margin = "0 0 -4px -4px";
|
|
36
|
+
anchor.style.overflow = "hidden";
|
|
37
|
+
anchor.style.width = "88px";
|
|
38
|
+
anchor.style.backgroundImage = `url(${this.logoURL})`;
|
|
39
|
+
anchor.style.backgroundSize = "100px 30px";
|
|
40
|
+
anchor.style.width = "100px";
|
|
41
|
+
anchor.style.height = "30px";
|
|
42
|
+
|
|
43
|
+
anchor.target = "_blank";
|
|
44
|
+
anchor.rel = "noopener nofollow";
|
|
45
|
+
anchor.href = this.linkURL;
|
|
46
|
+
anchor.setAttribute(
|
|
47
|
+
"aria-label",
|
|
48
|
+
this._map._getUIString("LogoControl.Title")
|
|
49
|
+
);
|
|
50
|
+
anchor.setAttribute("rel", "noopener nofollow");
|
|
51
|
+
this._container.appendChild(anchor);
|
|
52
|
+
this._container.style.display = "block";
|
|
53
|
+
|
|
54
|
+
this._map.on("resize", this._updateCompact);
|
|
55
|
+
this._updateCompact();
|
|
56
|
+
|
|
57
|
+
return this._container;
|
|
58
|
+
}
|
|
59
|
+
}
|