diff --git a/NEWS.md b/NEWS.md index b28fd363..1ca4c996 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,7 +1,8 @@ # leaflet.extras2 (development version) * Included [Leaflet TimeSlider](https://github.com/dwilhelm89/LeafletSlider) plugin -* `addWMS` gained the `popupOptions` parameter +* `addWMS` gained the `layerId` argument and works like `leaflet::addWMSTiles` except for the `popupOptions` +* `Side-by-Side` doesn't propagate click events when dragging. Thanks to `f905a47` of [#23](https://github.com/digidem/leaflet-side-by-side/pull/23) # leaflet.extras2 1.0.0 diff --git a/R/wms.R b/R/wms.R index 92086575..e4fea31d 100644 --- a/R/wms.R +++ b/R/wms.R @@ -15,12 +15,6 @@ wmsDependency <- function() { #' single-tile/untiled/nontiled layers, shared WMS sources, and #' GetFeatureInfo-powered identify. #' @inheritParams leaflet::addWMSTiles -#' @param layers vector or list of WMS layers to show. The name of the layer is -#' used as the \code{layerId} (for \code{\link[leaflet]{removeTiles}} -#' purposes) -#' @param group the name of the group the newly created layers should belong to. -#' If \code{layers} contains multiple elements, the \code{layers} names are -#' used as group-names. #' @param popupOptions List of popup options. See #' \code{\link[leaflet]{popupOptions}}. Default is NULL. #' @inherit leaflet::addWMSTiles return @@ -41,19 +35,21 @@ wmsDependency <- function() { #' transparent = TRUE, #' format = "image/png", #' info_format = "text/html")) -addWMS <- function(map, baseUrl, layers = NULL, group = NULL, - options = WMSTileOptions(), attribution = NULL, +addWMS <- function(map, baseUrl, layerId = NULL, group = NULL, + options = WMSTileOptions(), + attribution = NULL, + layers = NULL, popupOptions = NULL, data = getMapData(map)) { if (is.null(layers)) { - stop("layers is a required argument") + stop("layers is a required argument with comma-separated list of WMS layers to show") } options$attribution <- attribution - # options$layers <- layers + options$layers <- layers map$dependencies <- c(map$dependencies, wmsDependency()) - invokeMethod(map, data, "addWMS", baseUrl, layers, + invokeMethod(map, data, "addWMS", baseUrl, layerId, group, options, popupOptions) } diff --git a/inst/htmlwidgets/lfx-side-by-side/lfx-side-by-side.js b/inst/htmlwidgets/lfx-side-by-side/lfx-side-by-side.js index 6d454a46..b0d0e810 100644 --- a/inst/htmlwidgets/lfx-side-by-side/lfx-side-by-side.js +++ b/inst/htmlwidgets/lfx-side-by-side/lfx-side-by-side.js @@ -79,6 +79,7 @@ this._divider = L.DomUtil.create('div', 'leaflet-sbs-divider', container) var range = this._range = L.DomUtil.create('input', 'leaflet-sbs-range', container) + range.addEventListener('click', function (e) { e.stopPropagation() }) range.type = 'range' range.min = 0 range.max = 1 diff --git a/inst/htmlwidgets/lfx-wms/leaflet.wms-bindings.js b/inst/htmlwidgets/lfx-wms/leaflet.wms-bindings.js index 1f43a164..09f5e61f 100644 --- a/inst/htmlwidgets/lfx-wms/leaflet.wms-bindings.js +++ b/inst/htmlwidgets/lfx-wms/leaflet.wms-bindings.js @@ -1,4 +1,4 @@ -LeafletWidget.methods.addWMS = function(baseUrl, layers, group, options, popupOptions) { +LeafletWidget.methods.addWMS = function(baseUrl, layerId, group, options, popupOptions) { if(options && options.crs) { options.crs = LeafletWidget.utils.getCRS(options.crs); @@ -11,6 +11,8 @@ LeafletWidget.methods.addWMS = function(baseUrl, layers, group, options, popupOp if (!this._map) { return; } + + // TODO - Check if body is empty? this._map.openPopup(info, latlng, popupOptions); // Adaptation for R/Shiny @@ -21,16 +23,7 @@ LeafletWidget.methods.addWMS = function(baseUrl, layers, group, options, popupOp } }); - // Add WMS source var source = L.wms.source(baseUrl, options); - - // Add layers - if (typeof(layers) === "string") { - var layer = source.getLayer(layers); - this.layerManager.addLayer(layer, "tile", layers, group); - } else { - layers.forEach(e => this.layerManager.addLayer( - source.getLayer(e), "tile", e, e)); - } + this.layerManager.addLayer(source.getLayer(options.layers), "tile", layerId, group); }; diff --git a/man/addWMS.Rd b/man/addWMS.Rd index 9053cd65..17c8acc5 100644 --- a/man/addWMS.Rd +++ b/man/addWMS.Rd @@ -7,10 +7,11 @@ addWMS( map, baseUrl, - layers = NULL, + layerId = NULL, group = NULL, options = WMSTileOptions(), attribution = NULL, + layers = NULL, popupOptions = NULL, data = getMapData(map) ) @@ -20,19 +21,21 @@ addWMS( \item{baseUrl}{a base URL of the WMS service} -\item{layers}{vector or list of WMS layers to show. The name of the layer is -used as the \code{layerId} (for \code{\link[leaflet]{removeTiles}} -purposes)} +\item{layerId}{the layer id} -\item{group}{the name of the group the newly created layers should belong to. -If \code{layers} contains multiple elements, the \code{layers} names are -used as group-names.} +\item{group}{the name of the group the newly created layers should belong to +(for \code{\link[leaflet]{clearGroup}} and \code{\link[leaflet]{addLayersControl}} purposes). +Human-friendly group names are permitted--they need not be short, +identifier-style names. Any number of layers and even different types of +layers (e.g. markers and polygons) can share the same group name.} \item{options}{a list of extra options for tile layers, popups, paths (circles, rectangles, polygons, ...), or other map elements} \item{attribution}{the attribution text of the tile layer (HTML)} +\item{layers}{comma-separated list of WMS layers to show} + \item{popupOptions}{List of popup options. See \code{\link[leaflet]{popupOptions}}. Default is NULL.}