Skip to content

Commit

Permalink
more viewState stuff (for #211)
Browse files Browse the repository at this point in the history
  • Loading branch information
SymbolixAU committed Nov 15, 2019
1 parent 8cade3f commit 9323529
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
2 changes: 1 addition & 1 deletion R/mapdeck_map.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
) {
Expand Down
33 changes: 25 additions & 8 deletions inst/htmlwidgets/mapdeck.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
12 changes: 6 additions & 6 deletions man/mapdeck_update.Rd

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

0 comments on commit 9323529

Please sign in to comment.