Git Product home page Git Product logo

Comments (24)

dewalex avatar dewalex commented on June 6, 2024 1

I've given it try with going along a line, with feeding it lat/longs with one duration, and lat/longs with multiple durations, and it all looks great! This is awesome. Thanks for bringing this over to R.

from leaflet.extras2.

trafficonese avatar trafficonese commented on June 6, 2024 1

There is now the option pauseOnZoom with commit 706cb74, that lets you pause/resume the markers while zooming.

from leaflet.extras2.

dewalex avatar dewalex commented on June 6, 2024 1

Nice, thanks for fixing that one.

Yeah, I think people can live with that. If you have a manual pause, you'll probably have less of the need for the pauseOnZoom feature than someone that doesn't want/need a manual pause button.

from leaflet.extras2.

trafficonese avatar trafficonese commented on June 6, 2024 1

I will close this issue since movingMarkers are now available.

@gacolitti I will open a separate issue for the separate labels/popups for the Playback function. I've got a working code, only the popup locations seem to be wrong.

from leaflet.extras2.

trafficonese avatar trafficonese commented on June 6, 2024

I just uploaded 4e0f62a, which enables the plugin MovingMarker.
Could you please try (the dev version) to see if it fits or if something is missing?

Here is an example app - https://github.com/trafficonese/leaflet.extras2/blob/master/inst/examples/movingmarker_app.R

from leaflet.extras2.

dewalex avatar dewalex commented on June 6, 2024

@trafficonese I did catch one thing while trying to implement this in my application. If it's a possibility, can we add the ability for multiple markers to move?

I am trying to animate the results of 20 different gps units in the same area. Here is a minimal example with two markers of what I'm thinking:

df<-data.frame(long1=c(-85, -84), lat1=c(30,30),long2=c(-85, -84), lat2=c(40,40) )

leaflet() %>% addTiles() %>% 
    addMovingMarker(lng=c(df$long1, df$long2), lat=c(df$lat1, df$lat2),
                    duration = 4500,
                    movingOptions = movingMarkerOptions(autostart = TRUE, loop = FALSE))

Right now the one marker moves over to the 2nd marker's position, when it should be 2 markers moving parallel.

from leaflet.extras2.

trafficonese avatar trafficonese commented on June 6, 2024

Unfortunately, I dont think there is an easy way of doing that. The moving marker expects 1 track only.
Also, in your case you just pass a vector of coordinates, so there is no way of detecting which points should be visualized separately.

So either you use addMovingMarker for every track you want to display, or you could use an lapply-approach.

df<-data.frame(long1=c(-85, -84), lat1=c(30,30),
               long2=c(-85, -84), lat2=c(40,40) )
leaflet() %>% addTiles() %>% 
  addMovingMarker(lng=df$long2, 
                  lat=df$lat2,
                  duration = 4500) %>% 
  addMovingMarker(lng=df$long1, 
                  lat=df$lat1,
                  duration = 4500)

or

df <- data.frame(id = c(1,1,2,2),
                 long = c(-85, -84, -85, -84), 
                 lat = c(30,30, 40,40))
m <- leaflet() %>% addTiles()
lapply(split(df, df$id), function(x) {
    m <<- m %>% 
      addMovingMarker(m, lng = x$long, 
                    lat = x$lat,
                    duration = 4500)
})

from leaflet.extras2.

dewalex avatar dewalex commented on June 6, 2024

Ok, thought that may be the case :/
I tried running my dataset on a loop like that, but I can't get the icons to work with it (having conditions for which icon to use).

Any ideas how to make it work with the icon?:

df <- data.frame(id = c(1,1,2,2),
                 long = c(-85, -84, -85, -84), 
                 lat = c(30,30, 40,40))



m <- leaflet() %>% addTiles()
lapply(split(df, df$id), function(x) {
  
  Ico <- makeIcon(
        iconUrl = ifelse(x$id==1, "https://image.flaticon.com/icons/png/512/905/905567.png","https://www.iconpacks.net/icons/1/free-car-icon-1057-thumb.png" ),
        iconWidth = 40, iconHeight = 50,
        iconAnchorX = 0, iconAnchorY = 0
    )
    
    m <<- m %>% 
        addMovingMarker(m, lng = x$long, 
                        lat = x$lat,
                        icon=Ico,
                        duration = 4500)
})

from leaflet.extras2.

trafficonese avatar trafficonese commented on June 6, 2024

