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

react-leaflet-search-unpolyfilled

v0.1.0

Published

React component for search lat lng on leaflet

Downloads

349

Readme

react-leaflet-search

A React component for searching places or global coordinates on leaflet

Both react-leaflet v1 and v2 are supported.

With v2 you should wrap this component in the withLeaflet method

const wrappedZoomIndicator = withLeaflet(ReactLeafletZoomIndicator)

and then use a wrappedZoomIndicator component as child of the Map component.

Install

npm install react-leaflet-search

Don't forget to add the stylesheet to your project. It can be found in both the src/ and lib/ folders

Usage

import { ReactLeafletSearch } from 'react-leaflet-search'

This component should be a child to react-leaflet's map component:

const searchComponent = props => (
  <ReactLeafletSearch position="topleft" />
)

Search providers

There are 2 search providers, but with scope for adding more. The default provider is OpenStreetMap. If you want to use BingMap as a provider, it can be done as follows:

const searchComponent = props => (
  <ReactLeafletSearch
            position="topleft"
            provider="BingMap"
            providerKey="{BINGMAP_KEY}" />
)

You can pass in provider-specific options using the providerOptions prop:

const searchComponent = props => (
  <ReactLeafletSearch
            position="topleft"
            provider="OpenStreetMap"
            providerOptions={{region: 'gb'}} />
)

Search Result Marker

To change the marker icon, use the markerIcon prop:

const myIcon = L.icon({
    iconUrl: 'marker-icon.png',
    iconRetinaUrl: 'marker-icon-2x.png',
    shadowUrl: 'marker-shadow.png',
    iconSize: [25, 41],
    iconAnchor: [12, 41],
    popupAnchor: [1, -34],
    tooltipAnchor: [16, -28],
    shadowSize: [41, 41]
});

<ReactLeafletSearch position="topleft" markerIcon={ myIcon }/>

To change the Popup displayed by the marker, use the popUp prop:

myPopup(SearchInfo) {
  return(
    <Popup>
      <div>
        <p>I am a custom popUp</p>
        <p>latitude and longitude from search component: lat:{SearchInfo.latLng[0]} lng:{SearchInfo.latLng[1]}</p>
        <p>Info from search component: {SearchInfo.info}</p>
        <p>{JSON.stringify(SearchInfo.raw)}</p>
      </div>
    </Popup>
  );
}

<ReactLeafletSearch position="topleft" popUp={ myPopup }/>

Other props which can be set on the ReactLeafletSearch component

Other aspects can be customized as well:

<ReactLeafletSearch
  position="topleft"
  inputPlaceholder="The default text in the search bar"
  search={[]} // Setting this to [lat, lng] gives initial search input to the component and map flies to that coordinates, its like search from props not from user
  zoom={7} // Default value is 10
  showMarker={true}
  showPopup={false}
  openSearchOnLoad={false} // By default there's a search icon which opens the input when clicked. Setting this to true opens the search by default.
  closeResultsOnClick={false} // By default, the search results remain when you click on one, and the map flies to the location of the result. But you might want to save space on your map by closing the results when one is clicked. The results are shown again (without another search) when focus is returned to the search input.
  searchBounds={[]} // The BingMap and OpenStreetMap providers both accept bounding coordinates in [se,nw] format. Note that in the case of OpenStreetMap, this only weights the results and doesn't exclude things out of bounds.
  customProvider={false} // see examples to usage details until docs are ready
/>

Info about search input

It has two modes:

  • Search for latitude,longitude as numbers
  • Search for a place with its name, city, country, street etc.

To search with global coordinates, the search input should start with the ':' character and should respect the following format: :{LATITUDE},{LONGITUDE}

You can play with the demo

DEMO

React-Leaflet v2 Demo