Git Product home page Git Product logo

react-leaflet-pixi-overlay's Introduction

react-leaflet-pixi-overlay

A react wrapper for the awesome Pixi Overlay: https://github.com/manubb/Leaflet.PixiOverlay. With the option to change tooltip ui display.

Installing

yarn add react-leaflet-pixi-overlay
react-leaflet react-leaflet-pixi-overlay
v2.x v1.0
v3.x v3.x

Example

import { TileLayer, MapContainer } from "react-leaflet";
import PixiOverlay from "react-leaflet-pixi-overlay";
import { renderToString } from "react-dom/server";
import "leaflet/dist/leaflet.css";
import "./app.css";

const App = () => {
  const markers = [
    {
      id: "randomStringOrNumber",
      iconColor: "red",
      position: [-37.814, 144.96332],
      popup: renderToString(<div>All good!</div>),
      onClick: () => alert("marker clicked"),
      tooltip: "Hey!",
    },
    {
      id: "2",
      iconColor: "blue",
      position: [-37.814, 144.96332],
      popup: "Quack!",
      popupOpen: true, // if popup has to be open by default
      onClick: () => alert("marker clicked"),
      tooltip: "Nice!",
    },
  ];

  return (
    <MapContainer
      zoom={18} // initial zoom required
      preferCanvas
      maxZoom={20} // required
      minZoom={3} // required
      center={[-37.814, 144.96332]}
      // Other map props...
    >
      <TileLayer
        attribution='&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
        url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
      />
      <PixiOverlay markers={markers} />
    </MapContainer>
  );
};

export default App;

Marker object props

Prop Required Comment
id yes String or Int; Unique marker ID
position yes Array
iconColor yes/no String (any valid html color); Required if not using customIcon.
popup no String or HTML parsed to String
popupOpen no Boolean. Determines if popup is open by default. Only 1 at a time.
onClick no Function
tooltip no String
customIcon no String
iconId yes/no String; Required only if using customIcon
markerSpriteAnchor no number[] useful for marker icon calibration ex: [0.5,1]
tooltipOptions no Leaflet.TooltipOptions -> { opacity: 0.5, offset: [0, 0], ... }

|

Result

Map

Custom Icon

const markers = [
  {
    id: "someIDUniqueToMarker",
    iconId: "someIDUniqueToIcon", // used for cache
    customIcon:
      '<svg style="-webkit-filter: drop-shadow( 1px 1px 1px rgba(0, 0, 0, .4));filter: drop-shadow( 1px 1px 1px rgba(0, 0, 0, .4));" xmlns="http://www.w3.org/2000/svg" fill="red" width="36" height="36" viewBox="0 0 24 24"><path d="M12 0c-4.198 0-8 3.403-8 7.602 0 6.243 6.377 6.903 8 16.398 1.623-9.495 8-10.155 8-16.398 0-4.199-3.801-7.602-8-7.602zm0 11c-1.657 0-3-1.343-3-3s1.342-3 3-3 3 1.343 3 3-1.343 3-3 3z"/></svg>',
  },
];

Contribution guidelines

To contribute to project codebase, fork the repo and create Pull Requests pointing to master branch.

Local setup

The best way to run and develop the package is to import the local clone to local react project. It can be done with help of yarn link functionality. All peer dependencies must be linked. Here is how to do it:

cd YOUR_CLONNED_REACT_LEAFLET_PIXI_OVERLAY_FORK
yarn link
yarn install
cd node_modules/react
yarn link
cd ../react-dom
yarn link
cd ../leaflet
yarn link
cd ../react-leaflet
yarn link

cd YOUR_REACT_PROJECT
yarn link react-leaflet-pixi-overlay
yarn link react
yarn link react-dom

To compile any changes introduced to code, run yarn build.

License

This project is licensed under the MIT License.

react-leaflet-pixi-overlay's People

Contributors

better-iris avatar dependabot[bot] avatar firflant avatar hugobarragon avatar knapcio avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

react-leaflet-pixi-overlay's Issues

Does it support polygon/mutli polygons/geojson