Replace x$id==1 with x$id[1]==1 in the ifelse, otherwise you will have 2 iconUrl's and that apparently confuses the code.

from leaflet.extras2.

dewalex avatar dewalex commented on June 6, 2024

Oh ok, I guess that makes sense. I actually did have it set up that way in my app, but changed it because nothing was plotting. My icons are actually stored in my www folder of my shinyapp, and that seems to be the issue. When I replace the URL with a png from the internet (instead of "www/icon.png"), it plots.

Is there any reason why the addMovingMarker() would not be referencing the www folder?

from leaflet.extras2.

trafficonese avatar trafficonese commented on June 6, 2024

Try changing www/icon.png to ./icon.png
That works for me.

from leaflet.extras2.

dewalex avatar dewalex commented on June 6, 2024

That solves it. Thank you!

Thanks so much for getting this going, this really steps up the game for a lot of my visualizations.

There was one other thing that I noticed when testing. If you leave popup= blank or set it to NULL, you still get a blank pop up if the user clicks the icon.

from leaflet.extras2.

trafficonese avatar trafficonese commented on June 6, 2024

Indeed, the missing popup should be fixed with e4e199f

Very welcome, I'm glad it helps!

from leaflet.extras2.

dewalex avatar dewalex commented on June 6, 2024

Do you know if there is a setting I could use to have the markers zoom with the tiles, instead of after?

2021-02-23_15-30-15.mp4

from leaflet.extras2.

trafficonese avatar trafficonese commented on June 6, 2024

There is no setting, but apparently there is a workaround, described here: ewoken/Leaflet.MovingMarker#37

But there seems to be a downside to it, explained here: ewoken/Leaflet.MovingMarker#7

I could include it but I am not sure if its really an improvement, since the animation time gets messed up..

from leaflet.extras2.

dewalex avatar dewalex commented on June 6, 2024

Is it something that could be included in the options, like they did? For anyone using it like I do, a delay shouldn't hurt (if I'm understanding correctly what happens).

from leaflet.extras2.

dewalex avatar dewalex commented on June 6, 2024

Awesome, thanks!!

from leaflet.extras2.

dewalex avatar dewalex commented on June 6, 2024

I think that the pauseOnZoom is interfering with loop=FALSE. If you zoom after the marker reaches the end, the loop will start over:

leaflet() %>% addTiles() %>% 
    addMovingMarker(lng=c(-122, -75), 
                    lat=c(30, 45),
                    duration = 5000, 
                    movingOptions = movingMarkerOptions(pauseOnZoom = TRUE, loop=FALSE)) 

from leaflet.extras2.

trafficonese avatar trafficonese commented on June 6, 2024

Indeed, I apparently copied the wrong code snippet. It should have been pause/resume instead of pause/start.
That should be fixed now with 5ea0971.

from leaflet.extras2.

dewalex avatar dewalex commented on June 6, 2024

Any idea why the pauseOnZoom would only apply to the last moving marker added to the map?

2021-02-26_9-27-00.mp4
leaflet() %>% addTiles() %>% 
    addMovingMarker(lng=c(-122, -75), 
                    lat=c(30, 45),
                    duration = 5000, 
                    movingOptions = movingMarkerOptions(pauseOnZoom = TRUE, loop=FALSE)) %>% 
    addMovingMarker(lng=c(-122, -75), 
                    lat=c(35, 48),
                    duration = 5000, 
                    movingOptions = movingMarkerOptions(pauseOnZoom = TRUE, loop=FALSE))

from leaflet.extras2.

trafficonese avatar trafficonese commented on June 6, 2024

Indeed, that was a design bug, which should be solved with 6768b8b.

One other problem I encountered: If you pause the animation and then zoom, the animation will resume. I dont think there is an easy fix for that unfortunately.

from leaflet.extras2.

gacolitti avatar gacolitti commented on June 6, 2024

Is there any way to make the label, popup, or other elements depend on the data? As far as I can tell, the label must be static. How would one indicate an event happened at a specific point and time?

from leaflet.extras2.

trafficonese avatar trafficonese commented on June 6, 2024

Thats a good question indeed. It is currently not possible and I'm not sure if its possible at all with this plugin, but I will have a look.

from leaflet.extras2.

gacolitti avatar gacolitti commented on June 6, 2024

Thanks @trafficonese. Did you find any solution/ideas related to the problem I mentioned above?

from leaflet.extras2.

Related Issues (20)

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.