Leaflet.Geonames
A GeoNames powered geocoding search control for Leaflet.
It allows you to enter a placename, display a list of search results using GeoNames, and select a placename to zoom to.
Location markers remain on the map until the search field is cleared.
Click on icon to open / close unless alwaysOpen
is set to true (in which case clicking on the icon does nothing).
*Tested with Leaflet 1.1.0
Install
From NPM:
npm install leaflet-geonames
Usage
Include the CSS:
This control uses Google Material Icons by default.
Include the JavaScript:
Example usage:
var control = Lcontrol;map;
For mobile responsive view, use position: 'topcenter'
and alwaysOpen: true
options.
See mobile example
using a mobile device or emulator.
Events
Search Event
This control fires a search
event with the value of search parameters:
control.on('search', function(e){console.log(e.params)});
results in
{q: "oregon", lang: "en"}
Select Event
This control fires a select
event when an option was selected from list,
with the full response JSON from geonames:
control.on('select', function(e){console.log(e.geoname)});
results in
{adminCode1: "OR", lng: "-120.50139", geonameId: 5744337, ...}
Demos:
Changes
See changelog
Credits:
Developed with support from the South Atlantic Landscape Conservation Cooperative, and maintained with support from Peninsular Florida LCC.
Some ideas derived from L.GeoSearch.