GithubHelp home page GithubHelp logo

linghuam / leaflet.trackplayback Goto Github PK

View Code? Open in Web Editor NEW
148.0 4.0 60.0 5.55 MB

a leaflet track-playback plugin

Home Page: https://linghuam.github.io/Leaflet.TrackPlayBack/

License: MIT License

JavaScript 91.40% CSS 3.36% HTML 5.23%

leaflet.trackplayback's Introduction

Leaflet.TrackPlayBack

Introduce

It's a track playback plugin based on leaflet and HTML5 canvas.

To use it,you need provide some GPS data and time data, then you can play the track on the map.

Support track playback, pause, fast forward, fast reverse operation.

Requirements

  • leaflet version: >1.0.0

Demo

Click here to see demo

Usage

Using npm:

npm i leaflet
npm i leaflet-plugin-trackplayback

example:

import L from 'leaflet'
import 'leaflet-plugin-trackplayback'

const trackplayback = L.trackplayback(data, map);
// or
const trackplayback = new L.TrackPlayBack(data, map);

Using script tag:

  <link rel="stylesheet" href="./lib/leaflet/leaflet.css">

  <!--Optional (only if you need plaback control)-->
  <link rel="stylesheet" href="../dist/control.playback.css">

  <script src="./lib/leaflet/leaflet.js"></script>

  <!--Optional (only if you need plaback control)-->
  <script src="../dist/control.trackplayback.js"></script>

  <script src="../dist/leaflet.trackplayback.js"></script>

example:

    const trackplayback = L.trackplayback(data, map);

    // Optional  (only if you need plaback control)
    const trackplaybackControl = L.trackplaybackcontrol(trackplayback);

    trackplaybackControl.addTo(map);

API reference

initialize(data, map, options)

data can be:

when you want to play back one track

[{lat:30, lng:116, time:1502529980, dir:320, info:[{key: 'name', value: 'ship1'}]}, ....]

or

when you want to play back more tracks

[[{lat:30, lng:116, time:1502529980, dir:320, info:[]}, ....], [{lat:30, lng:116, time:1502529980, dir:320, info:[]}, ....]]

the trackpoint obj properties:

  • lat: Latitude of target
  • lng: Longitude of target
  • time: unix timestamp
  • dir(Optional): Moving direction(0-360 degrees, Clockwise direction), if you don't provide it, the program can auto caculate the target direction
  • info(Optional): other static information of the target, it's an array of key-value pairs

map is the L.map instance.

options can be:

const Options = {
  // the play options
  clockOptions: {
    // the default speed
    // caculate method: fpstime * Math.pow(2, speed - 1)
    // fpstime is the two frame time difference
    speed: 13,
    // the max speed
    maxSpeed: 65
  },
  // trackPoint options
  trackPointOptions: {
    // whether draw track point
    isDraw: false,
    // whether use canvas to draw it, if false, use leaflet api `L.circleMarker`
    useCanvas: true,
    stroke: false,
    color: '#ef0300',
    fill: true,
    fillColor: '#ef0300',
    opacity: 0.3,
    radius: 4
  },
  // trackLine options
  trackLineOptions: {
    // whether draw track line
    isDraw: false,
    stroke: true,
    color: '#1C54E2',
    weight: 2,
    fill: false,
    fillColor: '#000',
    opacity: 0.3
  },
  // target options
  targetOptions: {
    // whether use image to display target, if false, the program provide a default
    useImg: false,
    // if useImg is true, provide the imgUrl
    imgUrl: '../../static/images/ship.png',
    // the width of target, unit: px
    width: 8,
    // the height of target, unit: px
    height: 18,
    // the stroke color of target, effective when useImg set false
    color: '#00f',
    // the fill color of target, effective when useImg set false
    fillColor: '#9FD12D'
  }
}

events

// trigger on time change
trackplayback.on('tick', e => {
  console.log(e.time)
}, this)

methods

# start()

start play, return this

# stop()

stop play, return this

# rePlaying()

replay, return this

# slowSpeed()

slow play speed, return this

# quickSpeed()

quick play speed, return this

# getSpeed()

get play speed, return speed value

# getCurTime()

get current time, return unix timestamp

# getStartTime()

get start time, return unix timestamp

# getEndTime()

get end time, return unix timestamp

# isPlaying()

whether in playing, return true or false

# setCursor(time)

set current playing time, need a unix timestamp param, return this

# setSpeed(speed)

set the playback speed, return this

# showTrackPoint()

draw track point, return this

# hideTrackPoint()

remove track point, return this

# showTrackLine()

draw track line, return this

# hideTrackLine()

remove track line, return this

# dispose()

destory the trackplayback instance, when call this, the trackplayback instance can't be used again and the program will clear track layer.

performance

I collected the frame rate for a while.

Frame rate

Issues

If you have good suggestions or comments,welcome to ask questions.

Recommends

  1. html5 canvas
  2. LeafletPlayback

License

MIT license

leaflet.trackplayback's People

Contributors

linghuam avatar oppo12312312 avatar raffifu 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  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  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.trackplayback's Issues

