use variable for distance in esri leaflet nearby??

52
1
Saturday
Highlighted
New Contributor III

Hello:

How can I use a variable when using the nearby method on a query layer so the user can select the distance in a dropdown or is this not possible?

 

Here is a snippet of what I have:

HTML

<select id="buffer" name="buffer">
<option value="60.96">200 feet</option>
<option value="152.4">500 feet</option>
<option value="213.36">700 feet</option>
<option value="304.8">1000 feet</option>
</select>

JAVASCRIPT

var distance = document.getElementById("buffer").value;

 

function myFunction() {
if ((document.getElementById("pm1").checked == true) && (document.getElementById("tm1").checked == true)&& (document.getElementById("sr1").checked == true)){
pmquery.nearby(latlng, distance);

pmquery.run(function (error, featureCollection, response) {
if (error) {
console.log(error);
return;
}
L.geoJSON(featureCollection).addTo(map);
console.log('Found ' + featureCollection.features.length + ' features');
map.fitBounds(L.geoJSON(featureCollection).getBounds());
});

 

 

Tags (3)
Reply
0 Kudos
1 Reply
Highlighted
Esri Contributor

Yes that code looks like it should work. Make sure you check if your "distance" variable is actually defined within your function. You can use console.log to see if the value is defined. As a quick attempt, you could also move the line

var distance = document.getElementById("buffer").value;

 within your function "myFunction"

Tags (2)
Reply
0 Kudos