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());
});
Solved! Go to Solution.
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"
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"
Thanks Gavin. I had to make it a global variable and use parseFloat to convert from string to integer. I have another question though about how to use onEachFeature to get the attribute for all features when using query.run. I will post it later.