diff --git a/inst/htmlwidgets/mapdeck.js b/inst/htmlwidgets/mapdeck.js
index 9363687c..49bbae56 100644
--- a/inst/htmlwidgets/mapdeck.js
+++ b/inst/htmlwidgets/mapdeck.js
@@ -74,108 +74,28 @@ HTMLWidgets.widget({
//onLayerHover: setTooltip
onViewStateChange: ({viewId, viewState, interactionState}) => {
- //console.log("view");
- //console.log(view);
-
- //var lngLat = [144, -37];
- //var pos = [5,2];
- //console.log( deck.WebMercatorViewport.getMapCenterByLngLatPosition({ lngLat, pos }) );
- //console.log( deck.getMapCenterByLngLatPosition( viewState ) );
- //var vp = new deck.WebMercatorViewport({viewState});
- //console.log( vp );
- //console.log( deck.WebMercatorViewport );
- //console.log( viewId );
- //console.log( viewState );
- //console.log( interactionState );
- //return;
-
if (!HTMLWidgets.shinyMode && !x.show_view_state ) { return; }
// as per:
// https://github.com/uber/deck.gl/issues/3344
// https://github.com/SymbolixAU/mapdeck/issues/211
- //console.log("viewState");
- //console.log( viewState );
- const viewport = new deck.WebMercatorViewport({viewState});
- //console.log("viewport");
- //console.log( viewport );
-
- //console.log("initialViewState");
- //console.log(initialViewState);
-
- //console.log("dimensions: " );
- //console.log( getDimensions( 800, 900 ) );
-
- // 'project()' functions take lon/lat inputs
- // 'unproject()' functions take x/y (screen) inputs
- var lonlat_center = [ viewState.longitude, viewState.latitude ];
- var xy_center = viewport.projectFlat( lonlat_center );
-
- var xy_wh = [ viewState.width, viewState.height ];
- var lonlat_wh = viewport.unprojectFlat( [ viewState.width, viewState.height ] );
- //var minX = projected_center[0] - viewport.width;
- //var minY = projected_center[1] - viewport.height;
-
- //var projXY = viewport.unprojectFlat( [minX, minY] );
-
- //var lonlat_wh = viewport.unprojectFlat( [viewState.width, viewState.height, viewState.zoom ]);
-
-
- //var maxY = lonlat_wh[1] - xy_center[1];
- //var minY = projected_center[1] - maxY;
+ const viewport = new deck.WebMercatorViewport(viewState);
+ const nw = viewport.unproject([0, 0]);
+ const se = viewport.unproject([viewport.width, viewport.height]);
- //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 nw = viewport.unprojectFlat([0, 0]);
- //const se = viewport.unprojectFlat([viewState.width, viewState.height]);
+ 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 );
-
- //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] );
-
- var east = viewState.width - xy_center[0];
- var rightEdgeY = xy_center[1];
- var rigthEdgeLonLat = viewport.unprojectFlat( [rightEdgeX, rightEdgeY] );
-
- var val;
-
- val = {
- //lonlat_center: lonlat_center,
- //xy_center: viewport.projectFlat( lonlat_center ),
- //xy_wh: xy_wh,
- //lonlat_wh: lonlat_wh,
- //viewPort: viewport,
- viewState: viewState,
- xyz: viewport.projectFlat( [viewState.longitude, viewState.latitude ]),
- rightEdge: [rightEdgeX, rightEdgeY],
- rigthEdgeLonLat: rigthEdgeLonLat
- //getDistanceScales: viewport.getDistanceScales()
- //getCameraPosition: viewport.getCameraPosition(),
- //getCameraDirection: viewport.getCameraDirection(),
- //getCameraUp: viewport.getCameraUp()
- //maxY: maxY,
- //minY: minY
- };
-
- var vs = JSON.stringify( val, null, 2 );
- window[el.id + 'mapViewState'].innerHTML = vs;
-
- return;
-
-/*
- viewState.viewBounds = {
+ viewState.viewBounds = {
north: n, //nw[1],
east: e, //se[0],
south: s, //se[1],
west: w //nw[0]
};
viewState.interactionState = interactionState;
-*/
+
if( x.show_view_state ) {
var vs = JSON.stringify( viewState );
//console.log( vs );