Select to view content in your preferred language

Popup not pointing to feature and zoom to throws an error

573
1
Jump to solution
10-12-2022 04:36 PM
Aeseir
by
Frequent Contributor

I want to activate pop up for a selected feature, move the map to show the popup location, and then if i choose to use the zoom to function to go to the feature.

Unfortunately it throws an error: "Cannot center at a location without a target and view."

 

Here is what i have so far:

 

var fl = this.view?.map.findLayerById(data.featureLayerGroup.id);
fl.queryFeatures({ where: "id = '" + data.id + "'" }).then(results => {
      if (results.features.length) {
        this.view?.popup.open({
          features: results.features
        });
      }
    }
    );

 

I been going through the docs but cannot find the solution

0 Kudos
1 Solution

Accepted Solutions
Aeseir
by
Frequent Contributor

Figured it out, simple yet couldn't find it in docs.

 

If you want the popup to point to the feature at hand, you need to ensure the query returns the geometry AND updateLocationEnabled is enabled.

 

new code:

 

var fl = this.view?.map.findLayerById(data.featureLayerGroup.id);
fl.queryFeatures({ where: "id = '" + data.id + "'", returnGeometry: true  }).then(results => {
      if (results.features.length) {
        this.view?.popup.open({
          features: results.features,
          updateLocationEnabled: true
        });
      }
    }
    );

View solution in original post

0 Kudos
1 Reply
Aeseir
by
Frequent Contributor

Figured it out, simple yet couldn't find it in docs.

 

If you want the popup to point to the feature at hand, you need to ensure the query returns the geometry AND updateLocationEnabled is enabled.

 

new code:

 

var fl = this.view?.map.findLayerById(data.featureLayerGroup.id);
fl.queryFeatures({ where: "id = '" + data.id + "'", returnGeometry: true  }).then(results => {
      if (results.features.length) {
        this.view?.popup.open({
          features: results.features,
          updateLocationEnabled: true
        });
      }
    }
    );
0 Kudos