1

How to do after a search, zoom in on the value found on the map? My code is:

$("#txtSearch").autocomplete({
    source: setoresComerciais.features.map(function(d){
        return d.properties.sco_num_sc + " - " + d.properties.sco_dsc_loc
    }),
    select: function(event, ui){
        map.fitBounds(stComerciaisLayer.getBounds(ui.item.value));
    } 
});

First, I get return d.properties.sco_num_sc + " - " + d.properties.sco_dsc_loc, this return, for example: 1 - FORTALEZA After, I use select, where have the param ui, when do ui.item.value return 1 - FORTALEZA, so this:

map.fitBounds(stComerciaisLayer.getBounds(ui.item.value));

Where:

stComerciaisLayer = L.geoJSON(setoresComerciais, {
                style: function (feature) {
                    return feature.properties && feature.properties.style;
                },
                onEachFeature: onEachFeature,
(...)

It was to return exactly what I wanted, the result of the search and the zoom in it, but don't work. What did I do wrong?

closed as off-topic by IvanSanchez, aldo_tapia, whyzar, BERA, HDunn Nov 23 '17 at 13:13

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions relating to general IT or with no clear GIS component, are off-topic here but can be researched/asked at Stack Overflow (software development), Super User (computing hardware and software), Database Administrators (relational databases) and other SE sites" – IvanSanchez, aldo_tapia, whyzar, BERA, HDunn
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Seriously, no clear GIS component? This was an issue with Leaflet JS, search and zoom. How many other software packages that are not GIS, zoom to a GeoJSON feature. The other sites would throw it back to GIS. – Bill Chappell Nov 28 '17 at 15:54
1

I didn't see enough code above to troubleshoot, but I may be able to help.

Here is a write up and example I created for a class. My clue was tagging the layer._leaflet_id with the a feature attribute, then using this as my search results value, which happens in your onEachFeature function.

Hope this helps explain it: http://www.gistechsolutions.com/leaflet/DEMO/Search/index.html

Working example: http://www.gistechsolutions.com/leaflet/DEMO/Search/SearchState.html

  • Thank you so much!! That's exactly what I needed. I searched a lot and did not find an example like I wanted, but this will work! – Elton Santos Nov 22 '17 at 17:56

Not the answer you're looking for? Browse other questions tagged or ask your own question.