Skip to content

Commit

Permalink
copy unexported mapview:::initMap for #110
Browse files Browse the repository at this point in the history
  • Loading branch information
timelyportfolio committed Apr 14, 2020
1 parent 330c522 commit b5bad16
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 3 deletions.
80 changes: 80 additions & 0 deletions R/mapview_init.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
### these are all copies of unexported functions in mapview

# Initialise mapView map --------------------------------------------------

initMap <- function(map = NULL,
map.types = NULL,
proj4str,
native.crs = FALSE,
canvas = FALSE,
viewer.suppress = FALSE,
platform = mapviewGetOption("platform"),
...) {

# if (missing(map.types)) map.types <- mapviewGetOption("basemaps")
ls = list(...)
nms = names(ls)

if (platform %in% c("leaflet", "leafgl")) {

if (is.null(map) & is.null(map.types)) {
map.types <- mapviewGetOption("basemaps")
}

leafletHeight <- mapviewGetOption("leafletHeight")
leafletWidth <- mapviewGetOption("leafletWidth")

if (missing(proj4str)) proj4str <- NA
## create base map using specified map types
if (is.null(map)) {
if (is.na(proj4str) | native.crs) {
m <- leaflet::leaflet(
height = leafletHeight,
width = leafletWidth,
options = leaflet::leafletOptions(
minZoom = -1000,
crs = leafletCRS(crsClass = "L.CRS.Simple"),
preferCanvas = canvas),
sizingPolicy = leafletSizingPolicy(
viewer.suppress = viewer.suppress,
browser.external = viewer.suppress
)
)
} else {
m <- initBaseMaps(map.types, canvas = canvas, viewer.suppress = viewer.suppress)
}
} else {
m <- map
}

} else if (platform == "mapdeck") {

map.types = map.types[1]

if (is.null(map)) {
if (is.null(map.types)) {
map.types <- mapviewGetOption("basemaps")[1]
}

md_args = try(
match.arg(
nms,
names(as.list(args(mapdeck::mapdeck))),
several.ok = TRUE
)
, silent = TRUE
)
if (!inherits(md_args, "try-error")) {
md_args = ls[md_args]
md_args$style = map.types
m = do.call(mapdeck::mapdeck, Filter(Negate(is.null), md_args))
} else {
m = mapdeck::mapdeck(style = map.types)
}
} else {
m = map
}
}

return(m)
}
2 changes: 1 addition & 1 deletion R/select.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ selectFeatures.sf = function(
if (mode == "click") {

if (is.null(map)) {
map = mapview:::initMap(proj4str = sf::st_crs(x)$proj4string)
map = initMap(proj4str = sf::st_crs(x)$proj4string)
map = leafem::addFeatures(
map, data = x, layerId = ~x$edit_id, label = label, ...
)
Expand Down
4 changes: 2 additions & 2 deletions man/mapedit-package.Rd

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

0 comments on commit b5bad16

Please sign in to comment.