Mouseover for target

At present, the "info" box comes up for trackpoints. But can we have one for the boat (target) itself?

Translation for playback control

Plugin is really cool and simple to use, but are you going to implement translation for labels in playback control?
Is it possible to include translation into"options"?
Inform, pls, if you will need help with this issue.

Cannot drag the input range while the playback control is playing

It looks like the input range does not allow dragging while the playback control is playing.
I looked over the source code, _scrollchange but cannot figure it out what stops the control from changing the position.
This does not happen when the control stops playing.
image

data transform

请问代码里面有关于json解析的相关代码么?

轨迹线段太多会乱

是否考虑增加显示尾迹的功能,如果轨迹点太多线段太多眼花缭乱,可只显示最近的一段轨迹在后面跟着

GeoJSON implementation? Documentation of data input

Great plugin. I've recently started testing. I've been able to format the data correct for one vessel/ship. However, I'm having problems creating a syntax to support multiple vessels.

I'm thinking of a track as all the points for a vessel in my case.

I tried using the info key name to specify a unique vessel and hoped that would cause the tracks to be grouped by vessel id.

Can you clarify the syntax for multiple vessels. It looks like two ]].

Have you considered using geoJson as an input format?

Thanks for this plugin.

Cannot click on other markers while playback control is displayed

I have a Leaflet OpenStreetMap with many other markers (green one). Usually, I can click on those markers to show the marker info. When I hover my mouse over those markers, the cursor changes to a hand icon. After I showed the playback control on the map with playback marker (red one), the cursor changed to the hand icon and I no longer can click on other markers.
image

load data dynamically

Amazing plugin!

My data is loading dynamically, after page load. To make it work with TrackPlayback, I put all the code in the function block that triggers after my data has loaded.

Upon user input (filtering) I want to render the filtered data. But the function block where all the declaration was done has run and closed. I can't access it globally.

By declaring trackplayback globally and initiating it locally, I'm still able to do trackplayback.dispose() which gets rid of whatever was there on the map; but does not dispose of the playback control; and I'm not able to re-initate trackplayback again.

There is a cross button on the playback control which is generated by this library, which gets rid of everything. I'd like to be able to execute that then re-declare TrackPlayback all over again. But that cross button is also internally generated and there's a listener listening to it that I can't figure out how to trigger. As a workaround I'd like to trigger this "destroy everything" type action and then run the starting commands all over again with my new data.

Any tips on how to move forward would be most appreciated!

[Fixed]Chrome浏览器使用useImg无法在轨迹点回放时画图

Draw.js的函数_drawShip2需要做下修改:
var img = new Image();
img.src = this.shipOptions.imgUrl;
if (img.complete) {
this._ctx.save();
this._ctx.translate(point.x, point.y);
this._ctx.rotate(Math.PI / 180 * dir);
this._ctx.drawImage(img, 0 - offset.x, 0 - offset.y, width, height);
this._ctx.restore();
return;
}
img.onload = function () {
this._ctx.save();
this._ctx.translate(point.x, point.y);
this._ctx.rotate(Math.PI / 180 * dir);
this._ctx.drawImage(img, 0 - offset.x, 0 - offset.y, width, height);
this._ctx.restore();
}.bind(this);
原因暂时未知,可能不同浏览器对image的complete和onload方法支持不一样,之前的代码在IE Edge没问题

Error when trying to start playback

Hello, I'm using leaflet 1.9.1, leaflet-plugin-trackplayback 1.0.5 and react-leaflet 4.1.0.
I just reproduced the example on a simple project using react-leaflet's map, using the data.json file on this example too, but when I try to start the playback I get this error: TypeError: Cannot use 'in' operator to search for '_leaflet_id' in undefined, does anyone faced this?

npm run dev

image,您好,运行npm run dev ,然后一直处于这个状态,需要等待么?不接受任何输入

L.PlayBack.Util is undefined

在本地html文件引入两个js时尚未出现此问题,部署在tomcat调试时发现该问题,leaflet0.7.7版本,浏览器chrome,log(L)下没发现有playBack属性

Angular Import Issue

I'm having issues with the import to my angular program.

I've installed using npm
npm i leaflet-plugin-trackplayback

Then imported at the top of the component
import 'leaflet-plugin-trackplayback'

But I am getting an error on
const trackplayback = L.trackplayback(data, map);

Property 'trackplayback' does not exist on type 'typeof import

Is there a way to remove a "boat" icon after the time has completed for it showing only the line or track points?

I'm testing out your library, but what I have found is if I put a few years worth of data into it the older "complete" arrays of lat and lng still show an icon like they are still moving.

Is there anyway that if the leaflet program has passed the last "time" of the array of the individual item the animated marker can go away?

Example:

var data = [[ {lat:30, lng:-117, time:1500000000, dir:0, info:[]}, {lat:31, lng:-116, time:1700000000, dir:0, info:[]}], [ {lat:30, lng:-118, time:1600000000, dir:0, info:[]}, {lat:31, lng:-116, time:1800000000, dir:0, info:[]}]] ;

