What is the best way to implement a search functionality into an OL3 map?
I need a search input that will show me a few options while searching and then pan and zoom to the specific search term. Pretty much like google maps do.
Do I need to integrate google maps into my OL3?
OpenLayers makes it easy to put a dynamic map in any web page. It can display map tiles, vector data and markers loaded from any source. OpenLayers has been developed to further the use of geographic information of all kinds.
Use the layer switcher menu at the top right to select and explore different basemap layer styles.
There's no native Search/Geocoder in Openlayers 3. But you can use the ol-geocoder extension (I've wrote it) to address this need.
The instructions are at the provided link. I just want to show how I generally use it:
//Instantiate with some options and add the Control
var geocoder = new Geocoder('nominatim', {
provider: 'google',
lang: 'pt-BR',
placeholder: 'Pesquise por um endereço',
limit: 5,
key: '....',
keepOpen: false,
debug: true
});
map.addControl(geocoder);
// I don't want/need Geocoder layer to be visible
geocoder.getLayer().setVisible(false);
//Listen when an address is chosen
geocoder.on('addresschosen', function(evt){
var feature = evt.feature;
var coord = evt.coordinate;
// application specific
app.addMarker(feature, coord);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With