@maptiler/geocoding-control 1.4.2-dev.3 → 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.
Files changed (52) hide show
  1. package/MapLibreBasedGeocodingControl.d.ts +70 -35
  2. package/leaflet-controller.d.ts +1 -1
  3. package/leaflet-controller.js +407 -398
  4. package/leaflet-controller.js.map +1 -1
  5. package/leaflet-controller.umd.js +3 -3
  6. package/leaflet-controller.umd.js.map +1 -1
  7. package/leaflet.d.ts +52 -16
  8. package/leaflet.js +654 -638
  9. package/leaflet.js.map +1 -1
  10. package/leaflet.umd.js +3 -3
  11. package/leaflet.umd.js.map +1 -1
  12. package/maplibregl-controller.d.ts +7 -7
  13. package/maplibregl-controller.js +421 -413
  14. package/maplibregl-controller.js.map +1 -1
  15. package/maplibregl-controller.umd.js +3 -3
  16. package/maplibregl-controller.umd.js.map +1 -1
  17. package/maplibregl.d.ts +29 -5
  18. package/maplibregl.js +1352 -1346
  19. package/maplibregl.js.map +1 -1
  20. package/maplibregl.umd.js +3 -3
  21. package/maplibregl.umd.js.map +1 -1
  22. package/maptilersdk.d.ts +29 -5
  23. package/maptilersdk.js +1315 -1303
  24. package/maptilersdk.js.map +1 -1
  25. package/maptilersdk.umd.js +3 -3
  26. package/maptilersdk.umd.js.map +1 -1
  27. package/openlayers.js +1 -1
  28. package/openlayers.js.map +1 -1
  29. package/openlayers.umd.js +1 -1
  30. package/openlayers.umd.js.map +1 -1
  31. package/package.json +5 -5
  32. package/react.js +1 -1
  33. package/react.js.map +1 -1
  34. package/react.umd.js +1 -1
  35. package/react.umd.js.map +1 -1
  36. package/svelte/GeocodingControl.svelte +1 -1
  37. package/svelte/MapLibreBasedGeocodingControl.d.ts +70 -35
  38. package/svelte/MapLibreBasedGeocodingControl.js +69 -66
  39. package/svelte/leaflet-controller.d.ts +1 -1
  40. package/svelte/leaflet-controller.js +47 -24
  41. package/svelte/leaflet.d.ts +52 -16
  42. package/svelte/leaflet.js +14 -2
  43. package/svelte/maplibregl-controller.d.ts +7 -7
  44. package/svelte/maplibregl-controller.js +55 -34
  45. package/svelte/maplibregl.d.ts +29 -5
  46. package/svelte/maplibregl.js +3 -8
  47. package/svelte/maptilersdk.d.ts +29 -5
  48. package/svelte/maptilersdk.js +15 -18
  49. package/vanilla.js +1 -1
  50. package/vanilla.js.map +1 -1
  51. package/vanilla.umd.js +1 -1
  52. package/vanilla.umd.js.map +1 -1
@@ -3,7 +3,7 @@ import union from "@turf/union";
3
3
  import MarkerIcon from "./MarkerIcon.svelte";
4
4
  import { setMask } from "./mask";
5
5
  const emptyGeojson = featureCollection([]);
