Skip to content

Upgrade to Leaflet v1.x #453

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 43 commits into from
Mar 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
a648357
add simple crosstalk example
timelyportfolio Dec 30, 2016
f1e63f5
add basic crosstalk + shiny example
timelyportfolio Dec 30, 2016
31b8d05
Merge branch 'master' of https://github.com/rstudio/leaflet
timelyportfolio Dec 30, 2016
9261eca
hack to make leaflet only render once
timelyportfolio Dec 30, 2016
d1294a3
change to master for leaflet and crosstalk
timelyportfolio Dec 30, 2016
e9267e4
uglier by the commit; fix error with ui introduced by leaflet once re…
timelyportfolio Dec 30, 2016
f9ac904
Merge branch 'master' of https://github.com/rstudio/leaflet
timelyportfolio Jan 9, 2017
b4bc9d9
add an example using Shiny to get polygon from Leaflet.Draw and then …
timelyportfolio Jan 9, 2017
c5e27b4
add example with Shiny gadget for Leaflet.Draw; cc @tim-salabim
timelyportfolio Jan 10, 2017
4c75faf
add more complex Leaflet.Draw Shiny gadget; ref https://github.com/ti…
timelyportfolio Jan 10, 2017
351f0ef
fix small bug in second draw gadget example
timelyportfolio Jan 11, 2017
1880efb
also show how to plot points not within using lawn/turf
timelyportfolio Jan 11, 2017
e3010c2
quick little poc to combine listviewer::jsonedit with mapview to have…
timelyportfolio Jan 13, 2017
1deebd6
add Leaflet.Draw deleted shiny example
timelyportfolio Jan 17, 2017
ce3c1d7
test out leaflet with Split.js
timelyportfolio Jan 18, 2017
62907df
add resize on drag
timelyportfolio Jan 19, 2017
d1c3ef7
test with split.js and svglite responsive svg
timelyportfolio Jan 19, 2017
2d42d10
Merge branch 'master' of https://github.com/rstudio/leaflet
timelyportfolio Mar 10, 2017
c087ffd
copy/paste leaflet.js 1.0.3
timelyportfolio Mar 10, 2017
c1c030e
keep log of all errors found
timelyportfolio Mar 10, 2017
00eff02
change to leaflet version 1.0.3 in yaml
timelyportfolio Mar 11, 2017
4b841f0
fix (partially) marker.png not found error
timelyportfolio Mar 11, 2017
6d0e4e1
upgrade leaflet-measure to 2.1.5
timelyportfolio Mar 11, 2017
7279a94
add note in errors about leaflet-measure broken status
timelyportfolio Mar 11, 2017
f6a25e9
change leaflet-measure version in htmlDependency to 2.1.5 and remove …
timelyportfolio Mar 11, 2017
6899951
discovered remove controls do not work so log in errors
timelyportfolio Mar 11, 2017
c6762e3
temp fix for leaflet-measure but need to rewrite some legacy controls…
timelyportfolio Mar 11, 2017
55334c1
fix leaflet-measure and layersControl to use addControl and removeCon…
timelyportfolio Mar 13, 2017
a4875a3
start to remove leaflet-label since now L.tooltip
timelyportfolio Mar 13, 2017
8f78977
start discussing changes in NEWS to keep track
timelyportfolio Mar 13, 2017
03d6b38
update leaflet-markercluster to 1.0.4 and update its plugins
timelyportfolio Mar 14, 2017
f448c72
fix markercluster permanent/noHide tooltip for L.tooltip
timelyportfolio Mar 14, 2017
ea92252
change default label offset to same as default L.tooltip offset 0,0
timelyportfolio Mar 14, 2017
05dea44
update leaflet-omnivore to 0.3.4
timelyportfolio Mar 14, 2017
c1405d5
remove old bower from leaflet-providers
timelyportfolio Mar 14, 2017
aba117c
update to proj4leaflet 1.0.1 and test with http://rpubs.com/bhaskarvk…
timelyportfolio Mar 15, 2017
96667e3
step toward fixing broken addRasterImage; displays now but still not …
timelyportfolio Mar 15, 2017
83bee11
fix no. 2 on addRasterImage now displaying correctly but not working …
timelyportfolio Mar 16, 2017
a807435
Raster: Fix issue where rasters appear behind tiles by default
jcheng5 Aug 18, 2017
bb4e33d
Fix issue with rasters disappearing
jcheng5 Aug 18, 2017
3e65a74
Merge branch 'master' into v1.0
jcheng5 Aug 21, 2017
b719a0f
Upgrade to Leaflet 1.2.0
jcheng5 Aug 21, 2017
d19bd52
Rebuild docs
jcheng5 Aug 21, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,5 @@ Suggests:
RJSONIO,
purrr,
testthat
RoxygenNote: 5.0.1
RoxygenNote: 6.0.1
LazyData: true
9 changes: 9 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
leaflet 2.0
--------------------------------------------------------------------------------

