@maptiler/geocoding-control 0.0.31 → 0.0.36

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # MapTiler Geocoding control for MapLibre GL JS and Leaflet
2
2
 
3
- A geocoding control for [maplibre-gl-js](https://github.com/maplibre/maplibre-gl-js) and [Leaflet](https://github.com/maplibre/maplibre-gl-js).
3
+ A geocoding control for [Maplibre GL JS](https://github.com/maplibre/maplibre-gl-js) and [Leaflet](https://github.com/maplibre/maplibre-gl-js).
4
4
 
5
5
  Component can be used as ES module or UMD module.
6
6
 
@@ -8,7 +8,7 @@ Component can be used as ES module or UMD module.
8
8
 
9
9
  ### Usage with a module bundler
10
10
 
11
- Example for [Maplibre GL](https://maplibre.org/maplibre-gl-js-docs/api/):
11
+ Example for Maplibre GL JS:
12
12
 
13
13
  ```bash
14
14
  npm install --save @maptiler/geocoding-control maplibre-gl
@@ -19,24 +19,26 @@ import maplibregl from "maplibre-gl";
19
19
  import { GeocodingControl } from "@maptiler/geocoding-control/maplibre";
20
20
  import "@maptiler/geocoding-control/dist/style.css";
21
21
 
22
- const API_KEY = "your API key";
22
+ const API_KEY = "YOUR_MAPTILER_API_KEY_HERE";
23
23
 
24
24
  const map = new maplibregl.Map({
25
25
  container: "map", // id of HTML container element
26
- style: "https://api.maptiler.com/maps/streets/style.json?key=" + API_KEY,
26
+ style:
27
+ "https://api.maptiler.com/maps/streets/style.json?key=" +
28
+ YOUR_MAPTILER_API_KEY_HERE,
27
29
  center: [16.3, 49.2],
28
30
  zoom: 7,
29
31
  });
30
32
 
31
33
  const gc = new GeocodingControl({
32
- apiKey: API_KEY,
34
+ apiKey: YOUR_MAPTILER_API_KEY_HERE,
33
35
  maplibregl,
34
36
  });
35
37
 
36
38
  map.addControl(gc);
37
39
  ```
38
40
 
39
- Example for [Leaflet](https://leafletjs.com):
41
+ Example for Leaflet:
40
42
 
41
43
  ```bash
42
44
  npm install --save @maptiler/geocoding-control leaflet
@@ -47,19 +49,31 @@ import * as L from "leaflet";
47
49
  import { GeocodingControl } from "@maptiler/geocoding-control/leaflet";
48
50
  import "@maptiler/geocoding-control/dist/style.css";
49
51
 
50
- const API_KEY = "your API key";
51
-
52
52
  const map = L.map(document.getElementById("map")).setView([49.2, 16.3], 6);
53
53
 
54
- L.tileLayer("https://tile.openstreetmap.org/{z}/{x}/{y}.png", {
55
- attribution:
56
- '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
57
- }).addTo(map);
54
+ const scale = devicePixelRatio > 1.5 ? "@2x" : "";
55
+
56
+ L.tileLayer(
57
+ `https://api.maptiler.com/maps/streets/{z}/{x}/{y}${scale}.png?key=` +
58
+ YOUR_MAPTILER_API_KEY_HERE,
59
+ {
60
+ tileSize: 512,
61
+ zoomOffset: -1,
62
+ minZoom: 1,
63
+ attribution:
64
+ '<a href="https://www.maptiler.com/copyright/" target="_blank">&copy; MapTiler</a>, ' +
65
+ '<a href="https://www.openstreetmap.org/copyright" target="_blank">&copy; OpenStreetMap contributors</a>',
66
+ crossOrigin: true,
67
+ }
68
+ ).addTo(map);
58
69
 
59
- new GeocodingControl({ apiKey: API_KEY }).addTo(map);
70
+ L.control.maptilerGeocoding({ apiKey: YOUR_MAPTILER_API_KEY_HERE }).addTo(map);
60
71
  ```
61
72
 
62
- See [demo-maplibregl.html](./demo-maplibregl.html) or [demo-leaflet.html](./demo-leaflet.html) - after building this library (`npm install && npm run build`) open it in your browser with URL `file:///path_to_this_repository/demo.html#key=your_api_key`.
73
+ 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:
74
+
75
+ - Maplibre GL JS: `sensible-browser file://$(pwd)/demo-maplibregl.html#key=YOUR_MAPTILER_API_KEY_HERE`
76
+ - Leaflet: `sensible-browser file://$(pwd)/demo-leaflet.html#key=YOUR_MAPTILER_API_KEY_HERE`
63
77
 
64
78
  ## API Documentation
65
79
 
@@ -114,12 +128,12 @@ Component API matches API described above and options are exposed as component p
114
128
  <script lang="ts">
115
129
  import GeocodingControl from "@maptiler/geocoding-control/src/lib/GeocodingControl.svelte";
116
130
  import GeocodingControl from "@maptiler/geocoding-control/src/lib/GeocodingControl.svelte";
117
- import { createMaplibreMapController } from "@maptiler/geocoding-control/src/lib/maplibreMapController";
131
+ import { createMaplibreglMapController } from "@maptiler/geocoding-control/src/lib/maplibreglMapController";
118
132
  import type { MapController } from "@maptiler/geocoding-control/src/lib/types";
119
133
  import maplibregl from "maplibre-gl";
120
134
  import "maplibre-gl/dist/maplibre-gl.css";
121
135
 
122
- const apiKey = "your API key";
136
+ const apiKey = "YOUR_MAPTILER_API_KEY_HERE";
123
137
 
124
138
  let mapController: MapController;
125
139
 
@@ -132,7 +146,7 @@ Component API matches API described above and options are exposed as component p
132
146
  container,
133
147
  });
134
148
 
135
- const mapController = createMaplibreMapController(map, maplibregl);
149
+ const mapController = createMaplibreglMapController(map, maplibregl);
136
150
  }
137
151
  </script>
138
152
 
@@ -161,5 +175,5 @@ You will find compilation result in `dist` directory.
161
175
  ## Running in dev mode
162
176
 
163
177
  ```bash
164
- npm install && VITE_API_KEY=your_api_key npm run dev
178
+ npm install && VITE_API_KEY=YOUR_MAPTILER_API_KEY_HERE npm run dev
165
179
  ```