Skip to content

Commit

Permalink
layerId for addWMS, sideByside no click when drag
Browse files Browse the repository at this point in the history
  • Loading branch information
trafficonese committed Aug 18, 2020
1 parent 7a17032 commit 0a067f8
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 30 deletions.
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
18 changes: 7 additions & 11 deletions R/wms.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
1 change: 1 addition & 0 deletions inst/htmlwidgets/lfx-side-by-side/lfx-side-by-side.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 4 additions & 11 deletions inst/htmlwidgets/lfx-wms/leaflet.wms-bindings.js
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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
Expand All @@ -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);
};
17 changes: 10 additions & 7 deletions man/addWMS.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0a067f8

Please sign in to comment.