Skip to content

Commit

Permalink
fully reverted #382
Browse files Browse the repository at this point in the history
  • Loading branch information
dcooley committed May 21, 2024
1 parent cfaa037 commit fdf5ade
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
4 changes: 1 addition & 3 deletions inst/htmlwidgets/mapdeck.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ HTMLWidgets.widget({
}) ],
map: false,
container: el.id,
viewState: window[el.id + 'INITIAL_VIEW_STATE'],
initialViewState: window[el.id + 'INITIAL_VIEW_STATE'],
layers: [],
controller: true
//onLayerHover: setTooltip
Expand Down Expand Up @@ -140,7 +140,6 @@ HTMLWidgets.widget({
if (!HTMLWidgets.shinyMode ) { return; }

Shiny.onInputChange(el.id + '_view_change', viewState);
deckgl.setProps({ viewState })
},

onDragStart(info, event){
Expand Down Expand Up @@ -225,4 +224,3 @@ if (HTMLWidgets.shinyMode) {
}
});
}

42 changes: 25 additions & 17 deletions inst/htmlwidgets/mapdeck_location.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,41 @@ function md_change_location( map_id, map_type, location, zoom, pitch, bearing, d
var currentMinZoom;
var currentMaxPitch;
var currentMinPitch;
var currentViewState;

if( map_type == "google_map" ) {
//console.log( location );
window[map_id + 'map'].setCenter( { lat: location[1], lng: location[0] } );
window[map_id + 'map'].setZoom( zoom );
} else {

if ( window[ map_id + 'map'].viewManager.viewState["default-view"] !== undefined ) {

currentViewState = window[ map_id + 'map'].viewManager.viewState["default-view"]
console.log( window[ map_id + 'map' ].viewState.longitude );

if ( window[ map_id + 'map'].viewState["default-view"] !== undefined ) {
currentLon = (location === null || location.length == 0) ? window[ map_id + 'map'].viewState["default-view"].longitude : location[0];
currentLat = (location === null || location.length == 0) ? window[ map_id + 'map'].viewState["default-view"].latitude : location[1];
currentPitch = pitch === null ? window[ map_id + 'map'].viewState["default-view"].pitch : pitch;
currentBearing = bearing === null ? window[ map_id + 'map' ].viewState["default-view"].bearing : bearing;
currentZoom = zoom === null ? window[ map_id + 'map'].viewState["default-view"].zoom : zoom;
currentMaxZoom = window[ map_id + 'map'].viewState["default-view"].maxZoom;
currentMinZoom = window[ map_id + 'map'].viewState["default-view"].minZoom;
currentMaxPitch = window[ map_id + 'map'].viewState["default-view"].maxPitch;
currentMinPitch = window[ map_id + 'map'].viewState["default-view"].minPitch;
} else {
currentViewState = window[ map_id + 'map'].viewManager.viewState
currentLon = (location === null || location.length == 0) ? window[ map_id + 'map'].viewState.longitude : location[0];
currentLat = (location === null || location.length == 0) ? window[ map_id + 'map'].viewState.latitude : location[1];
currentPitch = pitch === null ? window[ map_id + 'map'].viewState.pitch : pitch;
currentBearing = bearing === null ? window[ map_id + 'map' ].viewState.bearing : bearing;
currentZoom = zoom === null ? window[ map_id + 'map'].viewState.zoom : zoom;
currentMaxZoom = window[ map_id + 'map'].viewState.maxZoom;
currentMinZoom = window[ map_id + 'map'].viewState.minZoom;
currentMaxPitch = window[ map_id + 'map'].viewState.maxPitch;
currentMinPitch = window[ map_id + 'map'].viewState.minPitch;
}

currentViewState = window[ map_id + 'map'].viewManager.viewState
currentLon = (location === null || location.length == 0) ? currentViewState.longitude : location[0];
currentLat = (location === null || location.length == 0) ? currentViewState.latitude : location[1];
currentPitch = pitch === null ? currentViewState.pitch : pitch;
currentBearing = bearing === null ? currentViewState.bearing : bearing;
currentZoom = zoom === null ? currentViewState.zoom : zoom;
currentMaxZoom = currentViewState.maxZoom;
currentMinZoom = currentViewState.minZoom;
currentMaxPitch = currentViewState.maxPitch;
currentMinPitch = currentViewState.minPitch;
console.log( currentLon );

window[map_id + 'map'].setProps({
viewState: {
initialViewState: {
longitude: currentLon,
latitude: currentLat,
zoom: currentZoom,
Expand All @@ -48,11 +55,13 @@ function md_change_location( map_id, map_type, location, zoom, pitch, bearing, d
controller: true
}
});

}
}

function md_update_style( map_id, style ) {

var vs = window[ map_id + 'map'].viewState;
var map = window[ map_id + 'map'].getMapboxMap();
map.setStyle( style );

Expand Down Expand Up @@ -249,4 +258,3 @@ function md_get_zoom_level( globalBox ) {

return diff;
}

0 comments on commit fdf5ade

Please sign in to comment.