Skip to content

Commit

Permalink
- 0.1.4 TopoJSON Choropleth support
Browse files Browse the repository at this point in the history
  • Loading branch information
Bhaskar Karambelkar committed Nov 2, 2016
1 parent ed0350c commit 7681044
Show file tree
Hide file tree
Showing 25 changed files with 641 additions and 46 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]",
role = c("aut", "cre"))
Description: Leaflet Javascript library provides many plugins some of which
Expand Down
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@ 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)
export(makeWeatherIcon)
export(pulseIconList)
export(pulseIcons)
export(removeGeoJSONChoropleth)
export(removeTopoJSONChoropleth)
export(removeWebGLHeatmap)
export(weatherIconList)
export(weatherIcons)
Expand Down
9 changes: 7 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
12 changes: 6 additions & 6 deletions R/geojson-choropleth.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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',
Expand All @@ -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,
Expand All @@ -60,7 +60,9 @@ addGeoJSONChoropleth = function(
options = list(
valueProperty=valueProperty,
popupProperty=popupProperty,
popupOptions=popupOptions,
labelProperty=labelProperty,
labelOptions=labelOptions,
scale=scale,
steps=steps,
mode=mode,
Expand All @@ -69,8 +71,6 @@ addGeoJSONChoropleth = function(
color=color,
weight=weight,
opacity=opacity,
#fill=fill,
#fillColor=fillColor,
fillOpacity=fillOpacity,
dashArray=dashArray,
smoothFactor=smoothFactor,
Expand Down
96 changes: 96 additions & 0 deletions R/topojson-choropleth.R
Original file line number Diff line number Diff line change
@@ -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')
}
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions docs/TileCaching.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="utf-8">
<title>enableTileCaching. leaflet.extras 0.1.3</title>
<title>enableTileCaching. leaflet.extras 0.1.4</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="author" content="">

Expand Down Expand Up @@ -32,7 +32,7 @@
<div class="navbar">
<div class="navbar-inner">
<div class="container">
<a class="brand" href="index.html">leaflet.extras 0.1.3</a>
<a class="brand" href="index.html">leaflet.extras 0.1.4</a>
<div class="nav">
<ul class="nav">
<li><a href="index.html">Home</a></li>
Expand Down
4 changes: 2 additions & 2 deletions docs/fullscreen.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="utf-8">
<title>addFullscreenControl. leaflet.extras 0.1.3</title>
<title>addFullscreenControl. leaflet.extras 0.1.4</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="author" content="">

Expand Down Expand Up @@ -32,7 +32,7 @@
<div class="navbar">
<div class="navbar-inner">
<div class="container">
<a class="brand" href="index.html">leaflet.extras 0.1.3</a>
<a class="brand" href="index.html">leaflet.extras 0.1.4</a>
<div class="nav">
<ul class="nav">
<li><a href="index.html">Home</a></li>
Expand Down
17 changes: 11 additions & 6 deletions docs/geojson-choropleth.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="utf-8">
<title>addGeoJSONChoropleth. leaflet.extras 0.1.3</title>
<title>addGeoJSONChoropleth. leaflet.extras 0.1.4</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="author" content="">

Expand Down Expand Up @@ -32,7 +32,7 @@
<div class="navbar">
<div class="navbar-inner">
<div class="container">
<a class="brand" href="index.html">leaflet.extras 0.1.3</a>
<a class="brand" href="index.html">leaflet.extras 0.1.4</a>
<div class="nav">
<ul class="nav">
<li><a href="index.html">Home</a></li>
Expand All @@ -55,10 +55,11 @@ <h1>removes the geojson choropleth.</h1>
<div class="span8">
<h2>Usage</h2>
<pre><span class="functioncall"><a href='geojson-choropleth.html'>addGeoJSONChoropleth</a></span><span class="keyword">(</span><span class="symbol">map</span><span class="keyword">,</span> <span class="symbol">geojson</span><span class="keyword">,</span> <span class="argument">layerId</span>&nbsp;<span class="argument">=</span>&nbsp;NULL<span class="keyword">,</span> <span class="argument">group</span>&nbsp;<span class="argument">=</span>&nbsp;NULL<span class="keyword">,</span>
<span class="symbol">valueProperty</span><span class="keyword">,</span> <span class="symbol">labelProperty</span><span class="keyword">,</span> <span class="symbol">popupProperty</span><span class="keyword">,</span> <span class="argument">scale</span>&nbsp;<span class="argument">=</span>&nbsp;<span class="functioncall"><a href='http://www.rdocumentation.org/packages/base/topics/c'>c</a></span><span class="keyword">(</span><span class="string">"white"</span><span class="keyword">,</span> <span class="string">"red"</span><span class="keyword">)</span><span class="keyword">,</span>
<span class="argument">steps</span>&nbsp;<span class="argument">=</span>&nbsp;<span class="number">5</span><span class="keyword">,</span> <span class="argument">mode</span>&nbsp;<span class="argument">=</span>&nbsp;<span class="string">"q"</span><span class="keyword">,</span> <span class="argument">colors</span>&nbsp;<span class="argument">=</span>&nbsp;NULL<span class="keyword">,</span> <span class="argument">stroke</span>&nbsp;<span class="argument">=</span>&nbsp;<span class="number">TRUE</span><span class="keyword">,</span> <span class="argument">color</span>&nbsp;<span class="argument">=</span>&nbsp;<span class="string">"#03F"</span><span class="keyword">,</span>
<span class="argument">weight</span>&nbsp;<span class="argument">=</span>&nbsp;<span class="number">1</span><span class="keyword">,</span> <span class="argument">opacity</span>&nbsp;<span class="argument">=</span>&nbsp;<span class="number">0.5</span><span class="keyword">,</span> <span class="argument">fillOpacity</span>&nbsp;<span class="argument">=</span>&nbsp;<span class="number">0.2</span><span class="keyword">,</span> <span class="argument">dashArray</span>&nbsp;<span class="argument">=</span>&nbsp;NULL<span class="keyword">,</span>
<span class="argument">smoothFactor</span>&nbsp;<span class="argument">=</span>&nbsp;<span class="number">1</span><span class="keyword">,</span> <span class="argument">noClip</span>&nbsp;<span class="argument">=</span>&nbsp;<span class="number">FALSE</span><span class="keyword">)</span>
<span class="symbol">valueProperty</span><span class="keyword">,</span> <span class="symbol">labelProperty</span><span class="keyword">,</span> <span class="argument">labelOptions</span>&nbsp;<span class="argument">=</span>&nbsp;<span class="package">leaflet</span><span class="keyword">::</span><span class="functioncall"><a href='http://www.rdocumentation.org/packages/leaflet/topics/map-options'>labelOptions</a></span><span class="keyword">(</span><span class="keyword">)</span><span class="keyword">,</span>
<span class="symbol">popupProperty</span><span class="keyword">,</span> <span class="argument">popupOptions</span>&nbsp;<span class="argument">=</span>&nbsp;<span class="package">leaflet</span><span class="keyword">::</span><span class="functioncall"><a href='http://www.rdocumentation.org/packages/leaflet/topics/map-options'>popupOptions</a></span><span class="keyword">(</span><span class="keyword">)</span><span class="keyword">,</span> <span class="argument">scale</span>&nbsp;<span class="argument">=</span>&nbsp;<span class="functioncall"><a href='http://www.rdocumentation.org/packages/base/topics/c'>c</a></span><span class="keyword">(</span><span class="string">"white"</span><span class="keyword">,</span>
<span class="string">"red"</span><span class="keyword">)</span><span class="keyword">,</span> <span class="argument">steps</span>&nbsp;<span class="argument">=</span>&nbsp;<span class="number">5</span><span class="keyword">,</span> <span class="argument">mode</span>&nbsp;<span class="argument">=</span>&nbsp;<span class="string">"q"</span><span class="keyword">,</span> <span class="argument">colors</span>&nbsp;<span class="argument">=</span>&nbsp;NULL<span class="keyword">,</span> <span class="argument">stroke</span>&nbsp;<span class="argument">=</span>&nbsp;<span class="number">TRUE</span><span class="keyword">,</span>
<span class="argument">color</span>&nbsp;<span class="argument">=</span>&nbsp;<span class="string">"#03F"</span><span class="keyword">,</span> <span class="argument">weight</span>&nbsp;<span class="argument">=</span>&nbsp;<span class="number">1</span><span class="keyword">,</span> <span class="argument">opacity</span>&nbsp;<span class="argument">=</span>&nbsp;<span class="number">0.5</span><span class="keyword">,</span> <span class="argument">fillOpacity</span>&nbsp;<span class="argument">=</span>&nbsp;<span class="number">0.2</span><span class="keyword">,</span>
<span class="argument">dashArray</span>&nbsp;<span class="argument">=</span>&nbsp;NULL<span class="keyword">,</span> <span class="argument">smoothFactor</span>&nbsp;<span class="argument">=</span>&nbsp;<span class="number">1</span><span class="keyword">,</span> <span class="argument">noClip</span>&nbsp;<span class="argument">=</span>&nbsp;<span class="number">FALSE</span><span class="keyword">)</span>

<span class="functioncall"><a href='geojson-choropleth.html'>removeGeoJSONChoropleth</a></span><span class="keyword">(</span><span class="symbol">map</span><span class="keyword">,</span> <span class="symbol">layerId</span><span class="keyword">)</span>

Expand All @@ -78,8 +79,12 @@ <h2>Arguments</h2>
<dd>The property to use for coloring</dd>
<dt>labelProperty</dt>
<dd>The property to use for labelling.</dd>
<dt>labelOptions</dt>
<dd>The Options for the label</dd>
<dt>popupProperty</dt>
<dd>The property to use for popup content</dd>
<dt>popupOptions</dt>
<dd>The Options for the popup</dd>
<dt>scale</dt>
<dd>The scale to use from chroma.js</dd>
<dt>steps</dt>
Expand Down
4 changes: 2 additions & 2 deletions docs/heatmap.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="utf-8">
<title>addWebGLHeatmap. leaflet.extras 0.1.3</title>
<title>addWebGLHeatmap. leaflet.extras 0.1.4</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="author" content="">

Expand Down Expand Up @@ -32,7 +32,7 @@
<div class="navbar">
<div class="navbar-inner">
<div class="container">
<a class="brand" href="index.html">leaflet.extras 0.1.3</a>
<a class="brand" href="index.html">leaflet.extras 0.1.4</a>
<div class="nav">
<ul class="nav">
<li><a href="index.html">Home</a></li>
Expand Down
9 changes: 5 additions & 4 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="utf-8">
<title>Home. leaflet.extras 0.1.3</title>
<title>Home. leaflet.extras 0.1.4</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="author" content="">

Expand Down Expand Up @@ -32,7 +32,7 @@
<div class="navbar">
<div class="navbar-inner">
<div class="container">
<a class="brand" href="index.html">leaflet.extras 0.1.3</a>
<a class="brand" href="index.html">leaflet.extras 0.1.4</a>
<div class="nav">
<ul class="nav">
<li><a href="index.html">Home</a></li>
Expand All @@ -55,15 +55,16 @@ <h1>leaflet.extras</h1>

<p>The goal of leaflet.extras is to provide extra functionality to leaflet R package using various leaflet plugins.</p>

<p>For now you&#39;ll have to build leaflet from github <code>devtools::install(&#39;rstudio/leaflet&#39;)</code>
<p>For now you&#39;ll have to build leaflet from github <code>devtools::install_github(&#39;rstudio/leaflet&#39;)</code>
to try this out. Check out the inst/examples for what&#39;s been done so far.</p>

<p>Plugins integrated so far</p>

<ul>
<li><a href="https://github.com/mapshakers/leaflet-icon-pulse">Pulse Icon</a> Demo at <a href="http://rpubs.com/bhaskarvk/leaflet-pulseIcon">Rpubs: Pulse Icons</a></li>
<li><a href="https://github.com/tallsam/Leaflet.weather-markers">Weather Markers</a> Demo at <a href="http://rpubs.com/bhaskarvk/leaflet-weather">Rpubs: Weather Icons</a></li>
<li><a href="https://github.com/timwis/leaflet-choropleth">Geojson Choropleth</a> Demo at <a href="http://rpubs.com/bhaskarvk/geojson-choropleth">Rpubs: GeoJSON Choropleth</a></li>
<li><a href="https://github.com/timwis/leaflet-choropleth">GeoJSON Choropleth</a> Demo at <a href="http://rpubs.com/bhaskarvk/geojson-choropleth">Rpubs: GeoJSON Choropleth</a></li>
<li><a href="https://github.com/TrantorM/leaflet-choroplethTopoJSON">TopoJSON Choropleth</a> Demo at <a href="http://rpubs.com/bhaskarvk/topojson-choropleth">Rpubs: GeoJSON Choropleth</a></li>
<li><a href="https://github.com/ursudio/webgl-heatmap-leaflet">webgl-heatmap</a> Demo at <a href="http://rpubs.com/bhaskarvk/leaflet-heatmap">Rpubs: Heatmap</a></li>
<li><a href="https://github.com/MazeMap/Leaflet.TileLayer.PouchDBCached">Tile Caching</a> Demo at <a href="http://rpubs.com/bhaskarvk/TileLayer-Caching">Rpubs: Tile Caching</a></li>
<li><a href="https://github.com/mlevans/leaflet-hash">Leaflet Hash</a></li>
Expand Down
4 changes: 2 additions & 2 deletions docs/leaflet.extras.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="utf-8">
<title>leaflet.extras. leaflet.extras 0.1.3</title>
<title>leaflet.extras. leaflet.extras 0.1.4</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="author" content="">

Expand Down Expand Up @@ -32,7 +32,7 @@
<div class="navbar">
<div class="navbar-inner">
<div class="container">
<a class="brand" href="index.html">leaflet.extras 0.1.3</a>
<a class="brand" href="index.html">leaflet.extras 0.1.4</a>
<div class="nav">
<ul class="nav">
<li><a href="index.html">Home</a></li>
Expand Down
4 changes: 2 additions & 2 deletions docs/leaflethash.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="utf-8">
<title>addHash. leaflet.extras 0.1.3</title>
<title>addHash. leaflet.extras 0.1.4</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="author" content="">

Expand Down Expand Up @@ -32,7 +32,7 @@
<div class="navbar">
<div class="navbar-inner">
<div class="container">
<a class="brand" href="index.html">leaflet.extras 0.1.3</a>
<a class="brand" href="index.html">leaflet.extras 0.1.4</a>
<div class="nav">
<ul class="nav">
<li><a href="index.html">Home</a></li>
Expand Down
Loading

0 comments on commit 7681044

Please sign in to comment.