Git Product home page Git Product logo

leaflet-tracking-marker's Introduction

react-leaflet-tracking-marker MIT License npm version npm version

✈ A React Leaflet library that allows developers to create custom markers that drifts to a certain point, computes their bearing angle using given coordinates and rotates accordingly.

Supports react-leaflet v3.x

"IMG"

This library was inspired from leaflet-drift-marker and react-leaflet-rotatedmarker.

Check-out a working example here:

Edit leaflet-tracking-marker

Installation

npm install --save react-leaflet-tracking-marker

react-leaflet-tracking-marker requires leaflet and react-leaflet as peerDependency

npm install --save leaflet react-leaflet

Usage

Inherits props from leaflet-drift-marker and still supports all existing props from react-leaflet marker

Props Type Default Description
position LatLngExpression The current coordinates. This is mandatory.
previousPosition LatLngExpression The previous point coordinates. Allows the marker to automatically computes its rotation angle. To set a fixed value, consider using rotationAngle property.
rotationOrigin String 'center' The rotation center, as a transform-origin CSS rule.
duration number Required, duration in milliseconds marker will take to destination point
keepAtCenter boolean false Makes map view follow marker
rotationAngle number 0 Rotation angle, in degrees, clockwise. Allows setting the marker rotation angle manually, replacing the rotation angle value that was automatically computed using the previousPosition property if provided.

Note: LatLngExpression type defines an array of latitude and longitude values. e.g. [51.505, -0.09]

Example

import { LeafletTrackingMarker } from "react-leaflet-tracking-marker";

function AirplaneMarker({ data }) {
  const { latitude, longitude } = data
  const [prevPos, setPrevPos] = useState([latitude, longitude])

  useEffect(() => {
    if (prevPos[1] !== longitude && prevPos[0] !== latitude) setPrevPos([latitude, longitude])
  }, [latitude, longitude, prevPos])

  return <LeafletTrackingMarker icon={icon} position={[latitude, longitude]} previousPosition={prevPos} duration={1000} />
}

License

MIT License

leaflet-tracking-marker's People

Contributors

alexandra-c avatar astritspancasd avatar dependabot[bot] avatar fernandoi7 avatar paveltretyakovru avatar tomszafr 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

leaflet-tracking-marker's Issues

Can you give example format data in here? im very confused about that

Sory ,i got an error when retrieving data, "undefined lat lng", Can you give example about format data in here? im very confused about that, thank you for your response

data-example

My Data:
[
{ "status": 1, "t": "180927072508000", "course": 0, "lat": 53.22376666666667, "lng": 50.745841666666664 },
{ "status": 1, "t": "180927072508000", "course": 0, "lat": 53.22376666666667, "lng": 50.745841666666664 },
{ "status": 1, "t": "180927072523000", "course": 114, "lat": 53.223728333333334, "lng": 50.74598666666667 },
{ "status": 1, "t": "180927072529000", "course": 138, "lat": 53.223705, "lng": 50.746021666666664 },
{ "status": 1, "t": "180927072538000", "course": 149, "lat": 53.22365166666667, "lng": 50.746075 },
]

My Code:
my-c0de

Problem with KeepAtCenter

I am trying to toggle keepAtCenter but it's not working, Stucked on the marker position i can't move the map

here is my code:

const [isTracking,setIsTracking] = useState(false)

<LeafletTrackingMarker position={....} icon={....} duration={1000} rotationAngle={...} rotationOrigin="center" keepAtCenter={isTrack}> 
  <Popup>
     Sample Bus Data & Speed:{bus.data.data.speed}
  </Popup>
</LeafletTrackingMarker>

 ..... onClick() {
  setIsTracking((prev)=>!prev)
}

TypeScript support

JSX element class does not support attributes because it does not have a 'props' property.
'LeafletTrackingMarker' cannot be used as a JSX component.
Its instance type 'LeafletTrackingMarker' is not a valid JSX element.

Error: Invalid LatLng object: (undefined, undefined)

Describe the bug
I have added the leaflet-tracking-marker to my project( which is for now a map with simple markers), and followed the same code example hosted in codesandbox link ,
But it doesn't rendering anything ( the hole map), and it showed me in the console this error :

Uncaught Error: Invalid LatLng object: (undefined, undefined)

  • at new LatLng (LatLng.js:32:1)
  • at Object.toLatLng [as latLng] (LatLng.js:123:1)
  • at NewClass.initialize (BaseMarker.js:23:1)
  • at new NewClass (Class.js:22:1)
  • at createMarker (LeafletTrackingMarker.js:42:1)
  • at useMutableLeafletElement (element.js:10:1)
  • at useLayer (layer.js:21:1)
  • at ContainerComponent (component.js:6:1)
  • at renderWithHooks (react-dom.development.js:14985:1)
  • at updateForwardRef (react-dom.development.js:17044:1)
    A capture of the Map.js file is attached(the tracker marker in this case is called MovingMarker in the last lines)
    Any help will be appreciated
    code

Rotation Angle Zero doesn't work on marker update

Describe the bug
When a marker is defined with rotationAngle equal to zero, after updating, the marker does not use the zero value and updates the marker angle considering the position variation.

To Reproduce

  1. Setup a marker with rotationAngle={0}
import { useEffect, useState } from "react";
import { LeafletTrackingMarker } from "react-leaflet-tracking-marker/src";
import PropTypes from "prop-types";

const AnimatedMarker = ({ icon, latitude, longitude, children }) => {
  const [prevPos, setPrevPos] = useState([latitude, longitude]);

  useEffect(() => {
    if (prevPos[1] !== longitude && prevPos[0] !== latitude)
      setPrevPos([latitude, longitude]);
  }, [latitude, longitude, prevPos]);

  return (
    <LeafletTrackingMarker
      icon={icon}
      position={[latitude, longitude]}
      duration={1000}
      rotationAngle={0}
      rotationOrigin="unset"
    >
      {children}
    </LeafletTrackingMarker>
  );
};

AnimatedMarker.propTypes = {
  icon: PropTypes.object.isRequired,
  latitude: PropTypes.number.isRequired,
  longitude: PropTypes.number.isRequired,
  children: PropTypes.object.isRequired,
};

export default AnimatedMarker;
  1. Update the marker position

Expected behaviour
Marker must keep zero angle even after marker position update

Screenshots
screencast-localhost_3000-2022 08 23-15_26_28

I already opened a pull request fixing the problem #23

Error when npm run build, in nextjs (typescript)

Version:
node : v18.7.0
npm : 8.15.0
react version : 17.0.2
react-leaflet : 3.2.0
leaflet : 1.7.1
react-leaflet-tracking-marker : 1.0.15

Hello good morning, i have some problem when, i build the application, when i use "npm run build" in nextjs, previously there was no error, when i build, can you help me? thank you

Screen Shot 2022-09-23 at 08 09 17

Tracking leaflet marker, Clusterize group of markers

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.
I want to render more than 1000 markers on the map, and being violation issue and slow, that is why please update for this feature

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

Wrong import method in the given example

Using the import method shown in the example gives an error.
The example: import LeafletTrackingMarker from 'react-leaflet-tracking-marker'

I fixed it by importing it this way:
import { LeafletTrackingMarker } from 'react-leaflet-tracking-marker'

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.