Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 4 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ demos
public
src
!dist/src
test
*.tgz
.github
.husky
.vscode
vite*
.*
tsconfig.json
tsconfig.*.json
eslint.config.js
tmp
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist
tmp
25 changes: 25 additions & 0 deletions demos/05-leaflet.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!doctype html>
<html>
<head>
<title>MapTiler Geocoding Control example</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style>
html,
body {
margin: 0;
}

#map {
position: absolute;
width: 100vw;
height: 100vh;
background: #ccc;
}
</style>
</head>

<body>
<div id="map"></div>
<script type="module" src="/src/05-leaflet.ts"></script>
</body>
</html>
1 change: 1 addition & 0 deletions demos/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
<a href="02-maptiler-sdk.html">MapTiler SDK →</a>
<a href="03-maplibregl.html">MapLibre GL →</a>
<a href="04-react.html">React →</a>
<a href="05-leaflet.html">Leaflet →</a>
</div>
</div>
</body>
Expand Down
95 changes: 95 additions & 0 deletions demos/src/05-leaflet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import { control, map as LMap, Marker, Popup, tileLayer } from "leaflet";
import "leaflet/dist/leaflet.css";

import { GeocodingControl } from "../../src/leaflet.public";

import { getApiKey } from "./demo-utils";

const map = LMap("map", {
center: [0, 0],
zoom: 2,
zoomControl: false,
});

tileLayer(`https://api.maptiler.com/maps/streets-v2/{z}/{x}/{y}.png?key=${getApiKey()}`, {
tileSize: 512,
zoomOffset: -1,
minZoom: 1,
attribution:
'\u003ca href="https://www.maptiler.com/copyright/" target="_blank"\u003e\u0026copy; MapTiler\u003c/a\u003e \u003ca href="https://www.openstreetmap.org/copyright" target="_blank"\u003e\u0026copy; OpenStreetMap contributors\u003c/a\u003e',
crossOrigin: true,
}).addTo(map);

const geocodingControl = new GeocodingControl({
apiKey: getApiKey(),
enableReverse: "button",
collapsed: true,
// limit: 20,
// types: ["poi"],
// fetchParameters: { credentials: "include" },
// selectFirst: false,
iconsBaseUrl: "/assets/icons/",
proximity: [
{ type: "map-center", minZoom: 12 },
{ type: "client-geolocation", minZoom: 8 },
{ type: "server-geolocation", minZoom: 8 },
],
adjustUrl(url) {
// for reverse geocoding use only address type
if (/\/\d+\.?\d*%2C\d+.?\d*.json$/.test(url.pathname)) {
url.searchParams.set("types", "address");
url.searchParams.set("limit", "5");
}
},
marker(map, feature) {
if (!feature) {
return;
}

const marker = new Marker({ lng: feature.center[0], lat: feature.center[1] })
.bindPopup(new Popup({ closeButton: false }).setContent(feature.text))
.addTo(map)
.togglePopup();

const element = marker.getElement();

if (element) {
element.style.cursor = "pointer";

element.addEventListener("click", (e) => {
marker.togglePopup();
e.stopPropagation();
});
}

return marker;
},
showResultMarkers(map, feature) {
return new Marker({ lng: feature.center[0], lat: feature.center[1] })
.bindPopup(new Popup({ closeButton: false }).setContent(feature.text))
.addTo(map)
.togglePopup();
},
});

map.addControl(geocodingControl);

geocodingControl.on("featureslisted", (e) => {
console.log(e);
});

map.addControl(
new GeocodingControl({
position: "topleft",
apiKey: getApiKey(),
keepListOpen: true,
enableReverse: "button",
collapsed: false,
pickedResultStyle: "full-geometry",
types: ["locality"],
fullGeometryStyle: true,
iconsBaseUrl: "/assets/icons/",
}),
);

map.addControl(control.zoom({ position: "topright" }));
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { defineConfig, globalIgnores } from "eslint/config";
import tseslint from "typescript-eslint";

export default defineConfig(
globalIgnores(["dist/", "vite.config*.ts", "**/eslint.config.js"]),
globalIgnores(["dist/", "vite.config*.ts", "**/eslint.config.js", "tmp/"]),
// https://typescript-eslint.io/getting-started/typed-linting/
tseslint.configs.strictTypeChecked,
tseslint.configs.stylisticTypeChecked,
Expand Down
78 changes: 64 additions & 14 deletions package-lock.json

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

31 changes: 23 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,21 @@
],
"scripts": {
"dev": "vite -c vite.config-dev.ts",
"make": "npm run clean && npm run build",
"build": "npm run build:index && npm run build:index:umd && npm run build:maptilersdk && npm run build:maptilersdk:umd && npm run build:maplibregl && npm run build:maplibregl:umd",
"make": "npm run clean && npm run build && npm run check-version",
"build": "npm run build:index && npm run build:index:umd && npm run build:maptilersdk && npm run build:maptilersdk:umd && npm run build:maplibregl && npm run build:maplibregl:umd && npm run build:leaflet && npm run build:leaflet:umd",
"build:index": "FLAVOUR=index vite build",
"build:index:umd": "FLAVOUR=index MODE=umd vite build",
"build:maptilersdk": "FLAVOUR=maptilersdk vite build",
"build:maptilersdk:umd": "FLAVOUR=maptilersdk MODE=umd vite build",
"build:maplibregl": "FLAVOUR=maplibregl vite build",
"build:maplibregl:umd": "FLAVOUR=maplibregl MODE=umd vite build",
"build:leaflet": "FLAVOUR=leaflet vite build",
"build:leaflet:umd": "FLAVOUR=leaflet MODE=umd vite build",
"check-version": "npm run check-version:leaflet-v1.5 && npm run check-version:leaflet-v1.7 && npm run check-version:leaflet-v1.9 && npm run check-version:leaflet-v2",
"check-version:leaflet-v1.5": "tsc -p tsconfig.leaflet-v1.5.json",
"check-version:leaflet-v1.7": "tsc -p tsconfig.leaflet-v1.7.json",
"check-version:leaflet-v1.9": "tsc -p tsconfig.leaflet-v1.9.json",
"check-version:leaflet-v2": "tsc -p tsconfig.leaflet-v2.json",
"lint": "eslint -c eslint.config.js . && prettier --check . && tsc --noEmit",
"lint:fix": "eslint -c eslint.config.js --fix && prettier --write . && tsc --noEmit",
"test": "vitest run -c vite.config-test.ts --dom",
Expand All @@ -51,23 +58,29 @@
"main": "dist/index.js",
"exports": {
".": {
"types": "./dist/index.d.ts",
"types": "./dist/src/index.d.ts",
"import": "./dist/index.js",
"require": "./dist/index.umd.js"
},
"./maplibregl": {
"types": "./dist/maplibregl.d.ts",
"types": "./dist/src/maplibregl.d.ts",
"import": "./dist/maplibregl.js",
"require": "./dist/maplibregl.umd.js"
},
"./maptilersdk": {
"types": "./dist/maptilersdk.d.ts",
"types": "./dist/src/maptilersdk.d.ts",
"import": "./dist/maptilersdk.js",
"require": "./dist/maptilersdk.umd.js"
},
"./leaflet": {
"types": "./dist/src/leaflet.public.d.ts",
"import": "./dist/leaflet.public.js",
"require": "./dist/leaflet.public.umd.js"
}
},
"dependencies": {
"@turf/bbox": "^7.2.0",
"@turf/clone": "^7.2.0",
"@turf/difference": "^7.2.0",
"@turf/flatten": "^7.2.0",
"@turf/helpers": "^7.2.0",
Expand All @@ -80,6 +93,9 @@
"@canvas/image-data": "^1.1.0",
"@maptiler/sdk": "^3.8.0",
"@types/leaflet": "^1.9.21",
"@types/leaflet--v1.5": "npm:@types/[email protected]",
"@types/leaflet--v1.7": "npm:@types/[email protected]",
"@types/leaflet--v1.9": "npm:@types/[email protected]",
"@types/node": "ts5.8",
"@types/react": "^19.2.6",
"@types/react-dom": "^19.2.3",
Expand All @@ -91,7 +107,6 @@
"happy-dom": "^20.0.10",
"husky": "^9.1.7",
"leaflet": "^1.9.4",
"leaflet-v2": "npm:[email protected]",
"ol": "^10.6.1",
"prettier": "^3.6.2",
"prettier-plugin-organize-imports": "^4.3.0",
Expand All @@ -107,8 +122,8 @@
"vitest": "^4.0.8"
},
"peerDependencies": {
"@maptiler/sdk": "1 - 3",
"leaflet": "1.7 - 2",
"@maptiler/sdk": "1 - 4",
"leaflet": "1.5 - 2",
"maplibre-gl": "2 - 5",
"ol": "6 - 10"
},
Expand Down
Loading