Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -20,7 +20,7 @@ Imports:
methods
Encoding: UTF-8
LazyData: true
RoxygenNote: 6.1.1
RoxygenNote: 7.2.1
Suggests:
knitr,
rmarkdown,
Expand Down
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,19 @@ export(as_mapbox_source)
export(basemap_background_style)
export(basemap_raster_style)
export(fit_bounds)
export(fly_to)
export(mapbox_source)
export(mapboxer)
export(mapboxerOutput)
export(mapboxer_proxy)
export(remove_source)
export(renderMapboxer)
export(set_data)
export(set_feature_state)
export(set_filter)
export(set_layout_property)
export(set_paint_property)
export(set_source_tiles)
export(set_style)
export(set_view_state)
export(stamen_raster_tiles)
Expand Down
7 changes: 4 additions & 3 deletions R/controls.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#' Add a standard control to the map
#' @inheritParams set_view_state
#' @param control_name The (class) name of the control.
#' @param ... The options of the control.
#' @param ... The options of the control. If named, converted into an object passed to the constructor; if not, converted into arguments passed to tne constructor in the same order.
#' @param pos The position of the control. One of \code{top-left}, \code{top-right},
#' \code{bottom-right} or \code{bottom-left}.
#' @param top_level The name of the higher level class for the constrcutor (defaults to "mapboxgl")
#' @seealso \url{https://docs.mapbox.com/mapbox-gl-js/api/markers/} for available options for the used control.
#' @example examples/api-reference/standard-controls.R
#' @export
add_control <- function(map, control_name, ..., pos = NULL) {
add_control <- function(map, control_name, ..., pos = NULL, top_level = "mapboxgl") {
map %>%
invoke_method("addControl", controlName = control_name, pos = pos, options = list(...))
invoke_method("addControl", controlName = control_name, topLevel = top_level, pos = pos, options = list(...))
}

#' @export
Expand Down
8 changes: 8 additions & 0 deletions R/fly-to.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#' Fly to a specific location
#' @param map A \link{mapboxer} object.
#' @param center The location coordinates as a vector in [lat, lng] order
#' @param ... Optional arguments, see \url{https://docs.mapbox.com/mapbox-gl-js/api/map/#map#flyto}.
#' @export
fly_to <- function(map, center, ...) {
invoke_method(map, "flyTo", options = list(center = center, ...))
}
16 changes: 14 additions & 2 deletions R/layers_update.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ NULL
#' @export
set_paint_property <- function(map, layer_id, property, value) {
map %>%
invoke_method("setPaintProperty", layer = layer_id, property = sub("_", "-", property), value = value)
invoke_method("setPaintProperty", layer = layer_id, property = gsub("_", "-", property), value = value)
}

#' @describeIn set_layer_properties Update a layout property of a layer.
Expand All @@ -21,7 +21,7 @@ set_layout_property <- function(map, layer_id, property, value) {
}

map %>%
invoke_method("setLayoutProperty", layer = layer_id, property = property, value = value)
invoke_method("setLayoutProperty", layer = layer_id, property = gsub("_", "-", property), value = value)
}

#' Update the data of a Mapbox source
Expand Down Expand Up @@ -66,3 +66,15 @@ set_data.sf <- function(map, data, source_id, ...) {
map %>%
set_data_(geojsonsf::sf_geojson(data, simplify = FALSE), source_id)
}


#' Set feature state
#' See https://docs.mapbox.com/mapbox-gl-js/api/map/#map#setfeaturestate
#' @param source A Mapbox source.
#' @param feature_id The id of the feature to set the state for (one at a time)
#' @param feature_source The source
#' @param feature_source_layer The source layer (required for vector layers)
#' @export
set_feature_state <- function(map, feature_id, feature_source, feature_source_layer = NULL, state) {
invoke_method(map, "setFeatureState", feature = list(id = feature_id, source = feature_source, sourceLayer = feature_source_layer), state = state)
}
16 changes: 16 additions & 0 deletions R/sources.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ add_source <- function(map, source, id = "mapboxer") {
invoke_method(map, "addSource", id = id, source = source)
}

#' Remove a Mapbox source from the map
#' @inheritParams set_view_state
#' @param id The unique id of the data source to remove.
#' @export
remove_source <- function(map, id = "mapboxer") {
invoke_method(map, "removeSource", id = id)
}

#' Create a Mapbox source
#' @param type The type of the source, e. g. \code{geojson}.
#' @param ... The properties of the source.
Expand Down Expand Up @@ -49,3 +57,11 @@ as_mapbox_source.sf <- function(data, ...) {
geojsonsf::sf_geojson(data, simplify = FALSE) %>%
mapbox_geojson_source(...)
}