6
- export function createMapLibreGlMapController(map, maplibregl, marker = true, showResultMarkers = true, flyToOptions = {}, fitBoundsOptions = {}, fullGeometryStyle = {
6
+ const defaultGeometryStyle = {
7
7
  fill: {
8
8
  paint: {
9
9
  "fill-color": "#000",
@@ -22,31 +22,37 @@ export function createMapLibreGlMapController(map, maplibregl, marker = true, sh
22
22
  },
23
23
  filter: ["!", ["has", "isMask"]],
24
24
  },
25
- }) {
25
+ };
26
+ export function createMapLibreGlMapController(map, maplibregl, marker = true, showResultMarkers = true, flyToOptions = {}, fitBoundsOptions = {}, fullGeometryStyle = defaultGeometryStyle) {
26
27
  let eventHandler;
27
28
  const markers = [];
28
29
  let selectedMarker;
29
30
  let reverseMarker;
30
31
  let savedData; // used to restore features on style switch
31
32
  function addFullGeometryLayer() {
33
+ const effFullGeometryStyle = !fullGeometryStyle
34
+ ? undefined
35
+ : fullGeometryStyle === true
36
+ ? defaultGeometryStyle
37
+ : fullGeometryStyle;
32
38
  if (!map.getSource("full-geom") &&
33
- (fullGeometryStyle?.fill || fullGeometryStyle?.line)) {
39
+ (effFullGeometryStyle?.fill || effFullGeometryStyle?.line)) {
34
40
  map.addSource("full-geom", {
35
41
  type: "geojson",
36
42
  data: emptyGeojson,
37
43
  });
38
44
  }
39
- if (!map.getLayer("full-geom-fill") && fullGeometryStyle?.fill) {
45
+ if (!map.getLayer("full-geom-fill") && effFullGeometryStyle?.fill) {
40
46
  map.addLayer({
41
- ...fullGeometryStyle?.fill,
47
+ ...effFullGeometryStyle?.fill,
42
48
  id: "full-geom-fill",
43
49
  type: "fill",
44
50
  source: "full-geom",
45
51
  });
46
52
  }
47
- if (!map.getLayer("full-geom-line") && fullGeometryStyle?.line) {
53
+ if (!map.getLayer("full-geom-line") && effFullGeometryStyle?.line) {
48
54
  map.addLayer({
49
- ...fullGeometryStyle?.line,
55
+ ...effFullGeometryStyle?.line,
50
56
  id: "full-geom-line",
51
57
  type: "line",
52
58
  source: "full-geom",
@@ -131,18 +137,20 @@ export function createMapLibreGlMapController(map, maplibregl, marker = true, sh
131
137
  }
132
138
  }
133
139
  else if (coordinates) {
134
- reverseMarker = (typeof marker === "object"
135
- ? new maplibregl.Marker(marker)
136
- : createMarker())
137
- .setLngLat(coordinates)
138
- .addTo(map);
139
- reverseMarker.getElement().classList.add("marker-reverse");
140
+ if (marker instanceof Function) {
141
+ reverseMarker = marker(map) ?? undefined;
142
+ }
143
+ else {
144
+ reverseMarker = (typeof marker === "object"
145
+ ? new maplibregl.Marker(marker)
146
+ : createMarker())
147
+ .setLngLat(coordinates)
148
+ .addTo(map);
149
+ reverseMarker.getElement().classList.add("marker-reverse");
150
+ }
140
151
  }
141
152
  },
142
153
  setMarkers(markedFeatures, picked) {
143
- if (!marker) {
144
- return;
145
- }
146
154
  for (const marker of markers) {
147
155
  marker.remove();
148
156
  }
@@ -190,12 +198,16 @@ export function createMapLibreGlMapController(map, maplibregl, marker = true, sh
190
198
  setData(picked);
191
199
  return; // no pin for (multi)linestrings
192
200
  }
193
- if (marker) {
194
- markers.push((typeof marker === "object"
201
+ if (marker instanceof Function) {
202
+ const m = marker(map, picked);
203
+ if (m) {
204
+ markers.push(m);
205
+ }
206
+ }
207
+ else if (marker) {
208
+ markers.push(typeof marker === "object"
195
209
  ? new maplibregl.Marker(marker)
196
- : createMarker())
197
- .setLngLat(picked.center)
198
- .addTo(map));
210
+ : createMarker().setLngLat(picked.center).addTo(map));
199
211
  }
200
212
  }
201
213
  if (showResultMarkers) {
@@ -203,19 +215,28 @@ export function createMapLibreGlMapController(map, maplibregl, marker = true, sh
203
215
  if (feature === picked) {
204
216
  continue;
205
217
  }
206
- const marker = (typeof showResultMarkers === "object"
207
- ? new maplibregl.Marker(showResultMarkers)
208
- : createMarker(true))
209
- .setLngLat(feature.center)
210
- .setPopup(new maplibregl.Popup({
211
- offset: [1, -27],
212
- closeButton: false,
213
- closeOnMove: true,
214
- className: "maptiler-gc-popup",
215
- }).setText(feature.place_type[0] === "reverse"
216
- ? feature.place_name
217
- : feature.place_name.replace(/,.*/, "")))
218
- .addTo(map);
218
+ let marker;
219
+ if (showResultMarkers instanceof Function) {
220
+ marker = showResultMarkers(map, feature);
221
+ if (!marker) {
222
+ continue;
223
+ }
224
+ }
225
+ else {
226
+ marker = (typeof showResultMarkers === "object"
227
+ ? new maplibregl.Marker(showResultMarkers)
228
+ : createMarker(true))
229
+ .setLngLat(feature.center)
230
+ .setPopup(new maplibregl.Popup({
231
+ offset: [1, -27],
232
+ closeButton: false,
233
+ closeOnMove: true,
234
+ className: "maptiler-gc-popup",
235
+ }).setText(feature.place_type[0] === "reverse"
236
+ ? feature.place_name
237
+ : feature.place_name.replace(/,.*/, "")))
238
+ .addTo(map);
239
+ }
219
240
  const element = marker.getElement();
220
241
  element.addEventListener("click", (e) => {
221
242
  e.stopPropagation();
@@ -1,7 +1,6 @@
1
1
  import type { Map } from "maplibre-gl";
2
2
  import * as maplibregl from "maplibre-gl";
3
- import type GeocodingControlComponent from "./GeocodingControl.svelte";
4
- import { MapLibreBasedGeocodingControl, type MapLibreBaseControlOptions, type Props } from "./MapLibreBasedGeocodingControl";
3
+ import { type MapLibreBaseControlOptions } from "./MapLibreBasedGeocodingControl";
5
4
  export { createMapLibreGlMapController } from "./maplibregl-controller";
6
5
  type Options = MapLibreBaseControlOptions & {
7
6
  /**
@@ -9,8 +8,33 @@ type Options = MapLibreBaseControlOptions & {
9
8
  */
10
9
  apiKey: string;
11
10
  };
12
- export declare class GeocodingControl extends MapLibreBasedGeocodingControl<Options> implements maplibregl.IControl {
13
- getMapLibreGl(): typeof maplibregl;
11
+ declare const Base: {
12
+ new <T extends MapLibreBaseControlOptions>(options?: T): {
13
+ "__#1@#gc"?: import("./GeocodingControl.svelte").default;
14
+ "__#1@#options": T;
15
+ onAddInt(map: Map): HTMLElement;
16
+ setOptions(options: T): void;
17
+ setQuery(value: string, submit?: boolean): void;
18
+ clearMap(): void;
19
+ clearList(): void;
20
+ setReverseMode(value: boolean): void;
21
+ focus(): void;
22
+ blur(): void;
23
+ onRemove(): void;
24
+ _listeners: maplibregl.Listeners;
25
+ _oneTimeListeners: maplibregl.Listeners;
26
+ _eventedParent: maplibregl.Evented;
27
+ _eventedParentData: any | (() => any);
28
+ on(type: string, listener: maplibregl.Listener): any;
29
+ off(type: string, listener: maplibregl.Listener): any;
30
+ once(type: string, listener?: maplibregl.Listener): Promise<any> | any;
31
+ fire(event: {
32
+ readonly type: string;
33
+ } | string, properties?: any): any;
34
+ listens(type: string): boolean;
35
+ setEventedParent(parent?: maplibregl.Evented | null, data?: any | (() => any)): any;
36
+ };
37
+ };
38
+ export declare class GeocodingControl extends Base<Options> implements maplibregl.IControl {
14
39
  onAdd(map: Map): HTMLElement;
15
- getExtraProps(): Partial<Props<GeocodingControlComponent>>;
16
40
  }
@@ -1,14 +1,9 @@
1
1
  import * as maplibregl from "maplibre-gl";
2
- import { MapLibreBasedGeocodingControl, } from "./MapLibreBasedGeocodingControl";
2
+ import { crateBaseClass, } from "./MapLibreBasedGeocodingControl";
3
3
  export { createMapLibreGlMapController } from "./maplibregl-controller";
4
- export class GeocodingControl extends MapLibreBasedGeocodingControl {
5
- getMapLibreGl() {
6
- return maplibregl;
7
- }
4
+ const Base = crateBaseClass(maplibregl.Evented, maplibregl);
5
+ export class GeocodingControl extends Base {
8
6
  onAdd(map) {
9
7
  return super.onAddInt(map);
10
8
  }
11
- getExtraProps() {
12
- return {};
13
- }
14
9
  }
@@ -1,11 +1,35 @@
1
1
  import * as maptilersdk from "@maptiler/sdk";
2
2
  import type * as maplibregl from "maplibre-gl";
3
3
  import type { Map } from "maplibre-gl";
4
- import type GeocodingControlComponent from "./GeocodingControl.svelte";
5
- import { MapLibreBasedGeocodingControl, type MapLibreBaseControlOptions, type Props } from "./MapLibreBasedGeocodingControl";
4
+ import { type MapLibreBaseControlOptions } from "./MapLibreBasedGeocodingControl";
6
5
  export { createMapLibreGlMapController } from "./maplibregl-controller";
7
- export declare class GeocodingControl extends MapLibreBasedGeocodingControl<MapLibreBaseControlOptions> implements maptilersdk.IControl {
8
- getMapLibreGl(): typeof maplibregl;
6
+ declare const Base: {
7
+ new <T extends MapLibreBaseControlOptions>(options?: T): {
8
+ "__#1@#gc"?: import("./GeocodingControl.svelte").default;
9
+ "__#1@#options": T;
10
+ onAddInt(map: Map): HTMLElement;
11
+ setOptions(options: T): void;
12
+ setQuery(value: string, submit?: boolean): void;
13
+ clearMap(): void;
14
+ clearList(): void;
15
+ setReverseMode(value: boolean): void;
16
+ focus(): void;
17
+ blur(): void;
18
+ onRemove(): void;
19
+ _listeners: maptilersdk.Listeners;
20
+ _oneTimeListeners: maptilersdk.Listeners;
21
+ _eventedParent: maplibregl.Evented;
22
+ _eventedParentData: any | (() => any);
23
+ on(type: string, listener: maptilersdk.Listener): any;
24
+ off(type: string, listener: maptilersdk.Listener): any;
25
+ once(type: string, listener?: maptilersdk.Listener): Promise<any> | any;
26
+ fire(event: {
27
+ readonly type: string;
28
+ } | string, properties?: any): any;
29
+ listens(type: string): boolean;
30
+ setEventedParent(parent?: maplibregl.Evented | null, data?: any | (() => any)): any;
31
+ };
32
+ };
33
+ export declare class GeocodingControl extends Base<MapLibreBaseControlOptions> implements maptilersdk.IControl {
9
34
  onAdd(map: maptilersdk.Map): HTMLElement;
10
- getExtraProps(map: Map, div: HTMLElement): Partial<Props<GeocodingControlComponent>>;
11
35
  }
@@ -1,25 +1,22 @@
1
1
  import * as maptilersdk from "@maptiler/sdk";
2
- import { MapLibreBasedGeocodingControl, } from "./MapLibreBasedGeocodingControl";
2
+ import { crateBaseClass, } from "./MapLibreBasedGeocodingControl";
3
3
  export { createMapLibreGlMapController } from "./maplibregl-controller";
4
- export class GeocodingControl extends MapLibreBasedGeocodingControl {
5
- getMapLibreGl() {
6
- return maptilersdk;
4
+ const Base = crateBaseClass(maptilersdk.Evented, maptilersdk, (map, div) => {
5
+ const sdkConfig = {};
6
+ if (!("getSdkConfig" in map && typeof map.getSdkConfig === "function")) {
7
+ throw new Error("MapTiler SDK not detected");
7
8
  }
9
+ const { primaryLanguage, apiKey } = map.getSdkConfig();
10
+ sdkConfig.apiKey = apiKey;
11
+ const match = /^([a-z]{2})($|_|-)/.exec(primaryLanguage);
12
+ if (match) {
13
+ sdkConfig.language = match[1];
14
+ }
15
+ div.className += " maptiler-ctrl";
16
+ return sdkConfig;
17
+ });
18
+ export class GeocodingControl extends Base {
8
19
  onAdd(map) {
9
20
  return super.onAddInt(map);
10
21
  }
11
- getExtraProps(map, div) {
12
- const sdkConfig = {};
13
- if (!("getSdkConfig" in map && typeof map.getSdkConfig === "function")) {
14
- throw new Error("MapTiler SDK not detected");
15
- }
16
- const { primaryLanguage, apiKey } = map.getSdkConfig();
17
- sdkConfig.apiKey = apiKey;
18
- const match = /^([a-z]{2})($|_|-)/.exec(primaryLanguage);
19
- if (match) {
20
- sdkConfig.language = match[1];
21
- }
22
- div.className += " maptiler-ctrl";
23
- return sdkConfig;
24
- }
25
22
  }
package/vanilla.js CHANGED
@@ -2058,7 +2058,7 @@ function mn(i, e, t) {
2058
2058
  "poi.restaurant": 18,
2059
2059
  "poi.aerodrome": 13
2060
2060
  };
2061
- let { class: r = void 0 } = e, { apiKey: d } = e, { bbox: u = void 0 } = e, { clearButtonTitle: f = "clear" } = e, { clearOnBlur: h = !1 } = e, { collapsed: v = !1 } = e, { country: _ = void 0 } = e, { debounceSearch: w = 200 } = e, { enableReverse: W = !1 } = e, { errorMessage: y = "Something went wrong…" } = e, { filter: E = () => !0 } = e, { flyTo: C = !0 } = e, { fuzzyMatch: O = !0 } = e, { language: p = void 0 } = e, { limit: q = void 0 } = e, { mapController: b = void 0 } = e, { minLength: g = 2 } = e, { noResultsMessage: m = "Oops! Looks like you're trying to predict something that's not quite right. We can't seem to find what you're looking for. Maybe try double-checking your spelling or try a different search term. Keep on typing - we'll do our best to get you where you need to go!" } = e, { placeholder: k = "Search" } = e, { proximity: H = [{ type: "server-geolocation" }] } = e, { reverseActive: X = W === "always" } = e, { reverseButtonTitle: $ = "toggle reverse geocoding" } = e, { searchValue: j = "" } = e, { showFullGeometry: L = !0 } = e, { showPlaceType: F = "ifNeeded" } = e, { showResultsWhileTyping: ee = !0 } = e, { selectFirst: re = !0 } = e, { flyToSelected: Pe = !1 } = e, { markerOnSelected: De = !0 } = e, { types: ge = void 0 } = e, { exhaustiveReverseGeocoding: Ze = !1 } = e, { excludeTypes: Re = !1 } = e, { zoom: ye = c } = e, { maxZoom: Ue = void 0 } = e, { apiUrl: Ge = "https://api.maptiler.com/geocoding" } = e, { fetchParameters: qe = {} } = e, { iconsBaseUrl: st = "https://cdn.maptiler.com/maptiler-geocoding-control/v1.4.2-dev.3/icons/" } = e, { adjustUrlQuery: Qe = () => {
2061
+ let { class: r = void 0 } = e, { apiKey: d } = e, { bbox: u = void 0 } = e, { clearButtonTitle: f = "clear" } = e, { clearOnBlur: h = !1 } = e, { collapsed: v = !1 } = e, { country: _ = void 0 } = e, { debounceSearch: w = 200 } = e, { enableReverse: W = !1 } = e, { errorMessage: y = "Something went wrong…" } = e, { filter: E = () => !0 } = e, { flyTo: C = !0 } = e, { fuzzyMatch: O = !0 } = e, { language: p = void 0 } = e, { limit: q = void 0 } = e, { mapController: b = void 0 } = e, { minLength: g = 2 } = e, { noResultsMessage: m = "Oops! Looks like you're trying to predict something that's not quite right. We can't seem to find what you're looking for. Maybe try double-checking your spelling or try a different search term. Keep on typing - we'll do our best to get you where you need to go!" } = e, { placeholder: k = "Search" } = e, { proximity: H = [{ type: "server-geolocation" }] } = e, { reverseActive: X = W === "always" } = e, { reverseButtonTitle: $ = "toggle reverse geocoding" } = e, { searchValue: j = "" } = e, { showFullGeometry: L = !0 } = e, { showPlaceType: F = "ifNeeded" } = e, { showResultsWhileTyping: ee = !0 } = e, { selectFirst: re = !0 } = e, { flyToSelected: Pe = !1 } = e, { markerOnSelected: De = !0 } = e, { types: ge = void 0 } = e, { exhaustiveReverseGeocoding: Ze = !1 } = e, { excludeTypes: Re = !1 } = e, { zoom: ye = c } = e, { maxZoom: Ue = void 0 } = e, { apiUrl: Ge = "https://api.maptiler.com/geocoding" } = e, { fetchParameters: qe = {} } = e, { iconsBaseUrl: st = "https://cdn.maptiler.com/maptiler-geocoding-control/v2.0.0/icons/" } = e, { adjustUrlQuery: Qe = () => {
2062
2062
  } } = e;
2063
2063
  function Ht() {
2064
2064
  te.focus();