@maptiler/geocoding-control 0.0.43 → 0.0.48
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.
- package/README.md +27 -16
- package/dist/leaflet.js +3909 -3883
- package/dist/leaflet.umd.js +4 -24
- package/dist/lib/maplibreglMapController.d.ts +3 -3
- package/dist/lib/types.d.ts +44 -3
- package/dist/main.d.ts +1 -1
- package/dist/maplibregl.js +4018 -3996
- package/dist/maplibregl.umd.js +4 -24
- package/dist/style.css +1 -1
- package/package.json +11 -11
- package/src/lib/GeocodingControl.svelte +106 -40
- package/src/lib/MarkerIcon.svelte +21 -14
- package/src/lib/leafletMapController.ts +102 -51
- package/src/lib/maplibreglMapController.ts +135 -73
- package/src/lib/types.ts +41 -29
package/README.md
CHANGED
|
@@ -16,24 +16,20 @@ npm install --save @maptiler/geocoding-control maplibre-gl
|
|
|
16
16
|
|
|
17
17
|
```js
|
|
18
18
|
import maplibregl from "maplibre-gl";
|
|
19
|
-
import { GeocodingControl } from "@maptiler/geocoding-control/
|
|
19
|
+
import { GeocodingControl } from "@maptiler/geocoding-control/maplibregl";
|
|
20
20
|
import "@maptiler/geocoding-control/dist/style.css";
|
|
21
|
+
import "maplibre-gl/dist/maplibre-gl.css";
|
|
21
22
|
|
|
22
|
-
const
|
|
23
|
+
const apiKey = "YOUR_MAPTILER_API_KEY_HERE";
|
|
23
24
|
|
|
24
25
|
const map = new maplibregl.Map({
|
|
25
26
|
container: "map", // id of HTML container element
|
|
26
|
-
style:
|
|
27
|
-
"https://api.maptiler.com/maps/streets/style.json?key=" +
|
|
28
|
-
YOUR_MAPTILER_API_KEY_HERE,
|
|
27
|
+
style: "https://api.maptiler.com/maps/streets/style.json?key=" + apiKey,
|
|
29
28
|
center: [16.3, 49.2],
|
|
30
29
|
zoom: 7,
|
|
31
30
|
});
|
|
32
31
|
|
|
33
|
-
const gc = new GeocodingControl({
|
|
34
|
-
apiKey: YOUR_MAPTILER_API_KEY_HERE,
|
|
35
|
-
maplibregl,
|
|
36
|
-
});
|
|
32
|
+
const gc = new GeocodingControl({ apiKey, maplibregl });
|
|
37
33
|
|
|
38
34
|
map.addControl(gc);
|
|
39
35
|
```
|
|
@@ -49,13 +45,14 @@ import * as L from "leaflet";
|
|
|
49
45
|
import { GeocodingControl } from "@maptiler/geocoding-control/leaflet";
|
|
50
46
|
import "@maptiler/geocoding-control/dist/style.css";
|
|
51
47
|
|
|
48
|
+
const apiKey = "YOUR_MAPTILER_API_KEY_HERE";
|
|
49
|
+
|
|
52
50
|
const map = L.map(document.getElementById("map")).setView([49.2, 16.3], 6);
|
|
53
51
|
|
|
54
52
|
const scale = devicePixelRatio > 1.5 ? "@2x" : "";
|
|
55
53
|
|
|
56
54
|
L.tileLayer(
|
|
57
|
-
`https://api.maptiler.com/maps/streets/{z}/{x}/{y}${scale}.png?key=` +
|
|
58
|
-
YOUR_MAPTILER_API_KEY_HERE,
|
|
55
|
+
`https://api.maptiler.com/maps/streets/{z}/{x}/{y}${scale}.png?key=` + apiKey,
|
|
59
56
|
{
|
|
60
57
|
tileSize: 512,
|
|
61
58
|
zoomOffset: -1,
|
|
@@ -67,7 +64,7 @@ L.tileLayer(
|
|
|
67
64
|
}
|
|
68
65
|
).addTo(map);
|
|
69
66
|
|
|
70
|
-
L.control.maptilerGeocoding({ apiKey
|
|
67
|
+
L.control.maptilerGeocoding({ apiKey }).addTo(map);
|
|
71
68
|
```
|
|
72
69
|
|
|
73
70
|
For examples without using bundler see `demo-maplibregl.html` or `demo-leaflet.html`. After building this library (`npm install && npm run build`) you can open it in the browser:
|
|
@@ -77,7 +74,7 @@ For examples without using bundler see `demo-maplibregl.html` or `demo-leaflet.h
|
|
|
77
74
|
|
|
78
75
|
## API Documentation
|
|
79
76
|
|
|
80
|
-
Options
|
|
77
|
+
### Options
|
|
81
78
|
|
|
82
79
|
- `apiKey`<sup>\*</sup>: `string` - Maptiler API key
|
|
83
80
|
- `maplibregl`: `MapLibreGL` - A Maplibre GL instance to use when creating [Markers](https://maplibre.org/maplibre-gl-js-docs/api/markers/#marker). Required if `options.marker` is `true`. Used only with Maplibre GL library.
|
|
@@ -89,7 +86,7 @@ Options:
|
|
|
89
86
|
- `trackProximity`: `boolean` - If true, the geocoder proximity will automatically update based on the map view. Default `true`.
|
|
90
87
|
- `minLength`: `number` - Minimum number of characters to enter before results are shown. Default `2`.
|
|
91
88
|
- `bbox`: `[number, number, number, number]` - A bounding box argument: this is a bounding box given as an array in the format [minX, minY, maxX, maxY]. Search results will be limited to the bounding box.
|
|
92
|
-
- `language`: `string` - Specify the language to use for response text and query result weighting. Options are IETF language tags comprised of a mandatory ISO 639-1 language code and optionally one or more IETF subtags for country or script. More than one value can also be specified, separated by commas. Set to empty string for forcing no language preference.
|
|
89
|
+
- `language`: `string | string[]` - Specify the language(s) to use for response text and query result weighting. Options are IETF language tags comprised of a mandatory ISO 639-1 language code and optionally one or more IETF subtags for country or script. More than one value can also be specified, separated by commas. Set to empty string for forcing no language preference.
|
|
93
90
|
- `showResultsWhileTyping`: `boolean` - If `false`, indicates that search will only occur on enter key press. If `true`, indicates that the Geocoder will search on the input box being updated above the minLength option. Default `false`.
|
|
94
91
|
- `marker`: `boolean | MarkerOptions` - If `true`, a [MapLibre GL Marker](https://maplibre.org/maplibre-gl-js-docs/api/markers/#marker) / [Leaflet Marker](https://leafletjs.com/reference.html#marker) will be added to the map at the location of the user-selected result using a default set of Marker options. If the value is an object, the marker will be constructed using these options. If `false`, no marker will be added to the map. Requires that `options.maplibregl` also be set. Default `true`.
|
|
95
92
|
- `showResultMarkers`: `boolean | MarkerOptions` - If `true`, [MapLibre GL Marker](https://maplibre.org/maplibre-gl-js-docs/api/markers/#marker) / [Leaflet Marker](https://leafletjs.com/reference.html#marker) will be added to the map at the location the top results for the query. If the value is an object, the marker will be constructed using these options. If `false`, no marker will be added to the map. Requires that `options.maplibregl` also be set. Default `true`.
|
|
@@ -104,15 +101,21 @@ Options:
|
|
|
104
101
|
- `clearButtonTitle`: `string` - Clear button title. Default `"clear"`.
|
|
105
102
|
- `showFullGeometry`: `boolean` - Set to `true` to show full feature geometry of the chosen result. Otherwise only marker will be shown. Default `true`.
|
|
106
103
|
- `fullGeometryStyle`: `{ fill: Pick<FillLayerSpecification, "layout" | "paint" | "filter">; line: Pick<LineLayerSpecification, "layout" | "paint" | "filter">; } | (L.PathOptions | L.StyleFunction)` - style of the full feature geometry. See Mapplibre GL JS or Leaflet documentation.
|
|
104
|
+
- `fuzzyMatch`: `boolean` - Set to `false` to disable fuzzy search. Default `true`.
|
|
105
|
+
- `limit`: `number` - Maximum number of results to show. Default `5`.
|
|
106
|
+
- `country`: `string | string[]` - Limit search to specified country(ies). Default `undefined` (use all countries).
|
|
107
|
+
- `types`: `string[]` - Filter of feature types to return. Default `undefined` (all available feature types are returned).
|
|
107
108
|
|
|
108
|
-
Methods
|
|
109
|
+
### Methods
|
|
109
110
|
|
|
110
111
|
- `setQuery(value: string, submit = true): void` - set the query and optionally submit it
|
|
111
112
|
- `focus(): void` - focus the query input box
|
|
112
113
|
- `blur(): void` - blur the query input box
|
|
113
114
|
- `setReverseMode(value: boolean | "always"): void` - set reverse mode
|
|
114
115
|
|
|
115
|
-
Events
|
|
116
|
+
### Events
|
|
117
|
+
|
|
118
|
+
Events are implemented using [EventTarget](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget) and [CustomEvent](https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent).
|
|
116
119
|
|
|
117
120
|
- `select` - Fired on highlighting search result in the dropdown by hovering it or by keyboard selection. Event value will be set to the highlighted `Feature` or to `undefined` if nothing is highlighted.
|
|
118
121
|
- `pick` - Fired on picking the result from the dropdown. Event value will be set to the picked `Feature` or to `undefined` if nothing is picked (eg. search input is cleared).
|
|
@@ -123,6 +126,14 @@ Events:
|
|
|
123
126
|
- `reversetoggle` - Fired if reverse geocoding button is toggled. Event value is `true` if reverse geocoding mode is active, otherwise `false`.
|
|
124
127
|
- `querychange` - Fired if query was changed. Event value is the query string.
|
|
125
128
|
|
|
129
|
+
Example:
|
|
130
|
+
|
|
131
|
+
```javascript
|
|
132
|
+
geocodingControl.addEventListener("optionsVisibilityChange", (e) => {
|
|
133
|
+
console.log("Options visible:", e.detail);
|
|
134
|
+
});
|
|
135
|
+
```
|
|
136
|
+
|
|
126
137
|
## Svelte component
|
|
127
138
|
|
|
128
139
|
In addition to using the component as MapLibre GL Control it is alto possible to use it stand-alone in Svelte projects.
|