@@ -1203,58 +1203,68 @@ class NetJSONGraphUtil {
12031203 if ( ! self . config . bookmarkableActions . enabled ) return ;
12041204 const fragments = this . parseUrlFragments ( ) ;
12051205 const id = self . config . bookmarkableActions . id ;
1206- let nodeId , zoom ;
1206+ let nodeId ;
1207+ self . selectedNode = self . selectedNode || { } ;
12071208 if ( params . componentSubType === "graph" ) {
12081209 nodeId = params . data . id ;
1210+ self . selectedNode [ nodeId ] = params . data
12091211 }
12101212 if ( [ "scatter" , "effectScatter" ] . includes ( params . componentSubType ) ) {
12111213 nodeId = params . data . node . id ;
1214+ self . selectedNode [ nodeId ] = params . data . node
12121215 }
1213- zoom = self ?. leaflet ?. getZoom ( ) ;
1214- if ( ! fragments [ id ] || ! ( fragments [ id ] instanceof URLSearchParams ) ) {
1216+ if ( ! fragments [ id ] ) {
12151217 fragments [ id ] = new URLSearchParams ( ) ;
12161218 fragments [ id ] . set ( "id" , id ) ;
12171219 }
12181220 fragments [ id ] . set ( "nodeId" , nodeId ) ;
1219- if ( zoom != null ) {
1220- fragments [ id ] . set ( "zoom" , zoom ) ;
1221- }
1222- window . location . hash = this . generateUrlFragments ( fragments ) ;
1221+ const newHash = this . generateUrlFragments ( fragments ) ;
1222+ const state = { id, nodeId } ;
1223+ history . pushState ( state , "" , `#${ newHash } ` ) ;
12231224 }
12241225
1225- removeUrlFragment ( self , id ) {
1226- if ( ! self . config . bookmarkableActions . enabled ) return ;
1227-
1226+ removeUrlFragment ( id ) {
12281227 const fragments = this . parseUrlFragments ( ) ;
12291228 if ( fragments [ id ] ) {
12301229 delete fragments [ id ] ;
12311230 }
1232- window . location . hash = this . generateUrlFragments ( fragments ) ;
1231+ const newHash = this . generateUrlFragments ( fragments ) ;
1232+ const state = { id } ;
1233+ history . pushState ( state , "" , `#${ newHash } ` ) ;
12331234 }
12341235
12351236 setSelectedNodeFromUrlFragments ( self , fragments , node ) {
12361237 if ( ! self . config . bookmarkableActions . enabled || ! Object . keys ( fragments ) . length ) return ;
12371238 const id = self . config . bookmarkableActions . id ;
12381239 const nodeId = fragments [ id ] ?. get ( "nodeId" ) ;
1239- const zoom = fragments [ id ] ?. get ( "zoom" ) ;
12401240 if ( nodeId === node . id ) {
1241- self . selectedNode = node ;
1242- if ( zoom != null ) self . selectedNode . zoom = Number ( zoom ) ;
1241+ self . selectedNode = self . selectedNode || { } ;
1242+ self . selectedNode [ nodeId ] = node ;
12431243 }
12441244 }
12451245
12461246 applyUrlFragmentState ( self ) {
1247+ console . log ( "ApplyUrlFragmentState Called!" )
12471248 if ( ! self . config . bookmarkableActions . enabled ) return ;
1248- const node = self . selectedNode ;
1249- if ( ! node ) return ;
1249+ const id = self . config . bookmarkableActions . id ;
1250+ const fragments = self . utils . parseUrlFragments ( ) ;
1251+ const nodeId = fragments [ id ] ?. get ( "nodeId" )
1252+ if ( ! self . selectedNode || ! self . selectedNode [ nodeId ] ) return ;
1253+ const node = self . selectedNode [ nodeId ] ;
12501254 const nodeType =
12511255 self . config . graphConfig . series . type || self . config . mapOptions . nodeConfig . type ;
1252- const { location, zoom } = node ;
1253- if ( [ "scatter" , "effectScatter" ] . includes ( nodeType ) && zoom != null ) {
1254- self . leaflet . setView ( [ location . lat , location . lng ] , zoom ) ;
1256+ const { location } = node ;
1257+ if ( [ "scatter" , "effectScatter" ] . includes ( nodeType ) ) {
1258+ self . leaflet . setView ( [ location . lat , location . lng ] ) ;
12551259 }
12561260 self . config . onClickElement . call ( self , "node" , node ) ;
12571261 }
1262+
1263+ setupHashChangeHandler ( self ) {
1264+ window . addEventListener ( 'popstate' , ( ) => {
1265+ this . applyUrlFragmentState ( self )
1266+ } ) ;
1267+ }
12581268}
12591269
12601270export default NetJSONGraphUtil ;
0 commit comments