@basemaps/landing 6.27.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.
Files changed (73) hide show
  1. package/CHANGELOG.md +1097 -0
  2. package/LICENSE +21 -0
  3. package/README.md +3 -0
  4. package/build/__test__/config.debug.test.d.ts +2 -0
  5. package/build/__test__/config.debug.test.d.ts.map +1 -0
  6. package/build/__test__/config.debug.test.js +28 -0
  7. package/build/__test__/config.test.d.ts +2 -0
  8. package/build/__test__/config.test.d.ts.map +1 -0
  9. package/build/__test__/config.test.js +8 -0
  10. package/build/__test__/geojson.test.d.ts +2 -0
  11. package/build/__test__/geojson.test.d.ts.map +1 -0
  12. package/build/__test__/geojson.test.js +42 -0
  13. package/build/__test__/map.config.test.d.ts +2 -0
  14. package/build/__test__/map.config.test.d.ts.map +1 -0
  15. package/build/__test__/map.config.test.js +103 -0
  16. package/build/__test__/tile.matrix.test.d.ts +2 -0
  17. package/build/__test__/tile.matrix.test.d.ts.map +1 -0
  18. package/build/__test__/tile.matrix.test.js +29 -0
  19. package/build/attribution.d.ts +48 -0
  20. package/build/attribution.d.ts.map +1 -0
  21. package/build/attribution.js +137 -0
  22. package/build/components/copyable.d.ts +14 -0
  23. package/build/components/copyable.d.ts.map +1 -0
  24. package/build/components/copyable.js +26 -0
  25. package/build/components/debug.d.ts +34 -0
  26. package/build/components/debug.d.ts.map +1 -0
  27. package/build/components/debug.js +309 -0
  28. package/build/components/layer.switcher.dropdown.d.ts +21 -0
  29. package/build/components/layer.switcher.dropdown.d.ts.map +1 -0
  30. package/build/components/layer.switcher.dropdown.js +68 -0
  31. package/build/components/layout.footer.d.ts +8 -0
  32. package/build/components/layout.footer.d.ts.map +1 -0
  33. package/build/components/layout.footer.js +23 -0
  34. package/build/components/layout.header.d.ts +23 -0
  35. package/build/components/layout.header.d.ts.map +1 -0
  36. package/build/components/layout.header.js +98 -0
  37. package/build/components/link.d.ts +17 -0
  38. package/build/components/link.d.ts.map +1 -0
  39. package/build/components/link.js +12 -0
  40. package/build/components/map.d.ts +31 -0
  41. package/build/components/map.d.ts.map +1 -0
  42. package/build/components/map.js +136 -0
  43. package/build/components/map.switcher.d.ts +21 -0
  44. package/build/components/map.switcher.d.ts.map +1 -0
  45. package/build/components/map.switcher.js +78 -0
  46. package/build/config.d.ts +15 -0
  47. package/build/config.d.ts.map +1 -0
  48. package/build/config.debug.d.ts +22 -0
  49. package/build/config.debug.d.ts.map +1 -0
  50. package/build/config.debug.js +62 -0
  51. package/build/config.js +43 -0
  52. package/build/config.map.d.ts +51 -0
  53. package/build/config.map.d.ts.map +1 -0
  54. package/build/config.map.js +179 -0
  55. package/build/global.d.ts +9 -0
  56. package/build/global.d.ts.map +1 -0
  57. package/build/global.js +1 -0
  58. package/build/index.d.ts +2 -0
  59. package/build/index.d.ts.map +1 -0
  60. package/build/index.js +21 -0
  61. package/build/split.d.ts +11 -0
  62. package/build/split.d.ts.map +1 -0
  63. package/build/split.js +45 -0
  64. package/build/tile.matrix.d.ts +23 -0
  65. package/build/tile.matrix.d.ts.map +1 -0
  66. package/build/tile.matrix.js +77 -0
  67. package/build/url.d.ts +37 -0
  68. package/build/url.d.ts.map +1 -0
  69. package/build/url.js +78 -0
  70. package/build/webp.d.ts +3 -0
  71. package/build/webp.d.ts.map +1 -0
  72. package/build/webp.js +32 -0
  73. package/package.json +107 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Crown copyright (c), Toitū Te Whenua Land Information New Zealand on behalf of the New Zealand Government.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # @basemaps/landing
