New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

leaflet-control-geocoder

Package Overview
Dependencies
Maintainers
2
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

leaflet-control-geocoder

Extendable geocoder with builtin support for OpenStreetMap Nominatim, Bing, Google, Mapbox, MapQuest, What3Words, Photon, Pelias, HERE, Neutrino, Plus codes

  • 1.12.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.7K
decreased by-80.35%
Maintainers
2
Weekly downloads
 
Created
Source

A few words on diversity in tech

I need to take some of your time. I can't believe we let shit like the Kathy Sierra incident or what happened to Brianna Wu happen over and over again. I can't believe we, the open source community, let sexist, misogynous shit happen over and over again.

I strongly believe that it is my — and your — duty to make the open source community, as well as the tech community at large, a community where everyone feel welcome and is accepted. At the very minimum, that means making sure the community and its forums both are safe, and are perceived as safe. It means being friendly and inclusive, even when you disagree with people. It means not shrugging off discussions about sexism and inclusiveness with handwaving about censorship and free speech. For a more elaborate document on what that means, the NPM Code of Conduct is a good start, Geek Feminism's resources for allies contains much more.

While I can't force anyone to do anything, if you happen to disagree with this, I ask of you not to use any of the open source I have published. Nor am I interested in contributions from people who can't accept or act respectfully towards other humans regardless of gender identity, sexual orientation, disability, ethnicity, religion, age, physical appearance, body size, race, or similar personal characteristics. If you think feminism, anti-racism or the LGBT movement is somehow wrong, disturbing or irrelevant, I ask you to go elsewhere to find software.

Leaflet Control Geocoder NPM version Leaflet 1.0.0 compatible!

A simple geocoder for Leaflet that by default uses OSM/Nominatim.

The plugin supports many different data providers:

The plugin can easily be extended to support other providers. Current extensions:

Demos

Usage

Download latest release, or obtain the latest release via unpkg.com:

<link rel="stylesheet" href="https://unpkg.com/leaflet-control-geocoder/dist/Control.Geocoder.css" />
<script src="https://unpkg.com/leaflet-control-geocoder/dist/Control.Geocoder.js"></script>

Add the control to a map instance:

