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-with-many-plugins

v1.0.1

Published

A leaflet map with many plugins

Downloads

11

Readme

react-leaflet-with-many-plugins

This package is a customized version of leaflet in react framework.

You can report any questions, problems, development requests by opening an issue.

Usage

To use the Map Component in your project, follow these steps:

  1. Install the package by running the following command:

    npm install react-leaflet-with-many-plugins
  2. Add the MapContainer component to your project:

    import MapContainer from 'react-leaflet-with-many-plugins';
  3. Use the MapContainer component in your code:

    const App = () => {
        return (
            <div>
                <h1>My Map Component</h1>
                <MapContainer />
            </div>
        );
    };
    
    export default App;

    Props

    The MapContainer component accepts the following props:

    | Prop | Default | Type
    |----------|---|----------| | mapProps | ✔ | object | | tileLayerProps | ✔ | object| |zoomLayerProps|✔|object| | markers | ❌ | array | | polylineProps|❌| object | | multiPolylineProps|❌|object | | geomanControl|❌|bool | | geomanControlProps|❌|object |

Default Props

const mapProps = {
  center: [37.874641, 32.493156],
  zoom: 13,
  zoomControl: false,
  scrollWheelZoom: true,
};

const tileLayerProps = {
  // attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
  url: 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
};

const zoomLayerProps = {
  position: 'bottomright',
  zoomInText: '+',
  zoomOutText: '-',
  zoomInTitle: 'Zoom in',
  zoomOutTitle: 'Zoom out',
};

Override Props

// for example if we want to override the 'center' prop
const mapProps = {
  center: [37.874641, 32.493156],
};

//Usage
<MapContainer  mapProps={mapProps} />

Create Marker Groups

  • The eventhandler prop has been customized. With the second parameter that you will give to each event in the eventhandler, you will be able to process the item that points to that marker.The eventhandler prop has been customized. With the second parameter that you will give to each event in the eventhandler, you will be able to process the item that points to that marker.

  • You can handle position and icon field in the same way

// This array includes markers object. Each object reference a marker group
import marker from './images/marker-icon.png';
import markerShadow from './images/marker-shadow.png';
import { renderToStaticMarkup } from 'react-dom/server';



const locToLangLong = (item) => [item.latitude, item.longitude];

const vehicles = [
  {
    vehiclePlate: '42C16',
    latitude: 37.9570187,
    longitude: 32.5903961,
  },
  {
    vehiclePlate: '42C106',
    latitude: 37.9568287,
    longitude: 32.5903961,
  },
];


const Car=({vehicle})=>(
  <div className="absolute top-0 bg-[#304564] border-white border-[1px] -mt-5 text-white px-1 color rounded-md">
  {vehicle.vehiclePlate}
</div>)

  const divIcons = {
  car: (vehicle) => {
    return divIcon({
      html: renderToStaticMarkup(<Car vehicle={vehicle} />),
      iconAnchor: [25, 57],
      iconSize: [50, 57],
      className: '',
    });
  },
};

const markers = [
    {
      items: vehicles,
      tooltip: {
        content: <ExamplePopup />,
        props: {
          direction: 'bottom',
          offset: [0, 73],
          opacity: 1,
          permanent: false,
        },
      },
      icon: function (item) {
        return L.icon({
        iconUrl: marker,
        iconSize: [25, 41],
        iconAnchor: [12.5, 41],
        shadowUrl: markerShadow,
        shadowSize: [41, 41],
        shadowAnchor: [12, 41],
        });
      },
      position: function (item) {
        return locToLangLong(item);
      },
      eventHandlers: {
        click: (event, item) => {
          console.log('clickEvent', event, item);
        },
      },
      markerCluster: true,
      responsivePopup: false,
    },
     {
      items: vehicles,
      popup: {
        content: <ExamplePopup />,
        props: {
          offset: [0, 73],
          opacity: 1,
          permanent: false,
        },
      },
      icon: function (item) {
        return L.icon({
        iconUrl: marker,
        iconSize: [25, 41],
        iconAnchor: [12.5, 41],
        shadowUrl: markerShadow,
        shadowSize: [41, 41],
        shadowAnchor: [12, 41],
        });
      },
      position: function (item) {
        return locToLangLong(item);
      },
      eventHandlers: {
        click: (event, item) => {
          console.log('clickEvent', event, item);
        },
      },
      markerCluster: true,
      responsivePopup: false,
    },
  ];

  
  function ExamplePopup() {
  return <div>examplePopup</div>;
  }

  //Usage
  <Mapcontainer 
  markers={markers}
  />

Create Other Layers

const multiPolylineData = [
  [
    [37.8716, 32.4849],
    [37.8717, 32.485],
    [37.8718, 32.4851],
  ],
  [
    [37.8718, 32.4851],
    [37.8719, 32.4852],
    [37.872, 32.4853],
  ],
  [
    [37.882, 32.4853],
    [37.8721, 32.4854],
    [37.8722, 32.4855],
  ],
];
const multiPolylineProps = {
  pathOptions: {
    color: 'red',
  },
  positions: multiPolylineData,
};
const polylineData = [
  [37.9568287, 32.5903961],
  [37.8816, 32.4849],
  [37.8916, 32.4849],
];
const polylineProps = {
  pathOptions: {
    color: 'black',
  },
  positions: polylineData,
};

//Usage
  return (<>
  <MapContainer 
    polylineProps={polylineProps}
    multiPolylineProps={multiPolylineProps}
  >
  </>)

Create Geoman Control Layer And Handle Events

Suppport all free geoman events geoman docs

 const  geomanControlProps={{
    onCreated: (event) => {
      console.log('onCreated', event);
    },
  }}

  //usage 
  return (
    <MapContainer 
    geomanControl
    geomanControlProps={geomanControlProps}
  />
  )

Extension Knowledge

The MapContainer component supports the following extensions:

| Extension | Description | |-----------|-------------| | Geoman | added | | Marker Cluster | added | | Responsive Popup | added | | Polyline Mesaure | adding |