diff --git a/DESCRIPTION b/DESCRIPTION index 5daf84eb..eba88e01 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: mapdeck Type: Package Title: Interactive Maps Using 'Mapbox GL JS' and 'Deck.gl' -Version: 0.3.5 -Date: 2024-01-29 +Version: 0.3.6 +Date: 2024-07-02 Authors@R: c( person("David", "Cooley", ,"dcooley@symbolix.com.au", role = c("aut", "cre")) ) diff --git a/inst/htmlwidgets/lib/view_state/view_state.js b/inst/htmlwidgets/lib/view_state/view_state.js index 6d19a738..ecc7c386 100644 --- a/inst/htmlwidgets/lib/view_state/view_state.js +++ b/inst/htmlwidgets/lib/view_state/view_state.js @@ -1,3 +1,4 @@ +/* function add_view_state( map_id, viewState ) { 'use strict'; @@ -26,7 +27,6 @@ function add_view_state( map_id, viewState ) { } } - function md_placeViewState( map_id, object ) { var mapbox_ctrl = document.getElementById( "mapViewStateContainer"+map_id); @@ -44,3 +44,4 @@ function clear_view_state( map_id ) { } +*/ diff --git a/inst/htmlwidgets/mapdeck.js b/inst/htmlwidgets/mapdeck.js index 50f7913c..993edad9 100644 --- a/inst/htmlwidgets/mapdeck.js +++ b/inst/htmlwidgets/mapdeck.js @@ -61,7 +61,7 @@ HTMLWidgets.widget({ } // INITIAL VIEW - window[el.id + 'INITIAL_VIEW_STATE'] = { + const initialViewState = { longitude: x.location[0], latitude: x.location[1], zoom: x.zoom, @@ -73,17 +73,19 @@ HTMLWidgets.widget({ minPitch: x.min_pitch }; + window[el.id + 'viewState'] = initialViewState; + + const mapView = new deck.MapView({ + id: el.id, + repeat: x.repeat_view + }) + if( x.access_token === null ) { deckgl = new deck.DeckGL({ - views: [ new deck.MapView({ - id: el.id, - repeat: x.repeat_view, -// width: width, -// height: height - }) ], + views: [mapView], map: false, container: el.id, - initialViewState: window[el.id + 'INITIAL_VIEW_STATE'], + initialViewState: initialViewState, layers: [], controller: true //onLayerHover: setTooltip @@ -91,22 +93,22 @@ HTMLWidgets.widget({ window[el.id + 'map'] = deckgl; } else { deckgl = new deck.DeckGL({ - views: [ new deck.MapView({ - id: el.id, - repeat: x.repeat_view, -// width: width, -// height: height - }) - ], + views: [mapView], mapboxApiAccessToken: x.access_token, container: el.id, mapStyle: x.style, - initialViewState: window[el.id + 'INITIAL_VIEW_STATE'], + initialViewState: initialViewState, layers: [], controller: true, //onLayerHover: setTooltip onViewStateChange: ({viewId, viewState, interactionState}) => { + //console.log("onViewStateChange"); + //console.log(viewState); + + // issue 382 + window[el.id + 'viewState'] = viewState; + if (!HTMLWidgets.shinyMode && !x.show_view_state ) { return; } // as per: // https://github.com/uber/deck.gl/issues/3344 diff --git a/inst/htmlwidgets/mapdeck_location.js b/inst/htmlwidgets/mapdeck_location.js index 1062d4c2..03dd67a6 100644 --- a/inst/htmlwidgets/mapdeck_location.js +++ b/inst/htmlwidgets/mapdeck_location.js @@ -19,8 +19,25 @@ function md_change_location( map_id, map_type, location, zoom, pitch, bearing, d currentViewState = window[ map_id + 'map'].viewState["default-view"]; } else { - currentViewState = window[ map_id + 'map'].viewState; + //currentViewState = window[ map_id + 'map'].viewState; + currentViewState = window[ map_id + 'viewState']; } +/* + console.log("default-view"); + console.log(window[ map_id + 'map'].viewState["default-view"]); + + console.log("viewState"); + console.log(window[ map_id + 'map'].viewState); + console.log(window[ map_id + 'viewState']); + + + console.log("viewManager"); + console.log(window[ map_id + 'map'].viewManager); + + console.log("viewManager.viewState"); + console.log(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];