Skip to content

Commit 75eade3

Browse files
committedJan 3, 2025
feat: add reverse example for maplibre + leaflet
1 parent 8576748 commit 75eade3

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed
 

‎examples/leaflet/leaflet+reverse.html

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<html>
2+
<head>
3+
<script src="https://api.jawg.io/libraries/jawg-places@latest/jawg-places.js?access-token=<YOUR_ACCESS_TOKEN>"></script>
4+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/leaflet@1.9.4/dist/leaflet.css" />
5+
<script src="https://cdn.jsdelivr.net/npm/leaflet@1.9.4/dist/leaflet.js"></script>
6+
</head>
7+
<body>
8+
<div id="my-map" style="height: 100%; min-height: 500px"></div>
9+
<script>
10+
const map = new L.Map('my-map').setView([0, 0], 2);
11+
L.tileLayer(`https://tile.jawg.io/jawg-sunny/{z}/{x}/{y}.png?access-token=<YOUR_ACCESS_TOKEN>`, {
12+
attribution:
13+
'<a href="http://jawg.io" title="Tiles Courtesy of Jawg Maps" target="_blank" class="jawg-attrib">&copy; <b>Jawg</b>Maps</a> | <a href="https://www.openstreetmap.org/copyright" title="OpenStreetMap is open data licensed under ODbL" target="_blank" class="osm-attrib">&copy; OSM contributors</a>',
14+
maxZoom: 22,
15+
}).addTo(map);
16+
const jawgPlaces = new JawgPlaces.Leaflet({
17+
searchOnTyping: true,
18+
reverse: true,
19+
layers: 'coarse',
20+
L,
21+
});
22+
map.addControl(jawgPlaces);
23+
map.on('click', ({ latlng }) => {
24+
jawgPlaces.setValue(`${latlng.lat.toFixed(5)} ${latlng.lng.toFixed(5)}`);
25+
jawgPlaces.submit();
26+
});
27+
</script>
28+
</body>
29+
</html>
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<html>
2+
<head>
3+
<script src="https://api.jawg.io/libraries/jawg-places@latest/jawg-places.js?access-token=<YOUR_ACCESS_TOKEN>"></script>
4+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/maplibre-gl@4.7.1/dist/maplibre-gl.min.css" />
5+
<script src="https://cdn.jsdelivr.net/npm/maplibre-gl@4.7.1/dist/maplibre-gl.min.js"></script>
6+
</head>
7+
<body>
8+
<div id="my-map" style="height: 100%; min-height: 500px"></div>
9+
<script>
10+
const map = new maplibregl.Map({
11+
container: 'my-map',
12+
style: `https://api.jawg.io/styles/jawg-sunny.json?access-token=<YOUR_ACCESS_TOKEN>`,
13+
center: [0, 0],
14+
zoom: 1,
15+
});
16+
const jawgPlaces = new JawgPlaces.MapLibre({
17+
searchOnTyping: true,
18+
reverse: true,
19+
layers: 'coarse',
20+
});
21+
map.addControl(new maplibregl.NavigationControl());
22+
map.addControl(jawgPlaces);
23+
map.on('click', ({ lngLat }) => {
24+
jawgPlaces.setValue(`${lngLat.lat.toFixed(5)} ${lngLat.lng.toFixed(5)}`);
25+
jawgPlaces.submit();
26+
});
27+
</script>
28+
</body>
29+
</html>

0 commit comments

Comments
 (0)
Please sign in to comment.