-
+
{% svgIcon 'search.svg' %}
Promise
;
+let debouncedAutocomplete: typeof autocompleteAddress;
let inputElement: HTMLInputElement;
let suggestionsList: HTMLUListElement;
let clearSearchBtn: HTMLButtonElement;
-let markerAddress: woosmap.map.Marker;
+let markerAddress: woosmap.map.marker.AdvancedMarkerElement;
function init(): void {
if (inputElement && suggestionsList) {
@@ -34,15 +32,14 @@ function init(): void {
debouncedAutocomplete = debouncePromise(autocompleteAddress, 0);
}
-function initMap(): void {
- map = new woosmap.map.Map(document.getElementById("map") as HTMLElement, {
- center: {
- lat: 48.8534,
- lng: 2.3488,
- },
+async function initMap(): Promise {
+ await woosmap.map.importLibrary("maps");
+ await woosmap.map.importLibrary("marker");
+
+ map = (document.getElementById("map") as woosmap.map.MapElement).innerMap;
+ map.setOptions({
disableDefaultUI: true,
gestureHandling: "greedy",
- zoom: 5,
styles: [
{
featureType: "poi",
@@ -50,6 +47,13 @@ function initMap(): void {
},
],
});
+ map.moveCamera({
+ center: {
+ lat: 48.8534,
+ lng: 2.3488,
+ },
+ zoom: 5,
+ });
}
function handleAutocomplete(): void {
@@ -172,15 +176,16 @@ function createAddressMarker(
markerAddress.setMap(null);
}
if (addressDetail && addressDetail.geometry) {
- markerAddress = new woosmap.map.Marker({
+ const { PinElement } = woosmap.map.marker;
+ const pin = new PinElement({
+ background: "#5588FF",
+ borderColor: "#3D6FE0",
+ glyphColor: "#FFFFFF",
+ });
+
+ markerAddress = new woosmap.map.marker.AdvancedMarkerElement({
position: addressDetail.geometry.location,
- icon: {
- url: "https://images.woosmap.com/marker.png",
- scaledSize: {
- height: 59,
- width: 37,
- },
- },
+ content: pin.element,
});
markerAddress.setMap(map);
panMap(addressDetail);
@@ -211,8 +216,7 @@ function panMap(addressDetail: woosmap.map.localities.LocalitiesDetailsResult) {
if (addressDetail.types[0] === "address") {
zoom = 18;
}
- map.setZoom(zoom);
- map.panTo(geometry.location);
+ map.moveCamera({ zoom, center: geometry.location });
}
}
@@ -260,17 +264,17 @@ function getLocalitiesDetails(
).then((response) => response.json());
}
-type DebouncePromiseFunction = (
+type DebouncePromiseFunction = (
...args: Args
) => Promise;
-function debouncePromise(
+function debouncePromise(
fn: (...args: Args) => Promise,
delay: number,
): DebouncePromiseFunction {
let timeoutId: ReturnType | null = null;
let latestResolve: ((value: T | PromiseLike) => void) | null = null;
- let latestReject: ((reason?: any) => void) | null = null;
+ let latestReject: ((reason?: unknown) => void) | null = null;
return function (...args: Args): Promise {
return new Promise((resolve, reject) => {
@@ -309,12 +313,7 @@ document.addEventListener("DOMContentLoaded", () => {
init();
});
-declare global {
- interface Window {
- initMap: () => void;
- }
-}
-window.initMap = initMap;
+initMap();
// [END woosmap_localities_api_details_postalcodes]
export {};
diff --git a/samples/localities-api-details-postalcodes/localities-api-details-postalcodes.json b/samples/localities-api-details-postalcodes/localities-api-details-postalcodes.json
index 6ea08756..f656821f 100644
--- a/samples/localities-api-details-postalcodes/localities-api-details-postalcodes.json
+++ b/samples/localities-api-details-postalcodes/localities-api-details-postalcodes.json
@@ -10,5 +10,7 @@
"size": 1,
"alias": "mode"
},
- "permalink": "samples/{{ page.fileSlug }}/{{mode}}/{% if mode == 'jsfiddle' %}demo{% else %}index{% endif %}.{{ page.outputFileExtension }}"
+ "permalink": "samples/{{ page.fileSlug }}/{{mode}}/{% if mode == 'jsfiddle' %}demo{% else %}index{% endif %}.{{ page.outputFileExtension }}",
+ "libraries": "marker",
+ "loaderShim": true
}
diff --git a/samples/localities-api-details/index.njk b/samples/localities-api-details/index.njk
index a8e5c97a..0e58dba7 100644
--- a/samples/localities-api-details/index.njk
+++ b/samples/localities-api-details/index.njk
@@ -10,7 +10,7 @@
{% block html %}
-
+
diff --git a/samples/localities-api-details/index.ts b/samples/localities-api-details/index.ts
index d099d552..49913b2c 100644
--- a/samples/localities-api-details/index.ts
+++ b/samples/localities-api-details/index.ts
@@ -2,26 +2,23 @@
const componentsRestriction: woosmap.map.localities.LocalitiesComponentRestrictions =
{ country: [] };
const woosmap_key = "YOUR_API_KEY";
-let debouncedAutocomplete: (
- ...args: any[]
-) => Promise
;
+let debouncedAutocomplete: typeof autocompleteAddress;
let inputElement: HTMLInputElement;
let suggestionsList: HTMLUListElement;
let clearSearchBtn: HTMLButtonElement;
let map: woosmap.map.Map;
-let markerAddress: woosmap.map.Marker;
+let markerAddress: woosmap.map.marker.AdvancedMarkerElement;
let detailsHTML: HTMLElement;
let addressDetailsContainer: HTMLElement;
-function initMap(): void {
- map = new woosmap.map.Map(document.getElementById("map") as HTMLElement, {
- center: {
- lat: 48.8534,
- lng: 2.3488,
- },
+async function initMap(): Promise {
+ await woosmap.map.importLibrary("maps");
+ await woosmap.map.importLibrary("marker");
+
+ map = (document.getElementById("map") as woosmap.map.MapElement).innerMap;
+ map.setOptions({
disableDefaultUI: true,
gestureHandling: "greedy",
- zoom: 5,
styles: [
{
featureType: "poi",
@@ -29,6 +26,13 @@ function initMap(): void {
},
],
});
+ map.moveCamera({
+ center: {
+ lat: 48.8534,
+ lng: 2.3488,
+ },
+ zoom: 5,
+ });
init();
manageCountrySelector();
}
@@ -40,15 +44,16 @@ function createAddressMarker(
markerAddress.setMap(null);
}
if (addressDetail && addressDetail.geometry) {
- markerAddress = new woosmap.map.Marker({
+ const { PinElement } = woosmap.map.marker;
+ const pin = new PinElement({
+ background: "#5588FF",
+ borderColor: "#3D6FE0",
+ glyphColor: "#FFFFFF",
+ });
+
+ markerAddress = new woosmap.map.marker.AdvancedMarkerElement({
position: addressDetail.geometry.location,
- icon: {
- url: "https://images.woosmap.com/marker.png",
- scaledSize: {
- height: 59,
- width: 37,
- },
- },
+ content: pin.element,
});
markerAddress.setMap(map);
panMap(addressDetail);
@@ -149,7 +154,7 @@ function handleAutocomplete(): void {
.map((country) => `country:${country}`)
.join("|");
if (input !== "") {
- debouncedAutocomplete(input, componentsArgs, woosmap_key)
+ debouncedAutocomplete(input, componentsArgs)
.then(({ localities }) => displaySuggestions(localities))
.catch((error) =>
console.error("Error autocomplete localities:", error),
@@ -189,7 +194,7 @@ function formatPredictionList(locality): string {
const prediction = locality;
const predictionClass = "no-viewpoint";
const matched_substrings = prediction.matched_substrings;
- let formatted_name = "";
+ let formatted_name: string;
if (
prediction.matched_substrings &&
prediction.matched_substrings.description
@@ -260,17 +265,17 @@ function buildQueryString(params: object) {
return queryStringParts.join("&");
}
-type DebouncePromiseFunction = (
+type DebouncePromiseFunction = (
...args: Args
) => Promise;
-function debouncePromise(
+function debouncePromise(
fn: (...args: Args) => Promise,
delay: number,
): DebouncePromiseFunction {
let timeoutId: ReturnType | null = null;
let latestResolve: ((value: T | PromiseLike) => void) | null = null;
- let latestReject: ((reason?: any) => void) | null = null;
+ let latestReject: ((reason?: unknown) => void) | null = null;
return function (...args: Args): Promise {
return new Promise((resolve, reject) => {
@@ -425,8 +430,7 @@ function panMap(addressDetail: woosmap.map.localities.LocalitiesDetailsResult) {
if (addressDetail.types[0] === "address") {
zoom = 18;
}
- map.setZoom(zoom);
- map.panTo(geometry.location);
+ map.moveCamera({ zoom, center: geometry.location });
}
}
@@ -442,12 +446,7 @@ function getLocalitiesDetails(
).then((response) => response.json());
}
-declare global {
- interface Window {
- initMap: () => void;
- }
-}
-window.initMap = initMap;
+initMap();
// [END woosmap_localities_api_details]
diff --git a/samples/localities-api-details/localities-api-details.json b/samples/localities-api-details/localities-api-details.json
index a68ed41a..de1d80b8 100644
--- a/samples/localities-api-details/localities-api-details.json
+++ b/samples/localities-api-details/localities-api-details.json
@@ -10,5 +10,7 @@
"size": 1,
"alias": "mode"
},
- "permalink": "samples/{{ page.fileSlug }}/{{mode}}/{% if mode == 'jsfiddle' %}demo{% else %}index{% endif %}.{{ page.outputFileExtension }}"
+ "permalink": "samples/{{ page.fileSlug }}/{{mode}}/{% if mode == 'jsfiddle' %}demo{% else %}index{% endif %}.{{ page.outputFileExtension }}",
+ "libraries": "marker",
+ "loaderShim": true
}
diff --git a/samples/localities-api-shape/index.njk b/samples/localities-api-shape/index.njk
index 8b2f31e0..c1be78f8 100644
--- a/samples/localities-api-shape/index.njk
+++ b/samples/localities-api-shape/index.njk
@@ -12,7 +12,7 @@
{% block html %}
-
+
diff --git a/samples/localities-api-shape/index.ts b/samples/localities-api-shape/index.ts
index e4833126..038438a1 100644
--- a/samples/localities-api-shape/index.ts
+++ b/samples/localities-api-shape/index.ts
@@ -2,27 +2,24 @@
const componentsRestriction: woosmap.map.localities.LocalitiesComponentRestrictions =
{ country: [] };
const woosmap_key = "YOUR_API_KEY";
-let debouncedAutocomplete: (
- ...args: any[]
-) => Promise
;
+let debouncedAutocomplete: typeof autocompleteAddress;
let inputElement: HTMLInputElement;
let suggestionsList: HTMLUListElement;
let clearSearchBtn: HTMLButtonElement;
let map: woosmap.map.Map;
-let markerAddress: woosmap.map.Marker;
+let markerAddress: woosmap.map.marker.AdvancedMarkerElement;
let detailsHTML: HTMLElement;
let addressDetailsContainer: HTMLElement;
let hasShape = false;
-function initMap(): void {
- map = new woosmap.map.Map(document.getElementById("map") as HTMLElement, {
- center: {
- lat: 48.8534,
- lng: 2.3488,
- },
+async function initMap(): Promise {
+ await woosmap.map.importLibrary("maps");
+ await woosmap.map.importLibrary("marker");
+
+ map = (document.getElementById("map") as woosmap.map.MapElement).innerMap;
+ map.setOptions({
disableDefaultUI: true,
gestureHandling: "greedy",
- zoom: 5,
styles: [
{
featureType: "poi",
@@ -30,15 +27,21 @@ function initMap(): void {
},
],
});
+ map.moveCamera({
+ center: {
+ lat: 48.8534,
+ lng: 2.3488,
+ },
+ zoom: 5,
+ });
init();
manageCountrySelector();
}
function createShape(result: woosmap.map.localities.LocalitiesDetailsResult) {
- // @ts-ignore TypeDef to be updated
if (result?.geometry?.shape) {
hasShape = true;
- // @ts-ignore TypeDef to be updated
+ // @ts-expect-error shape is typed as a Feature, but the API returns a bare geometry
map.data.addGeoJson({ type: "Feature", geometry: result.geometry.shape });
if (result.geometry.viewport) {
const bounds = {
@@ -58,15 +61,16 @@ function createAddressMarker(addressDetail) {
}
if (addressDetail?.geometry) {
const position = addressDetail.geometry.location;
- markerAddress = new woosmap.map.Marker({
+ const { PinElement } = woosmap.map.marker;
+ const pin = new PinElement({
+ background: "#5588FF",
+ borderColor: "#3D6FE0",
+ glyphColor: "#FFFFFF",
+ });
+
+ markerAddress = new woosmap.map.marker.AdvancedMarkerElement({
position: position,
- icon: {
- url: "https://images.woosmap.com/marker.png",
- scaledSize: {
- height: 59,
- width: 37,
- },
- },
+ content: pin.element,
});
markerAddress.setMap(map);
@@ -173,7 +177,7 @@ function handleAutocomplete(): void {
.map((country) => `country:${country}`)
.join("|");
if (input !== "") {
- debouncedAutocomplete(input, componentsArgs, woosmap_key)
+ debouncedAutocomplete(input, componentsArgs)
.then(({ localities }) => displaySuggestions(localities))
.catch((error) =>
console.error("Error autocomplete localities:", error),
@@ -213,7 +217,7 @@ function formatPredictionList(locality): string {
const prediction = locality;
const predictionClass = "no-viewpoint";
const matched_substrings = prediction.matched_substrings;
- let formatted_name = "";
+ let formatted_name: string;
if (
prediction.matched_substrings &&
prediction.matched_substrings.description
@@ -284,17 +288,17 @@ function buildQueryString(params: object) {
return queryStringParts.join("&");
}
-type DebouncePromiseFunction = (
+type DebouncePromiseFunction = (
...args: Args
) => Promise;
-function debouncePromise(
+function debouncePromise(
fn: (...args: Args) => Promise,
delay: number,
): DebouncePromiseFunction {
let timeoutId: ReturnType | null = null;
let latestResolve: ((value: T | PromiseLike) => void) | null = null;
- let latestReject: ((reason?: any) => void) | null = null;
+ let latestReject: ((reason?: unknown) => void) | null = null;
return function (...args: Args): Promise {
return new Promise((resolve, reject) => {
@@ -448,8 +452,7 @@ function panMap(addressDetail: woosmap.map.localities.LocalitiesDetailsResult) {
if (addressDetail.types[0] === "address") {
zoom = 18;
}
- map.setZoom(zoom);
- map.panTo(geometry.location);
+ map.moveCamera({ zoom, center: geometry.location });
}
}
@@ -466,12 +469,7 @@ function getLocalitiesDetails(
).then((response) => response.json());
}
-declare global {
- interface Window {
- initMap: () => void;
- }
-}
-window.initMap = initMap;
+initMap();
// [END woosmap_localities_api_shape]
diff --git a/samples/localities-api-shape/localities-api-shape.json b/samples/localities-api-shape/localities-api-shape.json
index 7aba6240..80478a4d 100644
--- a/samples/localities-api-shape/localities-api-shape.json
+++ b/samples/localities-api-shape/localities-api-shape.json
@@ -10,5 +10,7 @@
"size": 1,
"alias": "mode"
},
- "permalink": "samples/{{ page.fileSlug }}/{{mode}}/{% if mode == 'jsfiddle' %}demo{% else %}index{% endif %}.{{ page.outputFileExtension }}"
+ "permalink": "samples/{{ page.fileSlug }}/{{mode}}/{% if mode == 'jsfiddle' %}demo{% else %}index{% endif %}.{{ page.outputFileExtension }}",
+ "libraries": "marker",
+ "loaderShim": true
}
diff --git a/samples/localities-autocomplete/index.njk b/samples/localities-autocomplete/index.njk
index b71ca6e9..ba60a75d 100644
--- a/samples/localities-autocomplete/index.njk
+++ b/samples/localities-autocomplete/index.njk
@@ -16,7 +16,7 @@
-
+
{% endblock %}
diff --git a/samples/localities-autocomplete/index.ts b/samples/localities-autocomplete/index.ts
index 311bb479..ffeb5a37 100644
--- a/samples/localities-autocomplete/index.ts
+++ b/samples/localities-autocomplete/index.ts
@@ -1,21 +1,22 @@
// [START woosmap_localities_autocomplete]
let map: woosmap.map.Map;
-let marker: woosmap.map.Marker;
+let marker: woosmap.map.marker.AdvancedMarkerElement;
let infoWindow: woosmap.map.InfoWindow;
let localitiesService: woosmap.map.LocalitiesService;
let request: woosmap.map.localities.LocalitiesAutocompleteRequest;
-let debouncedLocalitiesAutocomplete: (...args: any[]) => Promise;
+let debouncedLocalitiesAutocomplete: woosmap.map.LocalitiesService["autocomplete"];
-function initMap(): void {
- map = new window.woosmap.map.Map(
- document.getElementById("map") as HTMLElement,
- {
+async function initMap(): Promise {
+ await woosmap.map.importLibrary("maps");
+ await woosmap.map.importLibrary("marker");
+
+ map = (document.getElementById("map") as woosmap.map.MapElement).innerMap;
+ map.moveCamera({
center: { lat: 51.50940214, lng: -0.133012 },
zoom: 4,
- },
- );
+ });
infoWindow = new woosmap.map.InfoWindow({});
- localitiesService = new window.woosmap.map.LocalitiesService();
+ localitiesService = new woosmap.map.LocalitiesService();
request = {
input: "",
@@ -90,19 +91,20 @@ function displayLocality(
infoWindow.close();
}
if (locality?.geometry) {
- marker = new woosmap.map.Marker({
+ const { PinElement } = woosmap.map.marker;
+ const pin = new PinElement({
+ background: "#5588FF",
+ borderColor: "#3D6FE0",
+ glyphColor: "#FFFFFF",
+ });
+
+ marker = new woosmap.map.marker.AdvancedMarkerElement({
position: locality.geometry.location,
- icon: {
- url: "https://images.woosmap.com/marker.png",
- scaledSize: {
- height: 50,
- width: 32,
- },
- },
+ content: pin.element,
});
marker.setMap(map);
infoWindow.setContent(`${locality.formatted_address}`);
- infoWindow.open(map, marker);
+ infoWindow.open({map, anchor: marker});
map.flyTo({ center: locality.geometry.location, zoom: 14 });
}
}
@@ -143,19 +145,19 @@ document.addEventListener("click", (event) => {
});
// [START woosmap_localities_autocomplete_debounce_promise]
-let PRESERVE_COMMENT_ABOVE; // force tsc to maintain the comment above eslint-disable-line
+let PRESERVE_COMMENT_ABOVE; // eslint-disable-line no-unassigned-vars -- force tsc to maintain the comment above
-type DebouncePromiseFunction = (
+type DebouncePromiseFunction = (
...args: Args
) => Promise;
-function debouncePromise(
+function debouncePromise(
fn: (...args: Args) => Promise,
delay: number,
): DebouncePromiseFunction {
let timeoutId: ReturnType | null = null;
let latestResolve: ((value: T | PromiseLike) => void) | null = null;
- let latestReject: ((reason?: any) => void) | null = null;
+ let latestReject: ((reason?: unknown) => void) | null = null;
return function (...args: Args): Promise {
return new Promise((resolve, reject) => {
@@ -182,14 +184,9 @@ function debouncePromise(
}
// [END woosmap_localities_autocomplete_debounce_promise] */
-PRESERVE_COMMENT_ABOVE; // force tsc to maintain the comment above eslint-disable-line
+PRESERVE_COMMENT_ABOVE; // eslint-disable-line @typescript-eslint/no-unused-expressions -- force tsc to maintain the comment above
-declare global {
- interface Window {
- initMap: () => void;
- }
-}
-window.initMap = initMap;
+initMap();
// [END woosmap_localities_autocomplete]
export {};
diff --git a/samples/localities-autocomplete/localities-autocomplete.json b/samples/localities-autocomplete/localities-autocomplete.json
index 0085c6e6..45ca3225 100644
--- a/samples/localities-autocomplete/localities-autocomplete.json
+++ b/samples/localities-autocomplete/localities-autocomplete.json
@@ -10,5 +10,7 @@
"size": 1,
"alias": "mode"
},
- "permalink": "samples/{{ page.fileSlug }}/{{mode}}/{% if mode == 'jsfiddle' %}demo{% else %}index{% endif %}.{{ page.outputFileExtension }}"
+ "permalink": "samples/{{ page.fileSlug }}/{{mode}}/{% if mode == 'jsfiddle' %}demo{% else %}index{% endif %}.{{ page.outputFileExtension }}",
+ "libraries": "marker",
+ "loaderShim": true
}
diff --git a/samples/localities-geocode/index.njk b/samples/localities-geocode/index.njk
index 917d06e4..c93154e3 100644
--- a/samples/localities-geocode/index.njk
+++ b/samples/localities-geocode/index.njk
@@ -39,7 +39,7 @@
-
+
{% endblock %}
diff --git a/samples/localities-geocode/index.ts b/samples/localities-geocode/index.ts
index 1a1c4f0a..476cb6ca 100644
--- a/samples/localities-geocode/index.ts
+++ b/samples/localities-geocode/index.ts
@@ -1,19 +1,20 @@
// [START woosmap_localities_geocode]
// Initialize and add the map
let map: woosmap.map.Map;
-let marker: woosmap.map.Marker;
+let marker: woosmap.map.marker.AdvancedMarkerElement;
let infoWindow: woosmap.map.InfoWindow;
let localitiesService: woosmap.map.LocalitiesService;
const request: woosmap.map.localities.LocalitiesGeocodeRequest = {};
-function initMap() {
- map = new window.woosmap.map.Map(
- document.getElementById("map") as HTMLElement,
- {
+async function initMap() {
+ await woosmap.map.importLibrary("maps");
+ await woosmap.map.importLibrary("marker");
+
+ map = (document.getElementById("map") as woosmap.map.MapElement).innerMap;
+ map.moveCamera({
center: { lat: 51.50940214, lng: -0.133012 },
zoom: 12,
- },
- );
+ });
infoWindow = new woosmap.map.InfoWindow({});
localitiesService = new woosmap.map.LocalitiesService();
map.addListener("click", (e) => {
@@ -79,19 +80,20 @@ function displayLocality(
}
if (locality?.geometry) {
- marker = new woosmap.map.Marker({
+ const { PinElement } = woosmap.map.marker;
+ const pin = new PinElement({
+ background: "#5588FF",
+ borderColor: "#3D6FE0",
+ glyphColor: "#FFFFFF",
+ });
+
+ marker = new woosmap.map.marker.AdvancedMarkerElement({
position: locality.geometry.location,
- icon: {
- url: "https://images.woosmap.com/marker.png",
- scaledSize: {
- height: 50,
- width: 32,
- },
- },
+ content: pin.element,
});
marker.setMap(map);
infoWindow.setContent(`
${locality.formatted_address}`);
- infoWindow.open(map, marker);
+ infoWindow.open({map, anchor: marker});
map.setCenter(locality.geometry.location);
renderResponse(locality);
}
@@ -211,12 +213,7 @@ function clearResponse() {
if (rawEl) rawEl.textContent = "";
}
-declare global {
- interface Window {
- initMap: () => void;
- }
-}
-window.initMap = initMap;
+initMap();
// [END woosmap_localities_geocode]
export {};
diff --git a/samples/localities-geocode/localities-geocode.json b/samples/localities-geocode/localities-geocode.json
index bb180d0c..314e3e12 100644
--- a/samples/localities-geocode/localities-geocode.json
+++ b/samples/localities-geocode/localities-geocode.json
@@ -10,5 +10,7 @@
"size": 1,
"alias": "mode"
},
- "permalink": "samples/{{ page.fileSlug }}/{{mode}}/{% if mode == 'jsfiddle' %}demo{% else %}index{% endif %}.{{ page.outputFileExtension }}"
+ "permalink": "samples/{{ page.fileSlug }}/{{mode}}/{% if mode == 'jsfiddle' %}demo{% else %}index{% endif %}.{{ page.outputFileExtension }}",
+ "libraries": "marker",
+ "loaderShim": true
}
diff --git a/samples/localities-js-api/index.ts b/samples/localities-js-api/index.ts
index db0a89c3..9d5506a7 100644
--- a/samples/localities-js-api/index.ts
+++ b/samples/localities-js-api/index.ts
@@ -1,7 +1,29 @@
// [START woosmap_localities_js_api]
const customDescription =
'postal_code:"{name} ({postal_town}) - {administrative_area_level_0}"';
-let localitiesAutocompleteService;
+// The Localities JS API ships no typings: describe the parts this sample uses.
+interface LocalitiesAutocompleteService {
+ autocomplete(
+ request: { input: string; custom_description: string },
+ onSuccess: (
+ response: woosmap.map.localities.LocalitiesAutocompleteResponse,
+ ) => void,
+ onError: (errorCode: number, errorText: string) => void,
+ debounceTime: number,
+ ): void;
+ getDetails(
+ publicId: string,
+ onSuccess: (result: woosmap.map.localities.LocalitiesPredictions) => void,
+ ): void;
+}
+
+interface LocalitiesApiGlobal {
+ localities: {
+ AutocompleteService: new (key: string) => LocalitiesAutocompleteService;
+ };
+}
+
+let localitiesAutocompleteService: LocalitiesAutocompleteService;
let inputElement: HTMLInputElement;
let suggestionsList: HTMLUListElement;
let clearSearchBtn: HTMLButtonElement;
@@ -27,8 +49,10 @@ function init(): void {
inputElement.focus();
});
- localitiesAutocompleteService =
- new window.woosmap.localities.AutocompleteService("YOUR_API_KEY");
+ const { localities } = woosmap as unknown as LocalitiesApiGlobal;
+ localitiesAutocompleteService = new localities.AutocompleteService(
+ "YOUR_API_KEY",
+ );
}
function handleAutocomplete(): void {
@@ -84,7 +108,7 @@ function formatPredictionList(locality): string {
const prediction = locality;
const predictionClass = "no-viewpoint";
const matched_substrings = prediction.matched_substrings;
- let formatted_name = "";
+ let formatted_name: string;
if (
prediction.matched_substrings &&
prediction.matched_substrings.description
@@ -145,16 +169,6 @@ document.addEventListener("DOMContentLoaded", () => {
init();
});
-declare global {
- interface Window {
- // currently, the localities JS API typings are not exported, so we use `any` here
- woosmap: {
- localities: {
- AutocompleteService: new (key: string) => any;
- };
- };
- }
-}
// [END woosmap_localities_js_api]
export {};
diff --git a/samples/localities-js-widget-custom-desc/index.ts b/samples/localities-js-widget-custom-desc/index.ts
index c690c087..a5381a4e 100644
--- a/samples/localities-js-widget-custom-desc/index.ts
+++ b/samples/localities-js-widget-custom-desc/index.ts
@@ -1,11 +1,23 @@
// [START woosmap_localities_js_widget_custom_desc]
+// The Localities JS Widget ships no typings: describe the parts this sample uses.
+interface LocalitiesWidget {
+ addListener(eventName: string, handler: () => void): void;
+ getSelectedSuggestionDetails(): unknown;
+}
+
+interface LocalitiesWidgetGlobal {
+ localities: {
+ Autocomplete: new (inputId: string, options: object) => LocalitiesWidget;
+ };
+}
+
function init(): void {
const responseElement = document.getElementById(
"response-container",
) as HTMLElement;
- // @ts-ignore
- const localitiesWidget = new window.woosmap.localities.Autocomplete(
+ const { localities } = woosmap as unknown as LocalitiesWidgetGlobal;
+ const localitiesWidget = new localities.Autocomplete(
"autocomplete-input",
{
minLength: 3,
@@ -29,17 +41,6 @@ document.addEventListener("DOMContentLoaded", () => {
init();
});
-declare global {
- interface Window {
- // currently, the localities JS Widget typings are not exported, so we use `any` here
- //@ts-ignore
- woosmap: {
- localities: {
- Autocomplete: new (inputId: string, customConfig: any) => any;
- };
- };
- }
-}
// [END woosmap_localities_js_widget_custom_desc]
export {};
diff --git a/samples/localities-js-widget/index.ts b/samples/localities-js-widget/index.ts
index 95f4f48c..31ae6b7d 100644
--- a/samples/localities-js-widget/index.ts
+++ b/samples/localities-js-widget/index.ts
@@ -1,11 +1,23 @@
// [START woosmap_localities_js_widget]
+// The Localities JS Widget ships no typings: describe the parts this sample uses.
+interface LocalitiesWidget {
+ addListener(eventName: string, handler: () => void): void;
+ getSelectedSuggestionDetails(): unknown;
+}
+
+interface LocalitiesWidgetGlobal {
+ localities: {
+ Autocomplete: new (inputId: string, options: object) => LocalitiesWidget;
+ };
+}
+
function init(): void {
const responseElement = document.getElementById(
"response-container",
) as HTMLElement;
- //@ts-ignore
- const localitiesWidget = new window.woosmap.localities.Autocomplete(
+ const { localities } = woosmap as unknown as LocalitiesWidgetGlobal;
+ const localitiesWidget = new localities.Autocomplete(
"autocomplete-input",
{},
);
@@ -23,17 +35,6 @@ document.addEventListener("DOMContentLoaded", () => {
init();
});
-declare global {
- interface Window {
- // currently, the localities JS Widget typings are not exported, so we use `any` here
- //@ts-ignore
- woosmap: {
- localities: {
- Autocomplete: new (inputId: string, customConfig: any) => any;
- };
- };
- }
-}
// [END woosmap_localities_js_widget]
export {};
diff --git a/samples/localities-nearby-poi/index.njk b/samples/localities-nearby-poi/index.njk
index 02476f91..7a36c1d0 100644
--- a/samples/localities-nearby-poi/index.njk
+++ b/samples/localities-nearby-poi/index.njk
@@ -34,7 +34,7 @@
-