npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@sjaakp/leaflet-search

v1.0.2

Published

Search Control for Leaflet

Downloads

1,058

Readme

Leaflet-search

Search Control for Leaflet

Leaflet-search is a Search Control for the Leaflet open source JavaScript map library. It makes use of one of several geocoding services.

A demo of Leaflet-search is here.

Here is Leaflet-search's GitHub page.

Installing

Install Leaflet-search with npm:

npm i @sjaakp/leaflet-search

You can also manually install Leaflet-search by downloading the source in ZIP-format.

Apart from Leaflet itself, Leaflet-search has no dependencies. There is no need to load jQuery or other libraries (though it won't hurt).

Usage

A minimum HTML page with a Leaflet-search would look something like this:

<html>
<head>
    <link href="//unpkg.com/leaflet/dist/leaflet.css" rel="stylesheet">
</head>
<body>

	<div id="m"></div>

	<script src="//unpkg.com/leaflet/dist/leaflet.js"></script>
	<script src="leaflet-search.js"></script>

	<script>
		var map = L.map("m" /* , { ... map options ... } */);
		map.setGeocoder('Nominatim' /* , { ... Geocoder options ... } */);
		map.addControl(L.control.search({ ... Search options ...}));
	</script>
</body>
</html>

The assets for Leaflet are loaded, as well as those for Leaflet-search (a single js-file). A Leaflet Map is initialized. The Leaflet map now has a new method:

  • setGeocoder(<string> name, <Object> options?) Set the geocoder with options. Return: this.

CDN

Leaflet-search is available on the unpkg Content Delivery Network, so you don't have to host the leaflet-search.js file on your own server. In this case, the Leaflet-search can be loaded like this:

<script src="//unpkg.com/@sjaakp/leaflet-search/dist/leaflet-search.js"></script>

L.Control.Search

Leaflet-search defines a new Leaflet Control: L.Control.Search. It places a button on the map, which expands to a text input field that accepts free-form addresses.

L.Control.Search inherits the position property from L.Control. Following the Leaflet-habit, a new L.Control.Search can be created by L.control.search(<options>), so adding Leaflet-search to a Map boils down to:

map.addControl(L.control.search({ position: 'bottomright' });

Geocoder

Leaflet-search retrieves its information from a geocoding service. The service is initialized by:

map.setGeocoder('<geocoder name>', { <geocoder options> });

Generally, options will be empty, apart from the API Key some providers expect, and which often can be obtained free of charge. Other options may be added.

Currently, Leaflet-search supports the following providers (there may be more in the future):

|Name| |Required option| |----|---|------------| |Nominatim|free, by OpenStreetMap| | |GeoNames|free|{ username: '...' } | |Here|commercial|{ apiKey: '...' } | |TomTom|commercial|{ key: '...' } | |Kadaster|Netherlands only| |

Notice that some providers may stipulate that you should use their service only on map tiles of the same provider.

If you don't explicitly set a geocoder, Leaflet-search uses Nominatim.