Comments (24)
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.
There is now the option pauseOnZoom
with commit 706cb74, that lets you pause/resume the markers while zooming.
from leaflet.extras2.
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.
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.
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.
@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.
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.
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.
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.
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.
Try changing www/icon.png
to ./icon.png
That works for me.
from leaflet.extras2.
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.
Indeed, the missing popup should be fixed with e4e199f
Very welcome, I'm glad it helps!
from leaflet.extras2.
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.
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.
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.
Awesome, thanks!!
from leaflet.extras2.
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.
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.
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.
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.
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.
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.
Thanks @trafficonese. Did you find any solution/ideas related to the problem I mentioned above?
from leaflet.extras2.
Related Issues (20)
- addArrowhead function not rendering HOT 4
- addEasyprint does only export the top part of a map for "Current Size" HOT 3
- Overlaying sidebar using shinydashboard and addSidebar HOT 13
- Spinner does not appear in Shiny application HOT 6
- "addHexbin" in leaflet.extras2 doesn't allow for mean/sum HOT 2
- addVelocity not work HOT 1
- addWMS with interactive options HOT 1
- Changing the moveable marker icons and colours in addPlayback() HOT 6
- addWMS - authentication for title layer HOT 2
- addWMS() does not hide the attribution when corresponding group is hidden HOT 2
- Release leaflet.extras2 1.2.1
- addSidebar causing issues if multiple leaflet maps are in one R shiny app HOT 6
- Feature Request: Function to Recolor Polygons in Shiny without Redrawing them HOT 2
- airDatePickerInput (ShinyWidgets) not rendering properly in leaflet sidebar menu HOT 1
- Release leaflet.extras2 1.2.2
- Integrating GetLegendGraphic from Geoserver WMS Layers HOT 1
- addgeojsonv2 is not working with leafletproxy function HOT 2
- Animation Options in startSpinner() Not Working HOT 1
- Scroll in Sidebar not working with Firefox HOT 5
- Toggle layer on when clicking on a Sidebar-v2 icon HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from leaflet.extras2.