Thanks for your lib, the perf are really impressive.
I'm currently mixing "points" and other shapes on the same map
with

 <Map ....>
      <GeoJSON data={geometry} />
      <PixiOverlay markers={pointMarkers} />
</Map>

I'm hiting problems to handle/click popup to points on top of the GeoJSON between "layers".

  • click on marker => popup
  • click on polygon => draw the polygon in different style

For the moment only polygons are clickable (popup of pixi overlay markers don't shows up)
click-over-popup

When removing GeoJSON then points are handled

click-over-points

The readme shows "point" markers. Can the marker bundles geojson ?
Or are you aware of fixes to handle clicks between the 2 layers ?

Multiple overlays

    {markersArray.map(markers => (
                       <PixiOverlay markers={markers} />
                ))}

Getting
Error: Cannot add resources while the loader is running.
The ideas is to have a dynamic number of overlays based on your selection on parent component.
Any thoughts?

Error: Invalid hook call

Trying to reproduce the example, but getting this
Снимок экрана 2020-11-07 в 13 48 18

My code:

<Map className="g-height-500" center={[53.904017, 27.551284]} zoom={11} scrollWheelZoom={false}>
				{!!data?.crimeEvents.length && (
					<HeatmapLayer
						fitBoundsOnLoad
						fitBoundsOnUpdate
						points={data.crimeEvents}
						radius={23}
						longitudeExtractor={(m: CrimeEvent) => m.lg}
						latitudeExtractor={(m: CrimeEvent) => m.lt}
						intensityExtractor={(m: CrimeEvent) => m.c}
					/>
				)}
				<TileLayer
					attribution='&amp;copy <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
					url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
				/>
					<PixiOverlay
						markers={[
							{
								id: 'randomStringOrNumber',
								iconColor: 'red',
								position: [-37.814, 144.96332],
								tooltip: 'Hey!',
							},
							{
								id: '2',
								iconColor: 'blue',
								position: [-37.814, 144.96332],
								popup: 'Quack!',
								popupOpen: true, // if popup has to be open by default
								tooltip: 'Nice!',
							},
						]}
					/>
			</Map>

Can i specify svg custom icon saved on disk?

Hi, I'm trying to apply CustomIcon but don't know how.

Instead of <svg style=...></svg> I want to use /images/icons/computer2.svg which I have in my public folder.

When specifying custom leaflet icon, I can do this with:

const iconComputer = new L.Icon({
    iconUrl: `/images/icons/computer2.svg`,
    iconSize: [20, 20],
    iconAnchor: [10, 20],
  })

How can I apply this on pixi overlay?

const markers = [{
  position: [10, 10],
  id: 'someIDUniqueToMarker',
  iconId: 'someIDUniqueToIcon',  // used for cache
  customIcon: '<img src="/images/icons/computer2.svg" alt="My Computer">',
}],

Package improvements and contribution

Hi! I cloned the project and managed to run it locally. I noticed there is some space for improvements on the file structure in general:

1. react-dom depencency

react-dom is missing dev dependency. It results in a following error: Module not found: Error: Can't resolve 'react-dom' in '/Users/michal/Projects/react-leaflet-pixi-overlay/node_modules/react-leaflet/es'

2. Contribution and local setup guidelines
The best way to test a clonned react-leaflet-pixi-overlay before commiting any change is to import it and use on a local react project. It can be done with help of yarn link functionality. All peer dependencies must be linked:

cd YOUR_CLONNED_REACT_LEAFLET_PIXI_OVERLAY_FORK
yarn link
yarn install
cd node_modules/react
yarn link
cd ../react-dom
yarn link
cd ../leaflet
yarn link
cd ../react-leaflet
yarn link

cd YOUR_REACT_PROJECT
yarn link react-leaflet-pixi-overlay
yarn link react
yarn link react-dom

This can be added to a readme file to make contribution easier for people.

**3. Ignoring **
Build directory does not have to be included in a codebase. It can be added to .gitignore.
The opposite for npm. When publishing a package, src directory and some other files unnecessarily extends the size of a npm package. It can be handled by adding new .npmignore file.

4. NPM vs Yarn
There is both package-lock.json and yarn.lock file on a project. It's a good practice to use only one package manager. Otherwise it might cause issues with dependencies versioning when people contribute. It might be worth to consider removing one of lock files.

Please say what do you think about these improvements, then i can prepare a PR - i already applied some of these points locally :)