2
+
3
+ The landing page for basemaps https://basemaps.linz.govt.nz
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=config.debug.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.debug.test.d.ts","sourceRoot":"","sources":["../../src/__test__/config.debug.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,28 @@
1
+ import o from 'ospec';
2
+ import { ConfigDebug, DebugDefaults } from '../config.debug.js';
3
+ function urlToString(o) {
4
+ const url = new URLSearchParams();
5
+ ConfigDebug.toUrl(o, url);
6
+ return url.toString();
7
+ }
8
+ o.spec('ConfigDebug', () => {
9
+ o('should only serialize when not defaults', () => {
10
+ o(urlToString(DebugDefaults)).equals('');
11
+ });
12
+ o('should write to url', () => {
13
+ o(urlToString({ debug: true })).equals('debug=true');
14
+ o(urlToString({ debug: false })).equals('');
15
+ o(urlToString({ debug: true, 'debug.background': 'magenta' })).equals('debug=true&debug.background=magenta');
16
+ });
17
+ o('should round trip', () => {
18
+ const cfg = { ...DebugDefaults };
19
+ cfg.debug = true;
20
+ cfg['debug.background'] = 'magenta';
21
+ cfg['debug.layer.linz-topographic'] = 0.5;
22
+ cfg['debug.layer.linz-aerial'] = -1;
23
+ const url = urlToString(cfg);
24
+ const newCfg = { ...DebugDefaults };
25
+ ConfigDebug.fromUrl(newCfg, new URLSearchParams(`?${url}`));
26
+ o(newCfg).deepEquals(cfg);
27
+ });
28
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=config.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.test.d.ts","sourceRoot":"","sources":["../../src/__test__/config.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,8 @@
1
+ import o from 'ospec';
2
+ import { Config } from '../config.js';
3
+ o.spec('Config', () => {
4
+ o('should return the same api key', () => {
5
+ const keyA = Config.ApiKey;
6
+ o(keyA).equals(Config.ApiKey);
7
+ });
8
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=geojson.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"geojson.test.d.ts","sourceRoot":"","sources":["../../src/__test__/geojson.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,42 @@
1
+ import { GoogleTms, Nztm2000QuadTms } from '@basemaps/geo';
2
+ import { Projection } from '@basemaps/shared/build/proj/projection.js';
3
+ import o from 'ospec';
4
+ import { projectGeoJson } from '../tile.matrix.js';
5
+ /** This feautre is located in tile x:237, y:278, z:9 of NZTM2000Quad see ./NZTMTileLocation.png for a reference picture */
6
+ const feature = {
7
+ type: 'FeatureCollection',
8
+ features: [
9
+ {
10
+ type: 'Feature',
11
+ geometry: {
12
+ type: 'Polygon',
13
+ coordinates: [
14
+ [
15
+ [170.18596414439156, -45.25562110152719],
16
+ [170.18756263742395, -45.223254647413995],
17
+ [170.21809624631874, -45.22400303710795],
18
+ [170.21651505261318, -45.25637033158635],
19
+ [170.18596414439156, -45.25562110152719],
20
+ ],
21
+ ],
22
+ },
23
+ properties: {
24
+ name: '/dunedin_rural_2013_0.40m_RGBA/CC16_5000_0704.tif',
25
+ },
26
+ bbox: [170.18596414439156, -45.25562110152719, 170.21809624631874, -45.22400303710795],
27
+ },
28
+ ],
29
+ };
30
+ o.spec('GeoJSONTransform', () => {
31
+ o('should convert to the right tile location', () => {
32
+ const newFeatures = JSON.parse(JSON.stringify(feature));
33
+ projectGeoJson(newFeatures, Nztm2000QuadTms);
34
+ const firstPoint = newFeatures.features[0].geometry.coordinates[0][0];
35
+ // find the target tile that will be used by this location
36
+ const proj = Projection.get(GoogleTms).fromWgs84(firstPoint);
37
+ const pixels = GoogleTms.sourceToPixels(proj[0], proj[1], 9);
38
+ const tile = { x: pixels.x / GoogleTms.tileSize, y: pixels.y / GoogleTms.tileSize };
39
+ o(tile.x.toFixed(2)).equals('237.11');
40
+ o(tile.y.toFixed(2)).equals('278.69');
41
+ });
42
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=map.config.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"map.config.test.d.ts","sourceRoot":"","sources":["../../src/__test__/map.config.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,103 @@
1
+ import { GoogleTms, Nztm2000QuadTms, Nztm2000Tms } from '@basemaps/geo';
2
+ import o from 'ospec';
3
+ import { Config } from '../config.js';
4
+ import { MapConfig } from '../config.map.js';
5
+ import { WindowUrl } from '../url.js';
6
+ o.spec('WindowUrl', () => {
7
+ const mc = new MapConfig();
8
+ o.beforeEach(() => {
9
+ global.window = { location: { origin: 'https://basemaps.linz.govt.nz' } };
10
+ });
11
+ o.afterEach(() => {
12
+ delete global.window;
13
+ });
14
+ const googleLoc = { lat: 174.7763921, lon: -41.277848, zoom: 8 };
15
+ o.spec('Hash', () => {
16
+ o('should encode lon lat', () => {
17
+ const output = WindowUrl.toHash(googleLoc);
18
+ o(output).equals('#@174.7763921,-41.2778480,z8');
19
+ o(WindowUrl.fromHash(output)).deepEquals(googleLoc);
20
+ o(WindowUrl.fromHash('#@174.7763921,-41.2778480,8z')).deepEquals(googleLoc);
21
+ });
22
+ o('should encode fractional zooms', () => {
23
+ o(WindowUrl.fromHash('#@174.7763921,-41.2778480,14.25z').zoom).deepEquals(14.25);
24
+ o(WindowUrl.fromHash('#@174.7763921,-41.2778480,z14.25').zoom).deepEquals(14.25);
25
+ });
26
+ o('should not fail if parts are missing', () => {
27
+ const missingZoom = WindowUrl.fromHash('#@174.7763921,-41.2778480,');
28
+ o(missingZoom).deepEquals({ lat: googleLoc.lat, lon: googleLoc.lon });
29
+ const missingParam = WindowUrl.fromHash('#@174.7763921,');
30
+ o(missingParam).deepEquals({});
31
+ });
32
+ });
33
+ o('should extract default information', () => {
34
+ mc.updateFromUrl('');
35
+ o(mc.tileMatrix).equals(GoogleTms);
36
+ o(mc.layerId).equals('aerial');
37
+ o(mc.style).equals(null);
38
+ o(mc.isDebug).equals(false);
39
+ });
40
+ o('should support vector tiles', () => {
41
+ mc.updateFromUrl('?i=topographic');
42
+ o(mc.tileMatrix).equals(GoogleTms);
43
+ o(mc.layerId).equals('topographic');
44
+ o(mc.style).equals('topographic');
45
+ o(mc.isDebug).equals(false);
46
+ });
47
+ o('should support NZTM tiles', () => {
48
+ mc.updateFromUrl('?p=2193');
49
+ o(mc.tileMatrix).equals(Nztm2000QuadTms);
50
+ o(mc.layerId).equals('aerial');
51
+ o(mc.style).equals(null);
52
+ o(mc.isDebug).equals(false);
53
+ });
54
+ o('should support basic', () => {
55
+ mc.updateFromUrl('?i=abc123&s=basic&p=2193&d=true&debug');
56
+ o(mc.tileMatrix).equals(Nztm2000QuadTms);
57
+ o(mc.layerId).equals('abc123');
58
+ o(mc.style).equals('basic');
59
+ o(mc.isDebug).equals(true);
60
+ });
61
+ o('should extract tile matrix information', () => {
62
+ mc.updateFromUrl('?i=abc123&p=nztm2000&d=true&debug=yes');
63
+ o(mc.tileMatrix).equals(Nztm2000QuadTms);
64
+ mc.updateFromUrl('?i=abc123&p=nztm2000quad&d=true&debug=yes');
65
+ o(mc.tileMatrix).equals(Nztm2000QuadTms);
66
+ mc.updateFromUrl('?i=abc123&s=basic&p=NZTM2000Quad&d=true&debug=yes');
67
+ o(mc.tileMatrix).equals(Nztm2000QuadTms);
68
+ });
69
+ o('should convert to a url', () => {
70
+ const apiKey = Config.ApiKey;
71
+ mc.updateFromUrl('');
72
+ o(mc.toTileUrl("raster" /* TileRaster */)).equals(`https://basemaps.linz.govt.nz/v1/tiles/aerial/EPSG:3857/{z}/{x}/{y}.png?api=${apiKey}`);
73
+ o(mc.toTileUrl("wmts" /* Wmts */)).equals(`https://basemaps.linz.govt.nz/v1/tiles/aerial/EPSG:3857/WMTSCapabilities.xml?api=${apiKey}`);
74
+ o(mc.toTileUrl("tile-wmts" /* TileWmts */)).equals(`https://basemaps.linz.govt.nz/v1/tiles/aerial/EPSG:3857/{TileMatrix}/{TileCol}/{TileRow}.png?api=${apiKey}`);
75
+ });
76
+ o('should use default epsg codes for urls', () => {
77
+ const apiKey = Config.ApiKey;
78
+ mc.updateFromUrl('');
79
+ o(mc.toTileUrl("raster" /* TileRaster */)).equals(`https://basemaps.linz.govt.nz/v1/tiles/aerial/EPSG:3857/{z}/{x}/{y}.png?api=${apiKey}`);
80
+ mc.tileMatrix = Nztm2000Tms;
81
+ o(mc.toTileUrl("raster" /* TileRaster */)).equals(`https://basemaps.linz.govt.nz/v1/tiles/aerial/EPSG:2193/{z}/{x}/{y}.png?api=${apiKey}`);
82
+ mc.tileMatrix = Nztm2000QuadTms;
83
+ o(mc.toTileUrl("raster" /* TileRaster */)).equals(`https://basemaps.linz.govt.nz/v1/tiles/aerial/NZTM2000Quad/{z}/{x}/{y}.png?api=${apiKey}`);
84
+ });
85
+ o('should convert to a url with baseUrl', () => {
86
+ const apiKey = Config.ApiKey;
87
+ mc.updateFromUrl('');
88
+ process.env.TILE_HOST = 'https://foo.bar.com';
89
+ o(mc.toTileUrl("raster" /* TileRaster */)).equals(`https://foo.bar.com/v1/tiles/aerial/EPSG:3857/{z}/{x}/{y}.png?api=${apiKey}`);
90
+ o(mc.toTileUrl("wmts" /* Wmts */)).equals(`https://foo.bar.com/v1/tiles/aerial/EPSG:3857/WMTSCapabilities.xml?api=${apiKey}`);
91
+ o(mc.toTileUrl("tile-wmts" /* TileWmts */)).equals(`https://foo.bar.com/v1/tiles/aerial/EPSG:3857/{TileMatrix}/{TileCol}/{TileRow}.png?api=${apiKey}`);
92
+ WindowUrl.ImageFormat = 'webp';
93
+ o(mc.toTileUrl("tile-wmts" /* TileWmts */)).equals(`https://foo.bar.com/v1/tiles/aerial/EPSG:3857/{TileMatrix}/{TileCol}/{TileRow}.webp?api=${apiKey}`);
94
+ WindowUrl.ImageFormat = 'png';
95
+ delete process.env.TILE_HOST;
96
+ });
97
+ o('should remove im_ prefix from imagery', () => {
98
+ mc.updateFromUrl('i=im_01EDA2YFXH2JN264VG1HKBT625');
99
+ o(mc.layerId).equals('01EDA2YFXH2JN264VG1HKBT625');
100
+ mc.updateFromUrl('i=01EDA2YFXH2JN264VG1HKBT625');
101
+ o(mc.layerId).equals('01EDA2YFXH2JN264VG1HKBT625');
102
+ });
103
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=tile.matrix.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tile.matrix.test.d.ts","sourceRoot":"","sources":["../../src/__test__/tile.matrix.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,29 @@
1
+ import { GoogleTms, Nztm2000QuadTms, Nztm2000Tms } from '@basemaps/geo';
2
+ import o from 'ospec';
3
+ import { locationTransform } from '../tile.matrix.js';
4
+ o.spec('locationTransform', () => {
5
+ const Precision = 10 ** 8;
6
+ o('should return the same google coordinate', () => {
7
+ const location = { lat: -41.2953946, lon: 174.7812425, zoom: 15.5128 };
8
+ o(location).deepEquals(locationTransform(location, GoogleTms, GoogleTms));
9
+ });
10
+ o('should return get the nztm location', () => {
11
+ const location = { lat: -41.29539461, lon: 174.78124251, zoom: 15.5128 };
12
+ const nztmLocation = locationTransform(location, Nztm2000QuadTms, GoogleTms);
13
+ o(nztmLocation).deepEquals({ lon: 0.01247576, lat: -0.0680115, zoom: 15.5128 });
14
+ });
15
+ o('should return Transform Back', () => {
16
+ const location = { lat: -41.29539461, lon: 174.78124251, zoom: 15.5128 };
17
+ const nztmLocation = locationTransform(location, Nztm2000QuadTms, GoogleTms);
18
+ const back = locationTransform(nztmLocation, GoogleTms, Nztm2000QuadTms);
19
+ o(location).deepEquals({
20
+ lon: Math.round(back.lon * Precision) / Precision,
21
+ lat: Math.round(back.lat * Precision) / Precision,
22
+ zoom: back.zoom,
23
+ });
24
+ });
25
+ o('should not convert between non google tms', () => {
26
+ const location = { lat: -41.29539461, lon: 174.78124251, zoom: 15.5128 };
27
+ o(() => locationTransform(location, Nztm2000QuadTms, Nztm2000Tms)).throws(Error);
28
+ });
29
+ });
@@ -0,0 +1,48 @@
1
+ import { AttributionBounds } from '@basemaps/attribution/build/attribution';
2
+ import { AttributionCollection, TileMatrixSet } from '@basemaps/geo';
3
+ import { BBox } from '@linzjs/geojson';
4
+ import maplibre, { LngLatBounds } from 'maplibre-gl';
5
+ /**
6
+ * Handles displaying attributions for the OpenLayers interface
7
+ */
8
+ export declare class MapAttribution {
9
+ map: maplibre.Map;
10
+ /** handle for scheduleRender setTimeout */
11
+ private _scheduled;
12
+ /** handle for scheduleRender requestAnimationFrame */
13
+ private _raf;
14
+ attributionHtml: string;
15
+ bounds: LngLatBounds;
16
+ zoom: number;
17
+ filteredRecords: AttributionCollection[];
18
+ attributionControl?: maplibre.AttributionControl | null;
19
+ constructor(map: maplibre.Map);
20
+ /**
21
+ * Trigger an attribution text update.
22
+ */
23
+ resetAttribution: () => void;
24
+ /**
25
+ * Trigger an attribution text update, will not update if the attribution text not change.
26
+ * Will fetch attributions if needed
27
+ */
28
+ updateAttribution: () => void;
29
+ isIgnored: (attr: AttributionBounds) => boolean;
30
+ /**
31
+ * Only update attributions at most every 200ms
32
+ */
33
+ private scheduleRender;
34
+ removeAttribution(): void;
35
+ /**
36
+ * Set the attribution text if needed
37
+ */
38
+ renderAttribution: () => void;
39
+ /**
40
+ * Covert Mapbox Bounds to tileMatrix BBox
41
+ */
42
+ mapboxBoundToBbox(bounds: LngLatBounds, tileMatrix: TileMatrixSet): BBox;
43
+ /**
44
+ * Add attribution for vector map
45
+ */
46
+ vectorAttribution(): void;
47
+ }
48
+ //# sourceMappingURL=attribution.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attribution.d.ts","sourceRoot":"","sources":["../src/attribution.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,yCAAyC,CAAC;AAC5E,OAAO,EAAE,qBAAqB,EAAmB,aAAa,EAAE,MAAM,eAAe,CAAC;AACtF,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,QAAQ,EAAE,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAYrD;;GAEG;AACH,qBAAa,cAAc;IACzB,GAAG,EAAE,QAAQ,CAAC,GAAG,CAAC;IAElB,2CAA2C;IAC3C,OAAO,CAAC,UAAU,CAAsC;IACxD,sDAAsD;IACtD,OAAO,CAAC,IAAI,CAAK;IAEjB,eAAe,SAAM;IACrB,MAAM,EAAE,YAAY,CAAkC;IACtD,IAAI,SAAM;IACV,eAAe,EAAE,qBAAqB,EAAE,CAAM;IAC9C,kBAAkB,CAAC,EAAE,QAAQ,CAAC,kBAAkB,GAAG,IAAI,CAAC;gBAE5C,GAAG,EAAE,QAAQ,CAAC,GAAG;IAQ7B;;OAEG;IACH,gBAAgB,QAAO,IAAI,CAGzB;IAEF;;;OAGG;IACH,iBAAiB,QAAO,IAAI,CAkB1B;IAGF,SAAS,SAAU,iBAAiB,KAAG,OAAO,CAE5C;IAEF;;OAEG;IACH,OAAO,CAAC,cAAc;IActB,iBAAiB,IAAI,IAAI;IAKzB;;OAEG;IACH,iBAAiB,QAAO,IAAI,CA2B1B;IAEF;;OAEG;IACH,iBAAiB,CAAC,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,aAAa,GAAG,IAAI;IASxE;;OAEG;IACH,iBAAiB,IAAI,IAAI;CAK1B"}
@@ -0,0 +1,137 @@
1
+ import { Attribution } from '@basemaps/attribution';
2
+ import { GoogleTms, Stac } from '@basemaps/geo';
3
+ import maplibre, { LngLatBounds } from 'maplibre-gl';
4
+ import { Config } from './config.js';
5
+ import { locationTransform } from './tile.matrix.js';
6
+ const Copyright = `© ${Stac.License} LINZ`;
7
+ /** Cache the loading of attribution */
8
+ const Attributions = new Map();
9
+ /** Rendering process needs synch access */
10
+ const AttributionSync = new Map();
11
+ /**
12
+ * Handles displaying attributions for the OpenLayers interface
13
+ */
14
+ export class MapAttribution {
15
+ constructor(map) {
16
+ /** handle for scheduleRender requestAnimationFrame */
17
+ this._raf = 0;
18
+ this.attributionHtml = '';
19
+ this.bounds = new LngLatBounds([0, 0, 0, 0]);
20
+ this.zoom = -1;
21
+ this.filteredRecords = [];
22
+ /**
23
+ * Trigger an attribution text update.
24
+ */
25
+ this.resetAttribution = () => {
26
+ this.attributionHtml = '';
27
+ this.updateAttribution();
28
+ };
29
+ /**
30
+ * Trigger an attribution text update, will not update if the attribution text not change.
31
+ * Will fetch attributions if needed
32
+ */
33
+ this.updateAttribution = () => {
34
+ // Vector layers currently have no attribution
35
+ if (Config.map.isVector)
36
+ return this.vectorAttribution();
37
+ const tmsId = Config.map.layerKeyTms;
38
+ let loader = Attributions.get(tmsId);
39
+ if (loader == null) {
40
+ loader = Attribution.load(Config.map.toTileUrl("attribution" /* Attribution */)).catch(() => null);
41
+ Attributions.set(tmsId, loader);
42
+ loader.then((attr) => {
43
+ if (attr == null)
44
+ return;
45
+ attr.isIgnored = this.isIgnored;
46
+ AttributionSync.set(tmsId, attr);
47
+ this.scheduleRender();
48
+ });
49
+ }
50
+ this.scheduleRender();
51
+ };
52
+ // Ignore DEMS from the attribution list
53
+ this.isIgnored = (attr) => {
54
+ return attr.collection.title.toLowerCase().startsWith('geographx');
55
+ };
56
+ /**
57
+ * Set the attribution text if needed
58
+ */
59
+ this.renderAttribution = () => {
60
+ var _a;
61
+ this._raf = 0;
62
+ const attr = AttributionSync.get(Config.map.layerKeyTms);
63
+ if (attr == null)
64
+ return this.removeAttribution();
65
+ this.zoom = Math.round((_a = this.map.getZoom()) !== null && _a !== void 0 ? _a : 0);
66
+ this.bounds = this.map.getBounds();
67
+ // Note that Mapbox rendering 512×512 image tiles are offset by one zoom level compared to 256×256 tiles.
68
+ // For example, 512×512 tiles at zoom level 4 are equivalent to 256×256 tiles at zoom level 5.
69
+ this.zoom += 1;
70
+ const bbox = this.mapboxBoundToBbox(this.bounds, Config.map.tileMatrix);
71
+ const filtered = attr.filter(bbox, this.zoom);
72
+ let attributionHTML = attr.renderList(filtered);
73
+ if (attributionHTML === '') {
74
+ attributionHTML = Copyright;
75
+ }
76
+ else {
77
+ attributionHTML = Copyright + ' - ' + attributionHTML;
78
+ }
79
+ if (attributionHTML !== this.attributionHtml) {
80
+ const customAttribution = (this.attributionHtml = attributionHTML);
81
+ this.removeAttribution();
82
+ this.attributionControl = new maplibre.AttributionControl({ compact: false, customAttribution });
83
+ this.map.addControl(this.attributionControl, 'bottom-right');
84
+ }
85
+ this.filteredRecords = filtered;
86
+ };
87
+ this.map = map;
88
+ map.on('load', this.resetAttribution);
89
+ map.on('move', this.updateAttribution);
90
+ Config.map.on('tileMatrix', this.resetAttribution);
91
+ Config.map.on('layer', this.resetAttribution);
92
+ }
93
+ /**
94
+ * Only update attributions at most every 200ms
95
+ */
96
+ scheduleRender() {
97
+ var _a;
98
+ if (this._scheduled != null || this._raf !== 0)
99
+ return;
100
+ if (this.map.getZoom() === this.zoom) {
101
+ const bounds = this.map.getBounds();
102
+ if (bounds === this.bounds)
103
+ return;
104
+ }
105
+ this.zoom = (_a = this.map.getZoom()) !== null && _a !== void 0 ? _a : 0;
106
+ this.bounds = this.map.getBounds();
107
+ this._scheduled = setTimeout(() => {
108
+ this._scheduled = undefined;
109
+ this._raf = requestAnimationFrame(this.renderAttribution);
110
+ }, 200);
111
+ }
112
+ removeAttribution() {
113
+ if (this.attributionControl == null)
114
+ return;
115
+ this.map.removeControl(this.attributionControl);
116
+ this.attributionControl = null;
117
+ }
118
+ /**
119
+ * Covert Mapbox Bounds to tileMatrix BBox
120
+ */
121
+ mapboxBoundToBbox(bounds, tileMatrix) {
122
+ const swLocation = { lon: bounds.getWest(), lat: bounds.getSouth(), zoom: this.zoom };
123
+ const neLocation = { lon: bounds.getEast(), lat: bounds.getNorth(), zoom: this.zoom };
124
+ const swCoord = locationTransform(swLocation, GoogleTms, tileMatrix);
125
+ const neCoord = locationTransform(neLocation, GoogleTms, tileMatrix);
126
+ const bbox = [swCoord.lon, swCoord.lat, neCoord.lon, neCoord.lat];
127
+ return bbox;
128
+ }
129
+ /**
130
+ * Add attribution for vector map
131
+ */
132
+ vectorAttribution() {
133
+ this.removeAttribution();
134
+ this.attributionControl = new maplibre.AttributionControl({ compact: false });
135
+ this.map.addControl(this.attributionControl, 'bottom-right');
136
+ }
137
+ }
@@ -0,0 +1,14 @@
1
+ /// <reference types="node" />
2
+ import { Component, ComponentChild } from 'preact';
3
+ export interface CopyableProps {
4
+ header: string;
5
+ value: string;
6
+ }
7
+ export declare class Copyable extends Component<CopyableProps, {
8
+ copied: boolean;
9
+ }> {
10
+ render(): ComponentChild;
11
+ _copyTimeout: null | NodeJS.Timeout;
12
+ copy: () => void;
13
+ }
14
+ //# sourceMappingURL=copyable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"copyable.d.ts","sourceRoot":"","sources":["../../src/components/copyable.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAInD,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACf;AAED,qBAAa,QAAS,SAAQ,SAAS,CAAC,aAAa,EAAE;IAAE,MAAM,EAAE,OAAO,CAAA;CAAE,CAAC;IACzE,MAAM,IAAI,cAAc;IAcxB,YAAY,EAAE,IAAI,GAAG,MAAM,CAAC,OAAO,CAAQ;IAC3C,IAAI,QAAO,IAAI,CAWb;CACH"}
@@ -0,0 +1,26 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
2
+ import { Component } from 'preact';
3
+ import clsx from 'clsx';
4
+ import { Config, gaEvent } from '../config.js';
5
+ export class Copyable extends Component {
6
+ constructor() {
7
+ super(...arguments);
8
+ this._copyTimeout = null;
9
+ this.copy = () => {
10
+ /**
11
+ * Create a readablish name for the copy event
12
+ * @example `copy:topographic::basic:tilejson`
13
+ * @example `copy:aerial:wmts:nztm2000quad`
14
+ */
15
+ gaEvent("Ui" /* Ui */, 'copy:' + Config.map.layerKey + ':' + this.props.header.replace(/ /g, '').toLowerCase());
16
+ navigator.clipboard.writeText(this.props.value);
17
+ this.setState({ copied: true });
18
+ if (this._copyTimeout != null)
19
+ clearTimeout(this._copyTimeout);
20
+ this._copyTimeout = setTimeout(() => this.setState({ copied: false }), 1000);
21
+ };
22
+ }
23
+ render() {
24
+ return (_jsxs("div", { class: "LuiDeprecatedForms", children: [_jsx("label", { children: this.props.header }), _jsxs("div", { class: clsx({ 'lui-menu-label': true, 'menu-copyable': true, 'menu-copyable-copied': this.state.copied }), children: [_jsx("button", { class: "menu-copyable-icon-button", title: "Copy", onClick: this.copy, children: _jsx("i", { class: "material-icons-round", children: this.state.copied ? 'check' : 'content_copy' }) }), _jsx("input", { value: this.props.value, readonly: true })] })] }));
25
+ }
26
+ }
@@ -0,0 +1,34 @@
1
+ import maplibre, { Style } from 'maplibre-gl';
2
+ import { Component, ComponentChild } from 'preact';
3
+ export declare class Debug extends Component<{
4
+ map: maplibre.Map;
5
+ }, {
6
+ lastFeatureId: string | number | undefined;
7
+ lastFeatureName: string | undefined;
8
+ }> {
9
+ componentDidMount(): void;
10
+ waitForMap: () => void;
11
+ updateFromConfig(): void;
12
+ render(): ComponentChild;
13
+ renderPurple(): ComponentChild | null;
14
+ renderSourceToggle(): ComponentChild;
15
+ /** Show the source bounding box ont he map */
16
+ toggleSource: (e: Event) => void;
17
+ trackMouseMove(layerId: string): void;
18
+ setSourceShown(isShown: boolean): void;
19
+ _layerLoading: Map<string, Promise<void>>;
20
+ loadSourceLayer(layerId: string): Promise<void>;
21
+ _loadSourceLayer(layerId: string): Promise<void>;
22
+ renderSliders(): ComponentChild | null;
23
+ _styleJson: Promise<Style> | null;
24
+ get styleJson(): Promise<Style>;
25
+ adjustTopographic: (e: Event) => void;
26
+ adjustVector(value: number): Promise<void>;
27
+ adjustOsm: (e: Event) => void;
28
+ adjustLinzAerial: (e: Event) => void;
29
+ adjustRaster(rasterId: 'osm' | 'linz-aerial', range: number): void;
30
+ togglePurple: (e: Event) => void;
31
+ setPurple(isPurple: boolean): void;
32
+ }
33
+ export declare function getTileServerUrl(tileServer: 'osm' | 'linz-aerial'): string;
34
+ //# sourceMappingURL=debug.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["../../src/components/debug.tsx"],"names":[],"mappings":"AAEA,OAAO,QAAQ,EAAE,EAAY,KAAK,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,cAAc,EAAY,MAAM,QAAQ,CAAC;AAuB7D,qBAAa,KAAM,SAAQ,SAAS,CAClC;IAAE,GAAG,EAAE,QAAQ,CAAC,GAAG,CAAA;CAAE,EACrB;IAAE,aAAa,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IAAC,eAAe,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CACpF;IACC,iBAAiB,IAAI,IAAI;IAIzB,UAAU,QAAO,IAAI,CA2BnB;IAEF,gBAAgB,IAAI,IAAI;IAQxB,MAAM,IAAI,cAAc;IAuBxB,YAAY,IAAI,cAAc,GAAG,IAAI;IAcrC,kBAAkB,IAAI,cAAc;IAoBpC,8CAA8C;IAC9C,YAAY,MAAO,KAAK,KAAG,IAAI,CAI7B;IAEF,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IA0BrC,cAAc,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IA2CtC,aAAa,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAa;IACtD,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IASzC,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAsBtD,aAAa,IAAI,cAAc,GAAG,IAAI;IA+BtC,UAAU,EAAE,OAAO,CAAC,KAAK,CAAC,GAAG,IAAI,CAAQ;IACzC,IAAI,SAAS,IAAI,OAAO,CAAC,KAAK,CAAC,CAO9B;IAED,iBAAiB,MAAO,KAAK,KAAG,IAAI,CAGlC;IAEI,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA0DhD,SAAS,MAAO,KAAK,KAAG,IAAI,CAE1B;IACF,gBAAgB,MAAO,KAAK,KAAG,IAAI,CAEjC;IAEF,YAAY,CAAC,QAAQ,EAAE,KAAK,GAAG,aAAa,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAmClE,YAAY,MAAO,KAAK,KAAG,IAAI,CAG7B;IAEF,SAAS,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI;CAKnC;AAED,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,KAAK,GAAG,aAAa,GAAG,MAAM,CAO1E"}