diff --git a/DESCRIPTION b/DESCRIPTION index ae186151..60fc2c87 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: leaflet.extras Type: Package Title: Extra functionality for leaflet package -Version: 0.1.3 +Version: 0.1.4 Authors@R: person("Bhaskar", "Karambelkar", email = "bhaskarvk@gmail.com", role = c("aut", "cre")) Description: Leaflet Javascript library provides many plugins some of which diff --git a/NAMESPACE b/NAMESPACE index 60b800c5..ada02b3a 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -6,10 +6,12 @@ export(addFullscreenControl) export(addGeoJSONChoropleth) export(addHash) export(addPulseMarkers) +export(addTopoJSONChoropleth) export(addWMSLegend) export(addWeatherMarkers) export(addWebGLHeatmap) export(clearGeoJSONChoropleth) +export(clearTopoJSONChoropleth) export(clearWebGLHeatmap) export(enableTileCaching) export(makePulseIcon) @@ -17,6 +19,7 @@ export(makeWeatherIcon) export(pulseIconList) export(pulseIcons) export(removeGeoJSONChoropleth) +export(removeTopoJSONChoropleth) export(removeWebGLHeatmap) export(weatherIconList) export(weatherIcons) diff --git a/NEWS.md b/NEWS.md index 46a283ed..521b6582 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,11 @@ -# leaflet.extras 0.1.2 +# leaflet.extras 0.1.4 + +* GeoJSON Choropleth now accepts popupOptions and labelOptions. +* Added addTopoJSONChoropleth (Thanks [TrantorM](https://github.com/TrantorM)). + +# leaflet.extras 0.1.3 -* Added WMS Legend Control +* Added WMS Legend Control. # leaflet.extras 0.1.2 diff --git a/R/geojson-choropleth.R b/R/geojson-choropleth.R index 348617d1..b768bcef 100644 --- a/R/geojson-choropleth.R +++ b/R/geojson-choropleth.R @@ -15,7 +15,9 @@ geoJSONChoroplethDependency <- function() { #' @param group the group this layer will be added to #' @param valueProperty The property to use for coloring #' @param popupProperty The property to use for popup content +#' @param popupOptions The Options for the popup #' @param labelProperty The property to use for labelling. +#' @param labelOptions The Options for the label #' @param scale The scale to use from chroma.js #' @param steps number of breakes #' @param mode q for quantile, e for equidistant, k for k-means @@ -38,8 +40,8 @@ geoJSONChoroplethDependency <- function() { addGeoJSONChoropleth = function( map, geojson, layerId = NULL, group = NULL, valueProperty, - labelProperty, - popupProperty, + labelProperty, labelOptions = leaflet::labelOptions(), + popupProperty, popupOptions = leaflet::popupOptions(), scale = c('white','red'), steps =5, mode = 'q', @@ -48,8 +50,6 @@ addGeoJSONChoropleth = function( color = "#03F", weight = 1, opacity = 0.5, - #fill = TRUE, - #fillColor = color, fillOpacity = 0.2, dashArray = NULL, smoothFactor = 1.0, @@ -60,7 +60,9 @@ addGeoJSONChoropleth = function( options = list( valueProperty=valueProperty, popupProperty=popupProperty, + popupOptions=popupOptions, labelProperty=labelProperty, + labelOptions=labelOptions, scale=scale, steps=steps, mode=mode, @@ -69,8 +71,6 @@ addGeoJSONChoropleth = function( color=color, weight=weight, opacity=opacity, - #fill=fill, - #fillColor=fillColor, fillOpacity=fillOpacity, dashArray=dashArray, smoothFactor=smoothFactor, diff --git a/R/topojson-choropleth.R b/R/topojson-choropleth.R new file mode 100644 index 00000000..57ead9f0 --- /dev/null +++ b/R/topojson-choropleth.R @@ -0,0 +1,96 @@ +# Source https://github.com/TrantorM/leaflet-choroplethTopoJSON +topoJSONChoroplethDependency <- function() { + list( + htmltools::htmlDependency( + "topojson-choropleth",version = "0.1.0", + system.file("htmlwidgets/lib/topojson-choropleth", package = "leaflet.extras"), + script = c("choroplethTopoJSON.min.js","topojson-choropleth-bindings.js") + ) + ) +} + +#' @param map The leaflet map +#' @param data Geojson or topojson data: either as a list or a string +#' @param layerId a unique ID for the layer +#' @param group the group this layer will be added to +#' @param valueProperty The property to use for coloring +#' @param popupProperty The property to use for popup content +#' @param popupOptions The Options for the popup +#' @param labelProperty The property to use for labelling. +#' @param labelOptions The Options for the label +#' @param scale The scale to use from chroma.js +#' @param steps number of breakes +#' @param mode q for quantile, e for equidistant, k for k-means +#' @param colors overrides scale with manual colors +#' @param stroke whether to draw stroke along the path (e.g. the borders of +#' polygons or circles) +#' @param color stroke color +#' @param weight stroke width in pixels +#' @param opacity stroke opacity (or layer opacity for tile layers) +#' circles) +#' @param fillOpacity fill opacity +#' @param dashArray a string that defines the stroke +#' \href{https://developer.mozilla.org/en/SVG/Attribute/stroke-dasharray}{dash +#' pattern} +#' @param smoothFactor how much to simplify the polyline on each zoom level +#' (more means better performance and less accurate representation) +#' @param noClip whether to disable polyline clipping +#' @rdname topojson-choropleth +#' @export +addTopoJSONChoropleth = function( + map, data, layerId = NULL, group = NULL, + valueProperty, + labelProperty, labelOptions = leaflet::labelOptions(), + popupProperty, popupOptions = leaflet::popupOptions(), + scale = c('white','red'), + steps =5, + mode = 'q', + colors = NULL, + stroke = TRUE, + color = "#03F", + weight = 1, + opacity = 0.5, + fillOpacity = 0.2, + dashArray = NULL, + smoothFactor = 1.0, + noClip = FALSE +) { + map$dependencies <- c(map$dependencies, + topoJSONChoroplethDependency()) + options = list( + valueProperty=valueProperty, + popupProperty=popupProperty, + popupOptions=popupOptions, + labelProperty=labelProperty, + labelOptions=labelOptions, + scale=scale, + steps=steps, + mode=mode, + colors=colors, + stroke=stroke, + color=color, + weight=weight, + opacity=opacity, + fillOpacity=fillOpacity, + dashArray=dashArray, + smoothFactor=smoothFactor, + noClip=noClip + ) + leaflet::invokeMethod( + map, leaflet::getMapData(map), 'addTopoJSONChoropleth', + data, layerId, group, options) +} + +#' removes the topojson choropleth. +#' @rdname topojson-choropleth +#' @export +removeTopoJSONChoropleth = function(map, layerId) { + leaflet::invokeMethod(map, leaflet::getMapData(map), 'removeTopoJSONChoropleth', layerId) +} + +#' clears the topojson choropleth. +#' @rdname topojson-choropleth +#' @export +clearTopoJSONChoropleth = function(map) { + leaflet::invokeMethod(map, NULL, 'clearTopoJSONChoropleth') +} diff --git a/README.md b/README.md index 3e7a5e75..9e73c6ec 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,8 @@ Plugins integrated so far - [Pulse Icon](https://github.com/mapshakers/leaflet-icon-pulse) Demo at [Rpubs: Pulse Icons](http://rpubs.com/bhaskarvk/leaflet-pulseIcon) - [Weather Markers](https://github.com/tallsam/Leaflet.weather-markers) Demo at [Rpubs: Weather Icons](http://rpubs.com/bhaskarvk/leaflet-weather) -- [Geojson Choropleth](https://github.com/timwis/leaflet-choropleth) Demo at [Rpubs: GeoJSON Choropleth](http://rpubs.com/bhaskarvk/geojson-choropleth) +- [GeoJSON Choropleth](https://github.com/timwis/leaflet-choropleth) Demo at [Rpubs: GeoJSON Choropleth](http://rpubs.com/bhaskarvk/geojson-choropleth) +- [TopoJSON Choropleth](https://github.com/TrantorM/leaflet-choroplethTopoJSON) Demo at [Rpubs: GeoJSON Choropleth](http://rpubs.com/bhaskarvk/topojson-choropleth) - [webgl-heatmap](https://github.com/ursudio/webgl-heatmap-leaflet) Demo at [Rpubs: Heatmap](http://rpubs.com/bhaskarvk/leaflet-heatmap) - [Tile Caching](https://github.com/MazeMap/Leaflet.TileLayer.PouchDBCached) Demo at [Rpubs: Tile Caching](http://rpubs.com/bhaskarvk/TileLayer-Caching) - [Leaflet Hash](https://github.com/mlevans/leaflet-hash) diff --git a/docs/TileCaching.html b/docs/TileCaching.html index a0ea002c..1c6ff465 100644 --- a/docs/TileCaching.html +++ b/docs/TileCaching.html @@ -2,7 +2,7 @@ -enableTileCaching. leaflet.extras 0.1.3 +enableTileCaching. leaflet.extras 0.1.4 @@ -32,7 +32,7 @@