Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ jobs:
${{ runner.os }}-node
- run: npm i
- run: npm run test:check
- run: npm run lint
8 changes: 6 additions & 2 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,13 @@ export default [
node: true,
},
rules: {
"no-unused-vars": [1, { varsIgnorePattern: "init*" }],
// The TS rule replaces the base one under @typescript-eslint/recommended,
// so the initMap-style callback exemption has to live on it.
"no-unused-vars": 0,
"@typescript-eslint/no-unused-vars": [2, { varsIgnorePattern: "^init" }],
"no-var": 2,
"@typescript-eslint/no-var-requires": 0,
// The build scripts are CommonJS (typescript-eslint v8 renamed no-var-requires).
"@typescript-eslint/no-require-imports": 0,
"prefer-arrow-callback": 2,
},
}),
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"@playwright/test": "^1.60.0",
"@types/geojson": "^7946.0.16",
"@types/supercluster": "^7.1.3",
"@types/woosmap.map": "^1.4.26",
"@types/woosmap.map": "^1.4.28",
"@typescript-eslint/eslint-plugin": "^8.60.1",
"@typescript-eslint/parser": "^8.15.0",
"chalk": "^5.6.2",
Expand Down
3 changes: 2 additions & 1 deletion samples/add-map/add-map.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
"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 }}",
"loaderShim": true
}
2 changes: 1 addition & 1 deletion samples/add-map/index.njk
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
{% block html %}
<!-- [START woosmap_{{ tag }}_div] -->
<!--The div element for the map -->
<div id="map"></div>
<wmp-map id="map"></wmp-map>
<!-- [END woosmap_{{ tag }}_div] -->
{% endblock %}
14 changes: 6 additions & 8 deletions samples/add-map/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
// Initialize and add the map
let map: woosmap.map.Map;

