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

leaflet-geocoder-ban

v1.0.7

Published

A simple Leaflet Plugin to add a geocoding control to your map, powered by the french [BAN](https://adresse.data.gouv.fr/) (Base Adresse Nationale) API. This API only covers French addresses.

Downloads

1,430

Readme

leaflet-geocoder-ban NPM version Leaflet 1.0.0 compatible!

A simple Leaflet Plugin to add a geocoding control to your map, powered by the french BAN (Base Adresse Nationale) API. This API only covers French addresses.

Check the online demos : demo1 and demo2.

Installation

You can either:

  • install with npm npm install --save leaflet-geocoder-ban

or

  • clone the git repository

Usage

First, load the leaflet files as usual.

Then, load the two leaflet-geocoder-ban files : the js and the css.

They are located in the src folder and minified versions are provided in the dist folder. You can load them directly in your html page :

<script src="leaflet-geocoder-ban.js"></script>
<link rel="stylesheet" href="leaflet-geocoder-ban.css">

In your javascript code, create a Leaflet map:

var map = L.map('mapid').setView([45.853459, 2.349312], 6)

L.tileLayer("https://cartodb-basemaps-{s}.global.ssl.fastly.net/light_all/{z}/{x}/{y}.png", {
attribution: 'map attribution'}).addTo(map)

And add the geocoder:

var geocoder = L.geocoderBAN().addTo(map)

Options

You can pass some options to the geocoderBAN() function:

| option | type | default | description |----------------------------|-------------|--------------|-----------------| | position | string | 'topleft' | Control position | | placeholder | string | 'adresse' | Placeholder of the text input | | resultsNumber | integer | 7 | Default number of address results suggested | | collapsed | boolean | true | Initial state of the control, collapsed or expanded | | autofocus | boolean | true | If the initial state of the control is expanded, choose wether the input is autofocused on page load| | serviceUrl | string | 'https://api-adresse.data.gouv.fr/search/' | API of the url | minIntervalBetweenRequests |integer | 250 | delay in milliseconds between two API calls made by the geocoder | | style | string | 'control' | style of the geocoder, either 'control' or 'searchBar'. See the two demos page. |

example

var options = {
  position: 'topright',
  collapsed: 'false'
}

var geocoder = L.geocoderBAN(options).addTo(map)

Custom markgeocode function

When you select a result on the geocoder, it calls a default markGeocode function. If you want to call a custom function, override it. It receives as argument the result given by the BAN API as described here

var geocoder = L.geocoderBAN({ collapsed: true }).addTo(map)

geocoder.markGeocode = function (feature) {
  var latlng = [feature.geometry.coordinates[1], feature.geometry.coordinates[0]]
  map.setView(latlng, 14)

  var popup = L.popup()
    .setLatLng(latlng
    .setContent(feature.properties.label)
    .openOn(map)
  }
})

Methods

| method | description | |------------------|-----------------------------| | remove() | removes the geocoder |

Those methods are only available for the 'control' style (and not for the 'searchBar' style):

| method | description | |------------------|-----------------------------| | collapse() | collapses the geocoder | | expand() | expands the geocoder | | toggle() | toggles between expanded and collapsed state |

example

var geocoder = L.geocoderBAN().addTo(map)

map.on('contextmenu', function () {
  geocoder.toggle()
})

Customize the search bar look

Customization of the search bar CSS is available through the searchBar class. For example :

.searchBar {
  border: 1px solid red !important;
  max-width: 500px;
}