For this example how do I make the icon for the first array of data go away (but keep trackLine and/or trackPoint) at time: 1700000001 ?

Ship was not shown when dragged to the beginning

When I dragged to the beginning, no ship was shown on the map. Just after I pressed the play button, like in an instant, the ship would appear. I checked the function _drawShipCanvas and everything seems normal.

How to get the event when a marker is clicked

It would be nice if the library supports an event when a marker is clicked or hovered. I read the source code but still have no clue how to do this. Maybe we need to define some events for the _ctx. Hope to hear some suggestions. In my case, I need to display a small popup showing the marker (vessel) info.

image

Error in tablet and mobile

I have a file in which the coordinates are saved and which is read using an api. The file has this content:

[{"lng":-6.2311238,"lat":42.0092283,"time":1709062962,"info": [{ "key": "", "value": "27/2/2024, 20:42:42"}]},{"lng":-6.2189937,"lat":42.0080344,"time":1709062969,"info": [{ "key": "", "value": "27/2/2024, 20:42:49"}]},{"lng":-6.2218882,"lat":42.0085202,"time":1709062975,"info": [{ "key": "", "value": "27/2/2024, 20:42:55"}]},{"lng":-6.2252116,"lat":42.0090601,"time":1709062982,"info": [{ "key": "", "value": "27/2/2024, 20:43:02"}]},{"lng":-6.2280514,"lat":42.0095289,"time":1709062988,"info": [{ "key": "", "value": "27/2/2024, 20:43:08"}]},{"lng":-6.2313671,"lat":42.0100505,"time":1709062995,"info": [{ "key": "", "value": "27/2/2024, 20:43:15"}]},{"lng":-6.2337413,"lat":42.0104197,"time":1709063000,"info": [{ "key": "", "value": "27/2/2024, 20:43:20"}]},{"lng":-6.2366549,"lat":42.0107059,"time":1709063006,"info": [{ "key": "", "value": "27/2/2024, 20:43:26"}]},{"lng":-6.2391088,"lat":42.0107172,"time":1709063011,"info": [{ "key": "", "value": "27/2/2024, 20:43:31"}]},{"lng":-6.2424719,"lat":42.0103327,"time":1709063018,"info": [{ "key": "", "value": "27/2/2024, 20:43:38"}]},{"lng":-6.2456857,"lat":42.0095226,"time":1709063025,"info": [{ "key": "", "value": "27/2/2024, 20:43:45"}]},{"lng":-6.2482826,"lat":42.0085404,"time":1709063031,"info": [{ "key": "", "value": "27/2/2024, 20:43:51"}]},{"lng":-6.2508601,"lat":42.0074954,"time":1709063037,"info": [{ "key": "", "value": "27/2/2024, 20:43:57"}]},{"lng":-6.2530774,"lat":42.00672,"time":1709063042,"info": [{ "key": "", "value": "27/2/2024, 20:44:02"}]},{"lng":-6.2558769,"lat":42.0060363,"time":1709063048,"info": [{ "key": "", "value": "27/2/2024, 20:44:08"}]}]

When I read a file on the PC it loads correctly and the control works fine. When I do it from a mobile or tablet I receive an error: SyntaxError: Expected ',' or '}' after array element in JSON at position 1632 (line 1 column 1633)

Can someone tell me what's happening?

请教下,图标可以使用divicon吗?并且支持单条线隐藏

请教下,图标可以使用divicon吗?并且支持单条线隐藏?

需求是,只显示5条线,然后每条线都可以单独隐藏。是否支持那?或者有什么思路可以实现。

船的图标的话,我看配置是支持图片的,但是需求是,需要图标颜色和线的颜色是一样的,并且支持单条隐藏。

5

is there way to show popup control instead of tooltip and also can we change icon using ship type

getCurrLatLng or getCurrentData

getCurTime is great to get the current time, it would be even greater if it can return back current latlng along with Info. Example getCurrentData { lat: lng: Info: }. Maybe this would be heavy for multiple tracks but for single track would be good

Drawing lines in different colors

A really great plugin !
There is something I wonder. I want the trackLineOptions color value to change its color based on each data in JSON.
image

Actually what i want is that each id draws a different color line?
is it possible to do it this way and how can it be done?

Cannot use 'in' operator to search for '_leaflet_id' in undefined

I tried to use this library with Leaflet map and Blazor. The playback control was shown on the map but no markers were shown.
Just got this error on console: Cannot use 'in' operator to search for '_leaflet_id' in undefined
It looks like a problem with the layer but I can't quite get it yet.

Unresponsive browser after playbackcontrol reinitialisation

Hi, I have been testing the demo app and it seems there is a problem with reinitialization of playback control.

  • I have enabled trackpoints and tracklines and played the demo
  • I have removed the playback control with close button which actually calls the _close() function and this function is supposed to dispose trackplayback
  • I initialise the trackplayback and trackplayback control again and add it to the map

And this is where things get tricky.. after doing this for 4 or 5 times, browser gets more and more unresponsive and track frames drop drastically. It looks like browser goes out of resources..

I tried tweaking few things but nothing helped.

Any idea ?

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.