diff --git a/R/mapdeck_map.R b/R/mapdeck_map.R index fff0fa33..dc8fc110 100644 --- a/R/mapdeck_map.R +++ b/R/mapdeck_map.R @@ -150,9 +150,9 @@ renderMapdeck <- function(expr, env = parent.frame(), quoted = FALSE) { #' after the next time all of the outputs are updated; defaults to TRUE. #' @export mapdeck_update <- function( + data = NULL, map_id, session = shiny::getDefaultReactiveDomain(), - data = NULL, deferUntilFlush = TRUE, map_type = c("mapdeck_update", "google_map_update") ) { diff --git a/inst/htmlwidgets/mapdeck.js b/inst/htmlwidgets/mapdeck.js index 567697c0..744d5f64 100644 --- a/inst/htmlwidgets/mapdeck.js +++ b/inst/htmlwidgets/mapdeck.js @@ -72,30 +72,47 @@ HTMLWidgets.widget({ const nw = viewport.unproject([0, 0]); const se = viewport.unproject([viewport.width, viewport.height]); + const w = nw[0] < -180 ? -180 : ( nw[0] > 180 ? 180 : nw[0] ); + const n = nw[1] < -90 ? -90 : ( nw[1] > 90 ? 90 : nw[1] ); + + const e = se[0] < -180 ? -180 : ( se[0] > 180 ? 180 : se[0] ); + const s = se[1] < -90 ? -90 : ( se[1] > 90 ? 90 : se[1] ); + + /* + console.log(nw); + console.log(se); + + console.log(w); + console.log(e); + */ + viewState.viewBounds = { - north: nw[1], - east: se[0], - south: se[1], - west: nw[0] + north: n, //nw[1], + east: e, //se[0], + south: s, //se[1], + west: w //nw[0] }; viewState.interactionState = interactionState; + Shiny.onInputChange(el.id + '_view_change', viewState); }, onDragStart(info, event){ if (!HTMLWidgets.shinyMode) { return; } - if( info.layer !== null ) { info.layer = null; } // dragging a layer; + //if( info.layer !== null ) { info.layer = null; } // dragging a layer; + info.layer = undefined; // in case of dragging a layer Shiny.onInputChange(el.id +'_drag_start', info); }, onDrag(info, event){ if (!HTMLWidgets.shinyMode) { return; } - //console.log( info ); - if( info.layer !== null ) { info.layer = null; } // dragging a layer; + //if( info.layer !== null ) { info.layer = null; } // dragging a layer; + info.layer = undefined; // in case of dragging a layer Shiny.onInputChange(el.id +'_drag', info); }, onDragEnd(info, event){ if (!HTMLWidgets.shinyMode) { return; } - if( info.layer !== null ) { info.layer = null; } // dragging a layer; + //if( info.layer !== null ) { info.layer = null; } // dragging a layer; + info.layer = undefined; // in case of dragging a layer Shiny.onInputChange(el.id +'_drag_end', info); }, onResize(size) { diff --git a/man/mapdeck_update.Rd b/man/mapdeck_update.Rd index a2cb9c54..a2156a60 100644 --- a/man/mapdeck_update.Rd +++ b/man/mapdeck_update.Rd @@ -4,19 +4,19 @@ \alias{mapdeck_update} \title{Mapdeck update} \usage{ -mapdeck_update(map_id, session = shiny::getDefaultReactiveDomain(), - data = NULL, deferUntilFlush = TRUE, map_type = c("mapdeck_update", - "google_map_update")) +mapdeck_update(data = NULL, map_id, + session = shiny::getDefaultReactiveDomain(), deferUntilFlush = TRUE, + map_type = c("mapdeck_update", "google_map_update")) } \arguments{ +\item{data}{data to be used in the layer. All coordinates are expected to be +EPSG:4326 (WGS 84) coordinate system} + \item{map_id}{string containing the output ID of the map in a shiny application.} \item{session}{the Shiny session object to which the map belongs; usually the default value will suffice.} -\item{data}{data to be used in the layer. All coordinates are expected to be -EPSG:4326 (WGS 84) coordinate system} - \item{deferUntilFlush}{indicates whether actions performed against this instance should be carried out right away, or whether they should be held until after the next time all of the outputs are updated; defaults to TRUE.}