function initMap(): void {
async function initMap(): Promise<void> {
await woosmap.map.importLibrary("maps");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocker: This first new API call illustrates the repo-wide type-check failure: the current @types/woosmap.map declarations do not include importLibrary, MapElement, moveCamera, the marker namespace, or the object-form InfoWindow.open. The Test workflow stops with 280 TypeScript errors, so every migrated sample currently fails the required compile check. Please make matching declarations available to tsc (for example, update/pin a released types package or add the necessary local declarations) and refresh the lockfile.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 97a7d80: bumped to @types/woosmap.map 1.4.28, which ships importLibrary, MapElement, moveCamera, the marker namespace and the object-form InfoWindow.open. test passes now.


// [START woosmap_add_map_instantiate_map]
// The location of London
const position: woosmap.map.LatLngLiteral = {
Expand All @@ -11,19 +13,15 @@ function initMap(): void {
};

// The map, centered at London
map = new woosmap.map.Map(document.getElementById("map") as HTMLElement, {
map = (document.getElementById("map") as woosmap.map.MapElement).innerMap;
map.moveCamera({
zoom: 13,
center: position,
});
// [END woosmap_add_map_instantiate_map]
}

declare global {
interface Window {
initMap: () => void;
}
}
window.initMap = initMap;
initMap();
// [END woosmap_add_map]

export {};
3 changes: 2 additions & 1 deletion samples/datasets-api/datasets-api.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
"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 }}",
"loaderShim": true
}
2 changes: 1 addition & 1 deletion samples/datasets-api/index.njk
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
</div>
</div>
<div id="mapContainer">
<div id="map"></div>
<wmp-map id="map"></wmp-map>
<div id="autocomplete-container">
{% svgIcon 'search.svg' %}
<input
Expand Down
43 changes: 22 additions & 21 deletions samples/datasets-api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,22 @@ let suggestionsList: HTMLUListElement;
let clearSearchBtn: HTMLButtonElement;
let datasetSelect: HTMLSelectElement;
let operatorSelect: HTMLSelectElement;
let debouncedLocalitiesAutocomplete: (...args: any[]) => Promise<any>;
let debouncedLocalitiesAutocomplete: (
request: woosmap.map.localities.LocalitiesAutocompleteRequest,
) => Promise<woosmap.map.localities.LocalitiesAutocompleteResponse>;
let results: HTMLOListElement;
let resetButton: HTMLButtonElement;

const datasetId = "a01df3d6-fe7d-42df-8fee-9f31726a2641"; //US - Seismic Hazard Map

function initMap(): void {
async function initMap(): Promise<void> {
await woosmap.map.importLibrary("maps");
await woosmap.map.importLibrary("drawing");

// [START woosmap_datasets_api_instantiate_map]

map = new woosmap.map.Map(document.getElementById("map") as HTMLElement, {
map = (document.getElementById("map") as woosmap.map.MapElement).innerMap;
map.setOptions({
gestureHandling: "auto",
defaultStyle: "streets",
});
Expand All @@ -41,7 +47,7 @@ function initServices(): void {
datasetsService = new woosmap.map.DatasetsService(datasetId);
datasetsOverlay.setMap(map);

localitiesService = new window.woosmap.map.LocalitiesService();
localitiesService = new woosmap.map.LocalitiesService();
request = {
input: "",
types: ["locality", "address", "postal_code"],
Expand All @@ -60,7 +66,7 @@ function initDrawing(): void {
},
});
drawTools.addControl(map);
drawTools.addListener("draw.create", async (ev) => {
drawTools.addListener("draw.create", async () => {
const collection = drawTools.getAll();
if (collection.features.length > 1) {
for (const feature of collection.features.slice(0, -1)) {
Expand Down Expand Up @@ -210,7 +216,7 @@ function manageFiltersElements() {
const selectElement = event.target as HTMLSelectElement;
updateDataset(selectElement.value);
});
operatorSelect.addEventListener("change", async (ev) => {
operatorSelect.addEventListener("change", async () => {
const collection = drawTools.getAll();
await intersectCb(collection);
});
Expand Down Expand Up @@ -245,16 +251,16 @@ async function intersectCb(ev) {

await applyOperator(ev.features[0].geometry, operatorSelect.value)
.then((response) => {
const features = [];
const features: woosmap.map.GeoJSONFeature[] = [];
bindResultsToPanel(response.features);
map.data.forEach((feature) => {
map.data.remove(feature);
});
for (const feature of response.features) {
// @ts-ignore TypeDef to be updated
features.push({
type: "Feature",
geometry: feature.geometry,
properties: {},
});
}

Expand Down Expand Up @@ -282,28 +288,28 @@ function bindResultsToPanel(features: woosmap.map.GeoJSONFeature[]) {
resultListItem.innerHTML +
`<tr><td><b>${key} </b></td><td>${attributes[key]}</td></tr>`;
}
}),
results.appendChild(resultListItem);
});
results.appendChild(resultListItem);
});
} else {
results.innerHTML = "No results found";
results.classList.add("error");
}
}
// [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<T, Args extends any[]> = (
type DebouncePromiseFunction<T, Args extends unknown[]> = (
...args: Args
) => Promise<T>;

function debouncePromise<T, Args extends any[]>(
function debouncePromise<T, Args extends unknown[]>(
fn: (...args: Args) => Promise<T>,
delay: number,
): DebouncePromiseFunction<T, Args> {
let timeoutId: ReturnType<typeof setTimeout> | null = null;
let latestResolve: ((value: T | PromiseLike<T>) => void) | null = null;
let latestReject: ((reason?: any) => void) | null = null;
let latestReject: ((reason?: unknown) => void) | null = null;

return function (...args: Args): Promise<T> {
return new Promise<T>((resolve, reject) => {
Expand All @@ -330,14 +336,9 @@ function debouncePromise<T, Args extends any[]>(
}

// [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_datasets_api]

export {};
4 changes: 3 additions & 1 deletion samples/directions-advanced/directions-advanced.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion samples/directions-advanced/index.njk
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@
<div class="linear-progress hide">
<div class="progress"></div>
</div>
<div id="map"></div>
<wmp-map id="map"></wmp-map>
<div id="infoMessage">Drag markers to update route</div>
<div class="tableContainer">
</div>
Expand Down
66 changes: 24 additions & 42 deletions samples/directions-advanced/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ let map: woosmap.map.Map;
let bounds: woosmap.map.LatLngBounds;
let directionsService: woosmap.map.DirectionsService;
let directionsRequest: woosmap.map.DirectionRequest;
let markersArray: woosmap.map.Marker[] = [];
let markersArray: woosmap.map.marker.AdvancedMarkerElement[] = [];
let waypointsList: HTMLElement;
let originContainer: HTMLElement;
let destinationContainer: HTMLElement;
Expand All @@ -18,24 +18,15 @@ const travelModeIcons = {
function createMarker(
position: woosmap.map.LatLngLiteral | woosmap.map.LatLng,
label: string,
url: string,
): woosmap.map.Marker {
return new woosmap.map.Marker({
background: string,
): woosmap.map.marker.AdvancedMarkerElement {
const { PinElement } = woosmap.map.marker;
const pin = new PinElement({ background, glyphText: label, glyphColor: "#FFFFFF" });
return new woosmap.map.marker.AdvancedMarkerElement({
map,
position,
draggable: true,
icon: {
url,
labelOrigin: new woosmap.map.Point(13, 15),
scaledSize: {
height: 38,
width: 26,
},
},
label: {
text: label,
color: "white",
},
gmpDraggable: true,
content: pin.element,
});
}

Expand All @@ -48,26 +39,18 @@ function clearMarkers(): void {

function displayDirectionsMarkers(): void {
clearMarkers();
const originMarker = createMarker(
directionsRequest.origin,
"O",
"https://images.woosmap.com/marker-blue.svg",
);
const originMarker = createMarker(directionsRequest.origin, "O", "#3d5afe");
originMarker.addListener("dragend", () => {
directionsRequest.origin = originMarker.getPosition();
setLatLngToContainer(originContainer, originMarker.getPosition().toJSON());
directionsRequest.origin = originMarker.position!;
setLatLngToContainer(originContainer, originMarker.position!.toJSON());
calculateDirections();
});
const destinationMarker = createMarker(
directionsRequest.destination,
"D",
"https://images.woosmap.com/marker-red.svg",
);
const destinationMarker = createMarker(directionsRequest.destination, "D", "#f50057");
destinationMarker.addListener("dragend", () => {
directionsRequest.destination = destinationMarker.getPosition();
directionsRequest.destination = destinationMarker.position!;
setLatLngToContainer(
destinationContainer,
destinationMarker.getPosition().toJSON(),
destinationMarker.position!.toJSON(),
);
calculateDirections();
});
Expand All @@ -80,12 +63,12 @@ function displayDirectionsMarkers(): void {
const waypointMarker = createMarker(
waypoint.location as woosmap.map.LatLngLiteral,
(index + 1).toString(),
"https://images.woosmap.com/marker-green.svg",
"#03BDA5",
);
waypointMarker.addListener("dragend", () => {
waypoints[index].location = waypointMarker.getPosition().toJSON();
waypoints[index].location = waypointMarker.position!.toJSON();
waypointsList.querySelectorAll("li")[index].innerHTML =
`<span>lat: ${waypointMarker.getPosition().lat().toFixed(4)}, lng: ${waypointMarker.getPosition().lng().toFixed(4)}<span>`;
`<span>lat: ${waypointMarker.position!.lat().toFixed(4)}, lng: ${waypointMarker.position!.lng().toFixed(4)}<span>`;
calculateDirections();
});
markersArray.push(waypointMarker);
Expand Down Expand Up @@ -522,8 +505,12 @@ function initUI(): void {
);
}

function initMap(): void {
map = new woosmap.map.Map(document.getElementById("map") as HTMLElement, {
async function initMap(): Promise<void> {
await woosmap.map.importLibrary("maps");
await woosmap.map.importLibrary("marker");

map = (document.getElementById("map") as woosmap.map.MapElement).innerMap;
map.moveCamera({
center: { lat: 51.5074, lng: -0.1478 },
zoom: 10,
});
Expand All @@ -539,12 +526,7 @@ function initMap(): void {
calculateDirections();
}

declare global {
interface Window {
initMap: () => void;
}
}
window.initMap = initMap;
initMap();
// [END woosmap_directions_advanced]

export {};
3 changes: 2 additions & 1 deletion samples/directions-simple/directions-simple.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
"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 }}",
"loaderShim": true
}
2 changes: 1 addition & 1 deletion samples/directions-simple/index.njk
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,5 @@
</div>
</div>
<!--The div element for the map -->
<div id="map"></div>
<wmp-map id="map"></wmp-map>
{% endblock %}
Loading
Loading