0

I have developed an application using leaflet JS, which loads the services from the ArcGIS server via REST API.

I want to put a search box to search by cities. Should I load a base map to be able to search? How should I configure the search box?

1 Answer 1

2

You can use leaflet-control-geocoder in order to do that, all you have to do is include it in your JS code.

var map = L.map('map').setView([0, 0], 2);
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
    attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
L.Control.geocoder().addTo(map);
5
  • Should I load the base map for that?
    – Leeloo
    Commented May 31, 2018 at 8:58
  • No, you only need a leaflet map Commented May 31, 2018 at 9:18
  • Does it work as Lat/long search?
    – Leeloo
    Commented May 31, 2018 at 12:13
  • @Leeloo yes it does support reverse geocoding by using the method reverse(<L.LatLng> location, <Number> scale, callback, context) Commented May 31, 2018 at 13:22
  • Thank you. Could you show an example of usage?
    – Leeloo
    Commented May 31, 2018 at 13:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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