* update to leaflet.js v1.0.3

* all plugins updated to their newest versions compatible with leaflet > 1.0

* leaflet-label plugin now L.tooltip in leaflet.js. labelOptions() now translates old options clickable to interactive and noHide to permanent.

leaflet 1.1.1
--------------------------------------------------------------------------------

Expand Down
21 changes: 14 additions & 7 deletions R/layers.R
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ tileOptions <- function(
zoomOffset = 0,
zoomReverse = FALSE,
opacity = 1.0,
zIndex = NULL,
zIndex = 1,
unloadInvisibleTiles = NULL,
updateWhenIdle = NULL,
detectRetina = FALSE,
Expand Down Expand Up @@ -497,25 +497,32 @@ safeLabel <- function(label, data) {

#' @param
#' noHide,direction,offset,textsize,textOnly,style
#' label options; see \url{https://github.com/Leaflet/Leaflet.label#options}
#' label options; see \url{http://leafletjs.com/reference-1.0.3.html#tooltip-option}
#' @describeIn map-options Options for labels
#' @export
labelOptions <- function(
clickable = FALSE,
noHide = FALSE,
interactive = FALSE,
clickable = NULL,
noHide = NULL,
permanent = FALSE,
className = '',
direction = 'right',
#pane = NULL,
offset = c(12,-15),
offset = c(0,0),
opacity = 1,
textsize = "10px",
textOnly = FALSE,
style = NULL,
zoomAnimation = TRUE,
...
) {
# use old clickable if provided
if(!is.null(clickable) && interactive != clickable) interactive <- clickable
# use old noHide if provided
if(!is.null(noHide) && permanent != noHide) permanent <- noHide

list(
clickable = clickable, noHide = noHide, direction = direction,
interactive = interactive, permanent = permanent, direction = direction,
opacity = opacity, offset = offset,
textsize = textsize, textOnly = textOnly, style = style,
zoomAnimation = zoomAnimation, className = className, ...
Expand Down Expand Up @@ -624,7 +631,7 @@ markerClusterDependencies <- function() {
list(
htmltools::htmlDependency(
'leaflet-markercluster',
'0.5.0',
'1.0.4',
system.file('htmlwidgets/plugins/Leaflet.markercluster', package = 'leaflet'),
script = c('leaflet.markercluster.js', 'leaflet.markercluster.layersupport-src.js', 'leaflet.markercluster.freezable-src.js'),
stylesheet = c('MarkerCluster.css', 'MarkerCluster.Default.css')
Expand Down
84 changes: 42 additions & 42 deletions R/plugin-measure.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ leafletMeasureDependencies <- function() {
list(
htmltools::htmlDependency(
"leaflet-measure",
"2.0.2",
"2.1.5",
system.file("htmlwidgets/lib/leaflet-measure", package = "leaflet"),
script = "leaflet-measure.min.js",
stylesheet = "leaflet-measure.css"
Expand Down Expand Up @@ -54,51 +54,51 @@ leafletMeasureDependencies <- function() {
#'
#' # customizing
#' leaf %>% addMeasure(
#' position = "bottomleft"
#' , primaryLengthUnit = "meters"
#' , primaryAreaUnit = "sqmeters"
#' , activeColor = "#3D535D"
#' , completedColor = "#7D4479"
#' , localization = 'de'
#' position = "bottomleft",
#' primaryLengthUnit = "meters",
#' primaryAreaUnit = "sqmeters",
#' activeColor = "#3D535D",
#' completedColor = "#7D4479",
#' localization = 'de'
#' )
#'
#' @export
addMeasure <- function(
map
, position = "topright"
, primaryLengthUnit = "feet"
, secondaryLengthUnit = NULL
, primaryAreaUnit = "acres"
, secondaryAreaUnit = NULL
, activeColor = "#ABE67E"
, completedColor ="#C8F2BE"
, popupOptions = list( className = 'leaflet-measure-resultpopup', autoPanPadding = c(10,10) )
, captureZIndex = 10000
, localization = 'en'
, decPoint = '.'
, thousandsSep = ','
map,
position = "topright",
primaryLengthUnit = "feet",
secondaryLengthUnit = NULL,
primaryAreaUnit = "acres",
secondaryAreaUnit = NULL,
activeColor = "#ABE67E",
completedColor ="#C8F2BE",
popupOptions = list( className = 'leaflet-measure-resultpopup', autoPanPadding = c(10,10) ),
captureZIndex = 10000,
localization = 'en',
decPoint = '.',
thousandsSep = ','
) {
map$dependencies <- c(map$dependencies, leafletMeasureDependencies())
invokeMethod(
map
, getMapData(map)
, 'addMeasure'
, Filter(
Negate(is.null)
,list(
position = position
, primaryLengthUnit = primaryLengthUnit
, secondaryLengthUnit = secondaryLengthUnit
, primaryAreaUnit = primaryAreaUnit
, secondaryAreaUnit = secondaryAreaUnit
, activeColor = activeColor
, completedColor = completedColor
, popupOptions = popupOptions
, captureZIndex = captureZIndex
, localization = localization
, decPoint = decPoint
, thousandsSep = thousandsSep
)
map,
getMapData(map),
'addMeasure',
Filter(
Negate(is.null),
list(
position = position,
primaryLengthUnit = primaryLengthUnit,
secondaryLengthUnit = secondaryLengthUnit,
primaryAreaUnit = primaryAreaUnit,
secondaryAreaUnit = secondaryAreaUnit,
activeColor = activeColor,
completedColor = completedColor,
popupOptions = popupOptions,
captureZIndex = captureZIndex,
localization = localization,
decPoint = decPoint,
thousandsSep = thousandsSep
)
)
)
}
Expand All @@ -107,8 +107,8 @@ addMeasure <- function(
#' @rdname remove
removeMeasure <- function( map ){
invokeMethod(
map
, getMapData(map)
, 'removeMeasure'
map,
getMapData(map),
'removeMeasure'
)
}
56 changes: 56 additions & 0 deletions inst/errors/errors.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Errors

### ? leaflet


```{r}
m %>% addMarkers(rand_lng(), rand_lat())
# html/css/js errors
# imagesmarker-icon-2x.png Failed to load resource: the server responded with a status of 403 (Forbidden)
# imagesmarker-shadow.png Failed to load resource: the server responded with a status of 403 (Forbidden)
```

error was pre-existing and not caused by 1.0.3
fixed but not solved [commit](https://github.com/timelyportfolio/leaflet/commit/4b841f02c399a206c84642a42e5eb189498f9b65)


### controls

leaflet-measure and layersControl do not remove

not an `v1.0.3` issue but fixed [commit](https://github.com/timelyportfolio/leaflet/commit/c6762e313f268954d8c19225177a991129c20a98) and [commit](https://github.com/timelyportfolio/leaflet/commit/55334c10536f6bc0b7250139e64e262f2cb48c51). However, none of controls use `ControlStore` mechanism, so would be nice to resolve this on a grander scale.


### labels/tooltips

https://github.com/Leaflet/Leaflet.label#upgrade-path-to-ltooltip

leaflet-label now in main leaflet as L.tooltip. How do we handle changed options in `labelOptions`?. Do we just translate `clickable` to `interactive` and `clickable` to `interactive` in R so old examples still work?

**NOTE: starting with Leaflet 1.0, `L.Label` is added to Leaflet core as `L.Tooltip` and this plugin is deprecrated.**

### Upgrade path to L.Tooltip

- `bindLabel`, `openLabel` and so should be replaced by `bindTooltip`, `openTooltip`, etc.
- option `clickable` is now named `interactive`
- option `noHide` is now named `permanent`
- default `offset` is now [6, -6]
- default `direction` is now `auto`
- default `opacity` is now `0.9`
- the CSS has been fully refactored

- Bonus: L.Tooltip also works for paths: polygons, polylines, etc.
- Bonus: new directions are supported: `top`, `bottom`, `center`
- Bonus: new option `sticky` will make the label follow the mouse instead of being displayed at the feature center


* removed leaflet-label source and in yaml in [commit]()


### tileLayer.canvas no longer available

```
library(mapview)

leaflet() %>% addRasterImage(poppendorf[[1]])
```
34 changes: 34 additions & 0 deletions inst/examples/crosstalk.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# devtools::install_github("rstudio/crosstalk")
# devtools::install_github("rstudio/leaflet")

library(crosstalk)
library(leaflet)
library(htmlwidgets)

rand_lng = function(n = 10) rnorm(n, -93.65, .01)
rand_lat = function(n = 10) rnorm(n, 42.0285, .01)

pts <- SharedData$new(
data.frame(
lng = rand_lng(),
lat = rand_lat()
),
group = "grp1"
)


lf <- leaflet(pts) %>%
addTiles() %>%
addMarkers()


onRender(
lf,
"
function(el,x) {
debugger;
var sl = new crosstalk.SelectionHandle('grp1');
sl.on('change', function(val){console.log(val);})
}
"
)
65 changes: 65 additions & 0 deletions inst/examples/crosstalk_shiny.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# devtools::install_github("rstudio/crosstalk")
# devtools::install_github("rstudio/leaflet")

library(crosstalk)
library(leaflet)
library(shiny)
library(dplyr)

rand_lng = function(n = 10) rnorm(n, -93.65, .01)
rand_lat = function(n = 10) rnorm(n, 42.0285, .01)

pts <- SharedData$new(
data.frame(
id = 1:10,
lng = rand_lng(),
lat = rand_lat()
),
key = ~id,
group = "grp1"
)


ui <- fluidPage(
fluidRow(
column(2, filter_select(id="filterselect", label="Points", sharedData=pts, group=~id)),
column(6, leafletOutput("leaflet1"))
),
h4("Selected points"),
verbatimTextOutput("selectedpoints")
)

server <- function(input, output, session) {

pts <- SharedData$new(
data.frame(
id = 1:10,
lng = rand_lng(),
lat = rand_lat()
),
key = ~id,
group = "grp1"
)


lf <- leaflet(pts) %>%
addTiles() %>%
addMarkers()

not_rendered <- TRUE

output$leaflet1 <- renderLeaflet({
if(req(not_rendered,cancelOutput=TRUE)) {
not_rendered <- FALSE
lf
}
})

output$selectedpoints <- renderPrint({
df <- pts$data(withSelection = TRUE)
cat(nrow(df), "observation(s) selected\n\n")
str(dplyr::glimpse(df))
})
}

shinyApp(ui, server)
30 changes: 30 additions & 0 deletions inst/examples/draw_shiny_deleted.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
library(leaflet)
library(leaflet.extras)
library(shiny)

#using examples from ?leaflet
rand_lng = function(n = 10) rnorm(n, -93.65, .01)
rand_lat = function(n = 10) rnorm(n, 42.0285, .01)
m = leaflet() %>%
addTiles() %>%
addPolygons(rand_lng(4), rand_lat(4), group = 'foo') %>%
addPolygons(rand_lng(4), rand_lat(4), group = 'foo') %>%
addDrawToolbar(targetGroup = "foo", editOptions = editToolbarOptions())

# do this in GlobalEnv only for example purposes
deleted <- list()
ui <- leafletOutput("leafmap")
server <- function(input, output, session) {
output$leafmap <- renderLeaflet({m})

observeEvent(input$leafmap_draw_deleted_features,{
str(input$leafmap_draw_deleted_features, max.level=2)
deleted <<- c(
deleted,
input$leafmap_draw_deleted_features
)
})
}
shinyApp(ui, server)

str(deleted, max.level=2)
Loading