Skip to content

Commit

Permalink
Clean code and support viewState access with viewId
Browse files Browse the repository at this point in the history
  • Loading branch information
Hernán Mejía committed May 20, 2024
1 parent 1ac4f0f commit cae6ffc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 25 deletions.
2 changes: 1 addition & 1 deletion inst/htmlwidgets/mapdeck.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ HTMLWidgets.widget({
mapboxApiAccessToken: x.access_token,
container: el.id,
mapStyle: x.style,
initialViewState: window[el.id + 'INITIAL_VIEW_STATE'],
viewState: window[el.id + 'INITIAL_VIEW_STATE'],
layers: [],
controller: true,
//onLayerHover: setTooltip
Expand Down
36 changes: 12 additions & 24 deletions inst/htmlwidgets/mapdeck_location.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,18 @@ function md_change_location( map_id, map_type, location, zoom, pitch, bearing, d
window[map_id + 'map'].setZoom( zoom );
} else {

console.log( window[ map_id + 'map' ].viewManager.viewState.longitude );

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

currentViewState = window[ map_id + 'map'].viewManager.getViewState(map_id)
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 );

Expand Down

0 comments on commit cae6ffc

Please sign in to comment.