var map = L.map('map').setView([0, 0], 2);
L.tileLayer('https://{s}.tile.osm.org/{z}/{x}/{y}.png', {
  attribution: '&copy; <a href="https://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
L.Control.geocoder().addTo(map);

Customizing

By default, when a geocoding result is found, the control will center the map on it and place a marker at its location. This can be customized by listening to the control's markgeocode event. To remove the control's default handler for marking a result, set the option defaultMarkGeocode to false.

For example:

var geocoder = L.Control.geocoder({
  defaultMarkGeocode: false
})
  .on('markgeocode', function(e) {
    var bbox = e.geocode.bbox;
    var poly = L.polygon([
      bbox.getSouthEast(),
      bbox.getNorthEast(),
      bbox.getNorthWest(),
      bbox.getSouthWest()
    ]).addTo(map);
    map.fitBounds(poly.getBounds());
  })
  .addTo(map);

This will add a polygon representing the result's boundingbox when a result is selected.

API

L.Control.Geocoder

This is the geocoder control. It works like any other Leaflet control, and is added to the map.

Constructor

This plugin supports the standard JavaScript constructor (to be invoked using new) as well as the class factory methods known from Leaflet:

new L.Control.Geocoder(options);
// or
L.Control.geocoder(options);

Options

OptionTypeDefaultDescription
collapsedBooleantrueCollapse control unless hovered/clicked
expandString"touch"How to expand a collapsed control: touch or click or hover
positionString"topright"Control position
placeholderString"Search..."Placeholder text for text input
errorMessageString"Nothing found."Message when no result found / geocoding error occurs
iconLabelString"Initiate a new search"Accessibility label for the search icon used by screen readers
geocoderIGeocodernew L.Control.Geocoder.Nominatim()Object to perform the actual geocoding queries
showUniqueResultBooleantrueImmediately show the unique result without prompting for alternatives
showResultIconsBooleanfalseShow icons for geocoding results (if available); supported by Nominatim
suggestMinLengthNumber3Minimum number characters before suggest functionality is used (if available from geocoder)
suggestTimeoutNumber250Number of milliseconds after typing stopped before suggest functionality is used (if available from geocoder)
queryString""Initial query string for text input
queryMinLengthNumber1Minimum number of characters in search text before performing a query

Methods

MethodReturnsDescription
markGeocode(<GeocodingResult> result)thisMarks a geocoding result on the map
setQuery(<String> query)thisSets the query string on the text input

L.Control.Geocoder.Nominatim

Uses Nominatim to respond to geocoding queries. This is the default geocoding service used by the control, unless otherwise specified in the options. Implements IGeocoder.

Unless using your own Nominatim installation, please refer to the Nominatim usage policy.

Constructor

new L.Control.Geocoder.Nominatim(options);
// or
L.Control.Geocoder.nominatim(options);

Options

OptionTypeDefaultDescription
serviceUrlString"https://nominatim.openstreetmap.org/"URL of the service
geocodingQueryParamsObject{}Additional URL parameters (strings) that will be added to geocoding requests; can be used to restrict results to a specific country for example, by providing the countrycodes parameter to Nominatim
reverseQueryParamsObject{}Additional URL parameters (strings) that will be added to reverse geocoding requests
htmlTemplatefunctionspecialA function that takes an GeocodingResult as argument and returns an HTML formatted string that represents the result. Default function breaks up address in parts from most to least specific, in attempt to increase readability compared to Nominatim's naming

L.Control.Geocoder.Bing

Uses Bing Locations API to respond to geocoding queries. Implements IGeocoder.

Note that you need an API key to use this service.

Constructor

new L.Control.Geocoder.Bing(<String>key);
// or
L.Control.Geocoder.bing(<String>key);

L.Control.Geocoder.OpenCage

Uses OpenCage Data API to respond to geocoding queries. Implements IGeocoder.

Note that you need an API key to use this service.

Constructor

new L.Control.Geocoder.OpenCage(<String>key, options);
// or
L.Control.Geocoder.opencage(<String>key, options);

Options

OptionTypeDefaultDescription
serviceUrlString"https://api.opencagedata.com/geocode/v1/json"URL of the service
geocodingQueryParamsObject{}Additional URL parameters (strings) that will be added to geocoding requests
reverseQueryParamsObject{}Additional URL parameters (strings) that will be added to reverse geocoding requests

L.Control.Geocoder.LatLng

Parses basic latitude/longitude strings such as '50.06773 14.37742', 'N50.06773 W14.37742', 'S 50° 04.064 E 014° 22.645', or 'S 50° 4′ 03.828″, W 14° 22′ 38.712″'.

Constructor

new L.Control.Geocoder.LatLng(options);
// or
L.Control.Geocoder.latLng(options);

Options

OptionTypeDefaultDescription
nextIGeocoderThe next geocoder to use for non-supported queries.
sizeInMetersNumber10000The size in meters used for passing to LatLng.toBounds.

IGeocoder

An interface implemented to respond to geocoding queries.

Methods

MethodReturnsDescription
geocode(<String> query, callback, context)GeocodingResult[]Performs a geocoding query and returns the results to the callback in the provided context
suggest(<String> query, callback, context)GeocodingResult[]Performs a geocoding query suggestion (this happens while typing) and returns the results to the callback in the provided context
reverse(<L.LatLng> location, <Number> scale, callback, context)GeocodingResult[]Performs a reverse geocoding query and returns the results to the callback in the provided context

GeocodingResult

An object that represents a result from a geocoding query.

Properties

PropertyTypeDescription
nameStringName of found location
bboxL.LatLngBoundsThe bounds of the location
centerL.LatLngThe center coordinate of the location
iconStringURL for icon representing result; optional
htmlString(optional) HTML formatted representation of the name

Keywords

FAQs

Package last updated on 22 Feb 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc