@maptiler/geocoding-control
Advanced tools
Comparing version 0.0.43 to 0.0.44
import type MapLibreGL from "maplibre-gl"; | ||
import type { FitBoundsOptions, Map, FlyToOptions, FillLayerSpecification, LineLayerSpecification } from "maplibre-gl"; | ||
import type { MapController } from "./types"; | ||
export declare function createMaplibreglMapController(map: Map, maplibregl?: typeof MapLibreGL | undefined, marker?: boolean | maplibregl.MarkerOptions, showResultMarkers?: boolean | maplibregl.MarkerOptions, flyToOptions?: FlyToOptions, fitBoundsOptions?: FitBoundsOptions, fullGeometryStyle?: { | ||
fill: Pick<FillLayerSpecification, "layout" | "paint" | "filter">; | ||
line: Pick<LineLayerSpecification, "layout" | "paint" | "filter">; | ||
export declare function createMaplibreglMapController(map: Map, maplibregl?: typeof MapLibreGL | undefined, marker?: boolean | maplibregl.MarkerOptions, showResultMarkers?: boolean | maplibregl.MarkerOptions, flyToOptions?: FlyToOptions, fitBoundsOptions?: FitBoundsOptions, fullGeometryStyle?: undefined | { | ||
fill?: Pick<FillLayerSpecification, "layout" | "paint" | "filter">; | ||
line?: Pick<LineLayerSpecification, "layout" | "paint" | "filter">; | ||
}): MapController; |
{ | ||
"name": "@maptiler/geocoding-control", | ||
"version": "0.0.43", | ||
"version": "0.0.44", | ||
"type": "module", | ||
@@ -46,3 +46,3 @@ "author": { | ||
"devDependencies": { | ||
"@sveltejs/vite-plugin-svelte": "^1.2.0", | ||
"@sveltejs/vite-plugin-svelte": "^1.3.1", | ||
"@tsconfig/svelte": "^3.0.0", | ||
@@ -53,3 +53,3 @@ "@turf/buffer": "^6.5.0", | ||
"@types/leaflet": "^1.9.0", | ||
"prettier": "^2.7.1", | ||
"prettier": "^2.8.0", | ||
"prettier-plugin-svelte": "^2.8.1", | ||
@@ -56,0 +56,0 @@ "svelte": "^3.53.1", |
@@ -19,12 +19,11 @@ # MapTiler Geocoding control for MapLibre GL JS and Leaflet | ||
import maplibregl from "maplibre-gl"; | ||
import { GeocodingControl } from "@maptiler/geocoding-control/maplibre"; | ||
import { GeocodingControl } from "@maptiler/geocoding-control/maplibregl"; | ||
import "@maptiler/geocoding-control/dist/style.css"; | ||
import "maplibre-gl/dist/maplibre-gl.css"; | ||
const API_KEY = "YOUR_MAPTILER_API_KEY_HERE"; | ||
const apiKey = "YOUR_MAPTILER_API_KEY_HERE"; | ||
const map = new maplibregl.Map({ | ||
container: "map", // id of HTML container element | ||
style: | ||
"https://api.maptiler.com/maps/streets/style.json?key=" + | ||
YOUR_MAPTILER_API_KEY_HERE, | ||
style: "https://api.maptiler.com/maps/streets/style.json?key=" + apiKey, | ||
center: [16.3, 49.2], | ||
@@ -34,6 +33,3 @@ zoom: 7, | ||
const gc = new GeocodingControl({ | ||
apiKey: YOUR_MAPTILER_API_KEY_HERE, | ||
maplibregl, | ||
}); | ||
const gc = new GeocodingControl({ apiKey, maplibregl }); | ||
@@ -54,2 +50,4 @@ map.addControl(gc); | ||
const apiKey = "YOUR_MAPTILER_API_KEY_HERE"; | ||
const map = L.map(document.getElementById("map")).setView([49.2, 16.3], 6); | ||
@@ -60,4 +58,3 @@ | ||
L.tileLayer( | ||
`https://api.maptiler.com/maps/streets/{z}/{x}/{y}${scale}.png?key=` + | ||
YOUR_MAPTILER_API_KEY_HERE, | ||
`https://api.maptiler.com/maps/streets/{z}/{x}/{y}${scale}.png?key=` + apiKey, | ||
{ | ||
@@ -74,3 +71,3 @@ tileSize: 512, | ||
L.control.maptilerGeocoding({ apiKey: YOUR_MAPTILER_API_KEY_HERE }).addTo(map); | ||
L.control.maptilerGeocoding({ apiKey }).addTo(map); | ||
``` | ||
@@ -77,0 +74,0 @@ |
@@ -36,6 +36,8 @@ import type MapLibreGL from "maplibre-gl"; | ||
fitBoundsOptions: FitBoundsOptions = {}, | ||
fullGeometryStyle: { | ||
fill: Pick<FillLayerSpecification, "layout" | "paint" | "filter">; | ||
line: Pick<LineLayerSpecification, "layout" | "paint" | "filter">; | ||
} = { | ||
fullGeometryStyle: | ||
| undefined | ||
| { | ||
fill?: Pick<FillLayerSpecification, "layout" | "paint" | "filter">; | ||
line?: Pick<LineLayerSpecification, "layout" | "paint" | "filter">; | ||
} = { | ||
fill: { | ||
@@ -72,20 +74,26 @@ paint: { | ||
function addFullGeometryLayer() { | ||
map.addSource("full-geom", { | ||
type: "geojson", | ||
data: emptyGeojson, | ||
}); | ||
if (fullGeometryStyle?.fill || fullGeometryStyle?.line) { | ||
map.addSource("full-geom", { | ||
type: "geojson", | ||
data: emptyGeojson, | ||
}); | ||
} | ||
map.addLayer({ | ||
...fullGeometryStyle.fill, | ||
id: "full-geom-fill", | ||
type: "fill", | ||
source: "full-geom", | ||
}); | ||
if (fullGeometryStyle?.fill) { | ||
map.addLayer({ | ||
...fullGeometryStyle?.fill, | ||
id: "full-geom-fill", | ||
type: "fill", | ||
source: "full-geom", | ||
}); | ||
} | ||
map.addLayer({ | ||
...fullGeometryStyle.line, | ||
id: "full-geom-line", | ||
type: "line", | ||
source: "full-geom", | ||
}); | ||
if (fullGeometryStyle?.line) { | ||
map.addLayer({ | ||
...fullGeometryStyle?.line, | ||
id: "full-geom-line", | ||
type: "line", | ||
source: "full-geom", | ||
}); | ||
} | ||
} | ||
@@ -255,25 +263,29 @@ | ||
markers.push( | ||
(typeof marker === "object" | ||
? new maplibregl.Marker(marker) | ||
: createMarker() | ||
) | ||
.setLngLat(picked.center) | ||
.addTo(map) | ||
); | ||
if (showResultMarkers) { | ||
markers.push( | ||
(typeof marker === "object" | ||
? new maplibregl.Marker(marker) | ||
: createMarker() | ||
) | ||
.setLngLat(picked.center) | ||
.addTo(map) | ||
); | ||
} | ||
} | ||
for (const feature of markedFeatures ?? []) { | ||
if (feature === picked) { | ||
continue; | ||
if (showResultMarkers) { | ||
for (const feature of markedFeatures ?? []) { | ||
if (feature === picked) { | ||
continue; | ||
} | ||
markers.push( | ||
(typeof showResultMarkers === "object" | ||
? new maplibregl.Marker(showResultMarkers) | ||
: createMarker() | ||
) | ||
.setLngLat(feature.center) | ||
.addTo(map) | ||
); | ||
} | ||
markers.push( | ||
(typeof showResultMarkers === "object" | ||
? new maplibregl.Marker(showResultMarkers) | ||
: createMarker() | ||
) | ||
.setLngLat(feature.center) | ||
.addTo(map) | ||
); | ||
} | ||
@@ -280,0 +292,0 @@ }, |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
1977049
35440
181