Displaying leaflet popup instead of a tooltip

The problem is that the tooltip you provide to be displayed, is being displayed inside a leaflet popup.(The displayed UI is the same for a popup and a tooltip)

  const markers = [
    {
      id: "randomStringOrNumber",
      iconColor: "red",
      position: [-37.814, 144.96332],
      popup: renderToString(<div>All good!</div>),
      onClick: () => alert("marker clicked"),
      tooltip: "Hey!",
    }

So in the markers example provided here both "All good!" and "Hey!" are displayed with the same UI.(Not using leaflet tooltip, only using leaflet popup).

Use react element as custom icon

HI,
I am trying to use a react element as a customIcon but it is not being displayed on the map.
I was wondering if react-leaflet-pixi-overlay supports this or not!!???
i wrapped the component inside renderToString and tried as well but it shows nothing at that position.
WIth normally passing iconColor, position and id then the marker icon is visible though.

Sharing array of the markers that i have tried so far.

const markers = [
{
id: "1",
iconColor: "red",
position: [-37.814, 143.96332],
// popup: renderToString(

All good!
),
onClick: () => {
alert("marker clicked");
},
customIcon: <span style={{ backgroundColor: "yellow", height: "50px", width: "50px" }} > hello user </span>,
iconId: "1234"
// tooltip: "Hey!"
},
{
id: "2",
iconColor: "blue",
position: [-37.2, 144.96332],
onClick: () => {
alert("marker clicked");
},
customIcon: renderToString(
<span
style={{ backgroundColor: "yellow", height: "50px", width: "50px" }}
>
hello user

),
iconId: "1567"
},
{
id: "3",
iconColor: "blue",
position: [-37.2, 145.2]
}
];

only the marker with id 3 is visible in the map.

inside the component i passed it like this.

Please provide your inputs on this.

Popup does not show.

My setup:
react: 17.0.2
react-leaflet: 3.2.5
react-leaflet-pixi-overlay: 3.0.0
Browser: firefox


  const markers = data.map(item=> ({
    id: item._id,
    iconColor: "red",
    position: [item.latitude, item.longitude],
    popup: "Test",
    onClick: () => {
     
    },
    tooltip: renderToString(<ItemComponent item={item}/>),
  }))

When i am hovering over marker data the tooltip is correctly displayed. When i click on the marker nothing happens. (I would expect to see popup).

Not working when built for production

Hi,

I can't get this plugin to work when built for production.

It works perfectly locally running on a dev server but when built for production using react-scripts 'build' nothing is rendered. I've done quite a lot of digging through the source of this but cannot seem to work out what could be wrong.

Any pointers would be much appreciated.

Thanks

Restrucutre lib, not working with jest and some browsers

This lib is not being compiled to es5 when published to npm, some folder restructure should do the work.

not working with aplications with jest, for unit testing and es5 browser and aplications
and has no types

the objective is to not change any funcionality, but fix thsi structural changes, without any breaking change
add prettier and eslint for sync changes to the project and keep same format

Custom Icon position issue

When using customIcon, the potion is not correct and when you zoom in/out the map the position changes.

When I use a default icon with pixi
image

When I use a custom icon with pixi
image

But the same lat/long shows here when drawn directly ask leaflet marker not Pixi stuff.
image

The same points are drawn using normal marker and circle. You can see the pixi webgl filled circles are off.
image

Any thoughts? is it the offset?

Rendered markers don't work with layers

I'm doing something like this:

<LayersControl.Overlay checked name="Test layer">
      <LayerGroup>
        <PixiOverlay markers={getMarkers()} />
      </LayerGroup>
</LayersControl.Overlay>

The markers don't disappear regardless of layer control state.

Can i add a geojson in my map?

Hello, I'm João Victor, and I'm trying to use this lib to add geojsons to my map, but I'm not succeeding. In the documentation, there is no specifying how to do it. Could you help me?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.