Select to view content in your preferred language

The ActiveViewChange function is not working

781
5
Jump to solution
11-08-2023 09:05 AM
Labels (1)
DéveloppeurP
New Contributor II

I tried to modify the widget for displaying map coordinates alongside it. However, when I launched it, I noticed that the ActiveViewChange function does not execute. Below is my widget's code.

export default class Widget extends React.Component<AllWidgetProps<IMConfig>, any>{
  constructor(props) {
    super(props);
  }
  ActiveViewChange = (jmv: JimuMapView): void => {
    console.log(jmv)
  }
  render() {
    return (
      <div className="widget-demo jimu-widget m-2">
        {this.props.hasOwnProperty("useMapWidgetIds") &&
          this.props.useMapWidgetIds &&
          this.props.useMapWidgetIds.length === 1 && (
            <JimuMapViewComponent
              useMapWidgetId={this.props.useMapWidgetIds?.[0]}
              onActiveViewChange={this.ActiveViewChange}
            />
          )}
        <p><FormattedMessage id="pr" defaultMessage={defaultMessages.pr} /></p>
      </div>
    )
  }
}

Is there anyone who might have an idea about the issue?

0 Kudos
1 Solution

Accepted Solutions
JeffreyThompson2
MVP Regular Contributor

The code above will get the first JimuMapView in an Experience, but because it is not dependent onActiveViewChange, it will not fail even if this widget loads before JimuMapView is created. You may need to add if checks for mapView to prevent other errors, especially on the first render of this widget.

GIS Developer
City of Arlington, Texas

View solution in original post

5 Replies
JeffreyThompson2
MVP Regular Contributor

The onActiveViewChange function may not operate the way you think it does. It only activates if the entire mapView is changed, as in the the entire map object is replaced with a completely separate map object. It is rarely if ever activated in most Experience Builder applications.

Does this explain your issue?

GIS Developer
City of Arlington, Texas
0 Kudos
DéveloppeurP
New Contributor II

I agree with you. However, upon display, it must still execute the function so that I can retrieve my jimuMapView, which should be displayed in the console.log().

0 Kudos
JeffreyThompson2
MVP Regular Contributor

I typically get the mapView with these two lines. They do not need to be within the onActiveViewChange function.

    const viewManager = MapViewManager.getInstance()
    const mapView = viewManager.getJimuMapViewById(viewManager.getAllJimuMapViewIds()[0])
GIS Developer
City of Arlington, Texas
0 Kudos
DéveloppeurP
New Contributor II

This code will allow you to retrieve the MapView from the widget inside the 'Carte' widget in question. My goal is to obtain the MapView of a 'Carte' widget from another widget, and to achieve that, I am required to go through JimuMapViewcomponent.

0 Kudos
JeffreyThompson2
MVP Regular Contributor

The code above will get the first JimuMapView in an Experience, but because it is not dependent onActiveViewChange, it will not fail even if this widget loads before JimuMapView is created. You may need to add if checks for mapView to prevent other errors, especially on the first render of this widget.

GIS Developer
City of Arlington, Texas