#' Update the tiles URL of a vector source
#' @param source_id The id of the data source to update
#' @param tiles A new list of tile urls
#' @export
set_source_tiles <- function(map, source_id, tiles) {
invoke_method(map, "setSourceTiles", sourceId = source_id, tiles = tiles)
}
2 changes: 1 addition & 1 deletion inst/htmlwidgets/deps.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mapbox-gl:
name: "mapbox-gl"
version: "1.11.0"
version: "1.13.2"
src: "htmlwidgets/lib/mapbox-gl"
script: "mapbox-gl.js"
stylesheet: "mapbox-gl.css"
Expand Down
4 changes: 2 additions & 2 deletions inst/htmlwidgets/lib/mapbox-gl/get-mapbox-gl.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh

wget https://unpkg.com/mapbox-gl/dist/mapbox-gl.js
wget https://unpkg.com/mapbox-gl/dist/mapbox-gl.css
wget https://unpkg.com/mapbox-gl@1.13.2/dist/mapbox-gl.js -O mapbox-gl.js
wget https://unpkg.com/mapbox-gl@1.13.2/dist/mapbox-gl.css -O mapbox-gl.css

2 changes: 1 addition & 1 deletion inst/htmlwidgets/lib/mapbox-gl/mapbox-gl.css

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions inst/htmlwidgets/lib/mapbox-gl/mapbox-gl.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion inst/htmlwidgets/mapboxer.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions javascript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"description": "",
"private": true,
"scripts": {
"build": "webpack src/index.js --mode production -o ../inst/htmlwidgets/mapboxer.js",
"start": "webpack-dev-server src/test.js --mode development -o bundle.js --open",
"build": "export NODE_OPTIONS=--openssl-legacy-provider; webpack src/index.js --mode production -o ../inst/htmlwidgets/mapboxer.js",
"start": "export NODE_OPTIONS=--openssl-legacy-provider; webpack-dev-server src/test.js --mode development -o bundle.js --open",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
Expand Down
36 changes: 34 additions & 2 deletions javascript/src/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import { DEFAULT_SOURCE } from "./constants";

function addControl(args) {
const map = this;
const control = new mapboxgl[args.controlName](args.options);
let control;
if (Array.isArray(args.options)) {
control = args.topLevel ? new window[args.topLevel][args.controlName](...args.options) : new window[args.controlName](...args.options)
} else {
control = args.topLevel ? new window[args.topLevel][args.controlName](args.options) : new window[args.controlName](args.options)
}
map.addControl(control, args.pos);
}

Expand All @@ -13,6 +18,11 @@ function addSource(args) {
map.addSource(args.id, args.source);
}

function removeSource(args) {
const map = this;
map.removeSource(args.id);
}

function addLayer(args) {
const map = this;
args.style.source = args.style.source || DEFAULT_SOURCE;
Expand Down Expand Up @@ -122,6 +132,11 @@ function fitBounds(args) {
map.fitBounds(args.bounds, args.options || { });
}

function flyTo(args) {
const map = this;
map.flyTo(args.options);
}

function setStyle(args) {
const map = this;
map.setStyle(args.style);
Expand All @@ -139,6 +154,20 @@ function addDrawControl(args) {
});
}

// UpdateSource
function setSourceTiles(args) {
const map = this;
map.getSource(args.sourceId).setTiles(args.tiles)

}

// setFeatureState
function setFeatureState(args) {
const map = this;
map.setFeatureState(args.feature, args.state)

}

export default {
addControl,
addSource,
Expand All @@ -153,6 +182,9 @@ export default {
setLayoutProperty,
setData,
fitBounds,
flyTo,
setStyle,
addDrawControl
addDrawControl,
setSourceTiles,
setFeatureState
};
2 changes: 2 additions & 0 deletions javascript/src/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const widgetData = {
methodName: "addControl",
args: {
controlName: "NavigationControl",
topLevel: "mapboxgl",
pos: "top-left",
options: {
showCompass: false
Expand All @@ -20,6 +21,7 @@ const widgetData = {
methodName: "addControl",
args: {
controlName: "ScaleControl",
topLevel: "mapboxgl",
pos: "bottom-right"
}
},
Expand Down
5 changes: 5 additions & 0 deletions javascript/src/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ export default function(widgetElement, width, height) {
map.on("load", () => widgetData.calls.forEach(({ methodName, args }) => {
methods[methodName].call(map, args);
}));

if (HTMLWidgets.shinyMode) {
map.on("load", () => {Shiny.setInputValue(widgetElement.id + "_loaded", true)});
};

}

function resize(width, height) {
Expand Down
28 changes: 20 additions & 8 deletions man/add_circle_layer.Rd

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

6 changes: 4 additions & 2 deletions man/add_control.Rd

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

2 changes: 1 addition & 1 deletion man/add_draw_control.Rd

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

22 changes: 16 additions & 6 deletions man/add_fill_layer.Rd

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

10 changes: 8 additions & 2 deletions man/add_filter_control.Rd

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

32 changes: 24 additions & 8 deletions man/add_line_layer.Rd

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

Loading