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

typeahead-address-photon

v1.1.0

Published

Address picker built with typeahead autocomplete using https://photon.komoot.io/

Downloads

106

Readme

typeahead-address-photon npm

Copy of famous typeahead-addresspicker but using free and Open-Source place search service https://photon.komoot.io/.

Provides PhotonAddressEngine, an implementation of suggestions engine Bloodhound (from corejs-typeahead).

Plugin provides convinient hooks if you wanna make other processing of suggested places, rather than only show them in the drop-down list of typeahead. For example, you can choose to pin markers on Leaflet map in suggested places while typing.

Note

corejs-typeahead is maintained fork of original twitter typeahead. It's strongly recommended to switch on corejs-typeahead if you still use the old one.

Demo

Check out the demo.

How to use

Include jQuery, corejs-typeahead & typeahead-address-photon on your page :

<script src="node_modules/jquery/dist/jquery.js"></script>
<script src="node_modules/corejs-typeahead/dist/typeahead.bundle.js"></script>
<script src="node_modules/typeahead-address-photon/dist/bundle.js"></script>

Add text input for address :

<input id="inpAddress" type="text" placeholder="Enter address here..."></input>

Instanciate PhotonAddressEngine and Typeahead :

var engine = new PhotonAddressEngine();

$('#inpAddress').typeahead(null, {
  source: engine.ttAdapter(),
  displayKey: 'description'
});

Options

PhotonAddressEngine constructor accepts object with options. The following options can be provided :

  • url - URL of the Photon API to use. Default: 'https://photon.komoot.io'
  • limit - limit number of results. Default: 5
  • formatResult - function to control the way geojson features are displayed in the results box
  • formatType - function to control the way features types (amenity, school, etc.) are displayed in the default formatResult function
  • lat, lon - latitude and longitude to make search with priority to a geo position
  • lang - preferred language

Events

Instance of PhotonAddressEngine can trigger two kind of events that allows you make your own processing of fetched OSM features.

  • addresspicker:selected - triggered when user selects one of suggestions, has OSM feature corresponding to selected place as parameter
  • addresspicker:predictions - triggered when suggestions are fetched for provided request, has all fetched OSM features as parameter

You can subscribe for those events as following :

$(engine).bind('addresspicker:selected', function (event, selectedPlace) {
  // Process selected place here ...
});

$(engine).bind('addresspicker:predictions', function (event, suggestions) {
  // Process all suggestions here ...
});

Reverse geocoding

Reverse geocoding allows to fetch places by geographic coordinates rather than by text query. This feature can be usefull when working with Leaflet map. For example, user drags marker and address input is automatically updated with new place. To do reverse geocoding use method PhotonAddressEngine.reverseGeocode([lat, lon]) that accepts array with coordinates and triggers event addresspicker:selected with first suggested result. Use it as following :

$(engine).bind('addresspicker:selected', function (event, selectedPlace) {
  // Process selected place here ...
});
...
engine.reverseGeocode([ pos.lat, pos.lng ]);