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

niwa-location-picker

v1.5.33

Published

Downloads

125

Readme

NIWA Location Picker

Alt text

After install add the styles styles.css found in the src folder to your project.

Create a new instance of the location picker. The country code is optional.

const picker = new LocationPicker('nz');

Events

To subscribe to an event triggered by the location picker follow this general idea and replace the event with the one that you are interested in.


const locationPicker = new LocationPicker('body');

locationPicker.addEventListener('BROWSER_GEOLOCATED',(pos)=> {
    console.log('pos', pos)
})
BROWSER_GEOLOCATED

This event is being triggered when the Browser API (HTML5) was used to find the location of the user. This can happen at the beginning when the page loads or the clicks on the geolocate button.

MAP_CENTERED_ON_LONLAT

This event is being triggered after a succesfull search for the entered Longitude / Latitude in the search field.

MAP_CENTERED_ON_ADDRESS

This event is being triggered after a succesfull search for the entered place / address.

CLICKED_ON_LONLAT

This event is being triggered after clicking on the map. It will return the lon/lat for the click event.

Adding / removing markers

addMarker

To add a marker to the map execute the addMarker method. The method returns an object of class 'Feature' (Openlayers). If you want to delete this marker later on you will need to keep track of it (e.g. sticking it into an array)

addMarker(lon, lat, url[optional])
const locationPicker = new LocationPicker('body');
const marker = locationPicker.addMarker(174.763336, -40.848461, '#ff0000');

The 'addMarker' method also has a third parameter url where a url to an icon can be set.

const locationPicker = new LocationPicker('body');
const marker = locationPicker.addMarker(174.763336, -40.848461, '#ff0000','/assts/icon.png');

When an URL is provided it overrules the color parameter.

removeMarker

To remove a marker from the map hand in the marker to the removeMarker method. The marker needs to be an Openlayers Feature object.

(See 'addMarker' above).


locationPicker.removeMarker(Marker)

fitFeaturesIntoView

This method expects an array of Features / Markers. It will then fit the view to show all markers

removeAllMarkers

This method removes all markers on the map.

getGeolocation

Return an Observable of type LonLat

Project setup

The project was set up with help of these guidelines https://webpack.js.org/guides/typescript/

The geolacting functionality is provided by Nominatim https://wiki.openstreetmap.org/wiki/Nominatim

Gotcha's

Since the update to openlayers 6, the map container must now have a height defined to render. This is set to 200px by default, but can be overridden by passing a numeric height value to the constructor, e.g.

const locationPicker = new LocationPicker('body', { height: 350 });

Index.ts Cheat sheet

This is for development only.

import {LocationPicker} from "./location-picker";
import './style.css';

const locationPicker = new LocationPicker('body');

locationPicker.addEventListener('BROWSER_GEOLOCATED', (pos) => {

    console.log('pos', pos.detail.msg);


});
locationPicker.addEventListener('MAP_CENTERED_ON_LONLAT', (pos) => {
    console.log('Lon Lat', pos.detail)
});
locationPicker.addEventListener('MAP_CENTERED_ON_ADDRESS', (pos) => {
    console.log('Lon Lat', pos.detail)
});


const marker1 = locationPicker.addMarker(160, -37, '#ff0000');
const marker2 = locationPicker.addMarker(120, -27, '#00ff00');
const marker3 = locationPicker.addMarker(160, -27, '#0000ff');
const marker4 = locationPicker.addMarker(120, -37, '#00ffff');

setTimeout(()=> {
    locationPicker.fitFeaturesIntoView([marker1, marker2, marker3, marker4])
}, 500)


setTimeout(()=> {
    locationPicker.removeAllMarkers();
}, 7000)