简体   繁体   中英

Leaflet Drawing a trail based on markers previous path

I want to try and draw a trail that follows each marker I have that is updated live from a MySQL database table with GeoJson every 8 seconds.

I have tried drawing a polyline from the Start Position to Current Position of each of the GeoJson features/leaflet markers but that won't work of course since it only takes into account the start and current position and not any turns of direction changes made underway.

I am trying to make something that draws a direct trail behind each of the markers based on the previous positions. My GPS trackers submit latitude and longitude to a database table every minute or so. My idea is that I could maybe create a new table and just make it submit every latitude and longitude from all GPS trackers and draw LineStrings for each marker based on that maybe?

But I think that wouldn't really be a good efficient way to do it since I would have multiple GPS trackers submitting latitude and longitude every minute and the GPS trackers would be moving very slow so it is very minor changes each time (if even any at all since the slow moment speed and only 4 decimal precision in the latitude and longitude there could even be cases without any changes in the submitted data)

Does anybody here have an idea for an efficient way to draw a live updating trail behind each marker from GeoJson? :)

Think of the database tables as "persistent storage" for all the data.

Have your client, when it receives more info (every 8 seconds and/or every minute) do the following:

  1. SELECT the last location from the``Current` table, which has 1 row per item being tracked.
  2. Draw on the canvas (or wherever) the line from where it was (step 1) to where it now is (incoming data).
  3. INSERT the new location into the History table.
  4. UPDATE the current location in a table that has just the Current locations of all your vehicles (or polar bears or dolphins or snails).

Four decimal places won't work for snails. It has a resolution of about 16 meters or 52 feet. See Representation choices . Four may not be sufficient for vehicles; some of the time it will erroneously show the vehicle in a ditch or on the wrong side of a highway -- simply because 4 decimal places is not enough.

I don't know about GeoJson; I'm looking at what can be done with MySQL and HTML5's "Canvas".

On a slow machine 100 changes per second should be possible. So, if you don't have a thousand things moving around, I don't see a performance problem.

The push-me, pull-me Problem

Since a web page is stateless and the data is flowing the wrong direction, it will be difficult to design a setup where the path is continually showing on the screen, and being updated periodically (every 8 seconds).

One approach is to 'push' the data into the database (as discussed above). Then have the web page that is showing the trail poll the database to see if there is something need to display.

Such "polling" would be done via AJAX that is called every, say, second. The reply would include all new location changes. The web page would paint new line segments based on whatever data was returned (zero or more kangaroos, as appropriate).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM