Select to view content in your preferred language

ExpB code: runs in one location but not the other.....Why

367
2
04-19-2024 12:01 PM
Labels (1)
brundageb
Emerging Contributor

Below are pretty much 2 identical sets of code.

One set of code is called by a JimuMapviewComponent activeViewChangeHandler. Sets current JMV to correct Extent but does not reset the Home Button to needed extent.  does not error. just does not do it.

The other code is called by a DataSourceComponent Render.  This code sets current JMV to correct Extent AND sets  the Home Button to needed extent.

See below:

When the map is switched this code fires.  The map zooms to the previous saved extent(mv1Ext).  Then the JimuMaptool (jsapi Home widget) is found.  But the Home widget will not take the new home extent of mv1Ext (which was just used above).   The Home extent defaults to all features in layer.

 const activeViewChangeHandler = (jmv: JimuMapView) => {
    if (jmv) {
      alert(jmv.dataSourceId)
      if (mapView.isActive) {
        alert('mapView.isActive') 
        if (mv1Ext) {
          jmv.view.goTo(mv1Ext)
          let myViewpoint = new Viewpoint ({targetGeometry: mv1Ext})
          const MapTools:JimuMapTool[] = jmv.jimuMapTools
          MapTools.forEach( (element) => {
            if (element.name === "Home") {
              alert('found Home Widget')
              element.instance.viewpoint = new Viewpoint({targetGeometry: mv1Ext})
            }
          })
        }       
      }
    }
  }

The above code is used in the jmv component render event

See successfully executing code below:  This is called by a DataSourceComponent Render.

    else if (myTitle.includes("Hot")) {
      if (!mapView.isActive) {return}
      mySQL = HZquery.where
      if (myTitle.includes("Hot")) {     
        DL_layer.definitionExpression = mySQL
          DL_layer.when(() => {
            return DL_layer.queryExtent()
          })
          .then((response) => {
            myExt = response.extent
            myExt.expand(1.25)
            mv1Ext = myExt
            mapView.view.goTo(myExt)
            const MapTools:JimuMapTool[] = mapView.jimuMapTools
            MapTools.forEach( (element) => {
              if (element.name === "Home") {
                element.instance.viewpoint = new Viewpoint({targetGeometry: mv1Ext})
              }
            })
          })
        }   
    }

 Note the same code getting the jsapi Home widget.  This code executes fine and sets the Home extent to the previously set mv1Ext.

Any ideas what is going on?

BobinTN

0 Kudos
2 Replies
TimWestern
Frequent Contributor

My first thought when looking at these two clips was the following.

I'm presuming that mapView exists and isActive returns a boolean and not null, is it possible mv1Ext doesn't exist when it is called?

The only other thought that I can think of, is that this is an issue where there won't be a rerender because the props being used in that function have not changed.  It may be you need something to signal that it should force re-render.


0 Kudos
brundageb
Emerging Contributor

Hey Tim, 

Thanks so much for responding.  MapView.isActive does return a Boolean.  

In both sets of code mv1Ext is present with value because the Active MapView Does get set to this mv1Ext (the map zooms to this mv1Ext).

But on the activeViewChangeHandler execution the code (sets and zooms to mv1Ext) but does not set the mv1Ext to the Home button (JimuMapTool). 

 

0 Kudos