I would like to change the size of the circle when selecting a value in the dropdown menu. I can change the size of the circle by pressing enter again in the search bar but I want to do it automaticaly when selecting a new value.
I thought about emulate the enter key (folowing this : jquery (or pure js) simulate enter key pressed for testing) in the input box but I wasn’t able to make it work. Maybe someone have a better idea?
My code :
JavaScript
x
44
44
1
<html>
2
<head>
3
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.3.4/dist/leaflet.css" />
4
<link rel="stylesheet" href="https://unpkg.com/leaflet-geosearch@3.5.0/dist/geosearch.css" />
5
6
<script src="https://unpkg.com/leaflet@1.3.4/dist/leaflet.js"></script>
7
<script src="https://unpkg.com/leaflet-geosearch@3.5.0/dist/geosearch.umd.js"></script>
8
<script src="https://unpkg.com/leaflet-control-custom@1.0.0/Leaflet.Control.Custom.js"></script>
9
10
</head>
11
12
<body>
13
<div id="mapid" style="width: 1920px; height: 1018px;">
14
<script>
15
const carte = L.tileLayer('https://{s}.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png', { minZoom: 1, maxZoom: 18 });
16
const map = L.map('mapid', { layers: [carte], attributionControl: false, drawControl: true }).setView([46.73881, -1.10074], 6);
17
18
const geocodageAdresse = new GeoSearch.GeoSearchControl({
19
provider: new GeoSearch.OpenStreetMapProvider(),
20
});
21
22
map.addControl(geocodageAdresse);
23
24
L.control.custom({
25
position: 'topleft',
26
content: '<p>Circle size: ' +
27
'<select id="dist">' +
28
'<option value="0">0Km</option>' +
29
'<option value="5000">5Km</option>' +
30
'<option value="10000">10Km</option>' +
31
'</select></p>',
32
events: { click: function () { $("form").submit(); } }
33
}).addTo(map);
34
35
map.on("geosearch/showlocation", function (e) { radiusGPS(e); });
36
var geoCircle = L.circle();
37
function radiusGPS(e) {
38
var value = document.getElementById('dist').value;
39
map.removeLayer(geoCircle);
40
geoCircle = L.circle([e.location.y.toFixed(2), e.location.x.toFixed(2)], { radius: value }).addTo(map);
41
}
42
</script>
43
</body>
44
</html>
Advertisement
Answer
Solution:
You can add a change
listener and then change the radius with geoCircle.setRadius(value)