Hello,
I'm trying to open the feature popup when my map is recieving a message:
window.addEventListener("message", function (event) {
if (event?.data?.type === "external") {
console.log(_getAllFeaturesRecursive(featureLayer,[]));
}
});
By doing this, I know that I need to open my popup...
I was using a function "getAllFeaturesRecursives" that get all the features:
const _getAllFeaturesRecursive = (layer, featuresSoFar) => {
return layer
.queryFeatures({
start: featuresSoFar.length,
num: layer.capabilities.query.maxRecordCount,
outFields: ['*']
})
.then((results) => {
if (
results.exceededTransferLimit &&
results.exceededTransferLimit === true
) {
return _getAllFeaturesRecursive(layer, [
...featuresSoFar,
...results.features
]);
} else {
var p = Promise.resolve([...featuresSoFar, ...results.features]).then((feat) => {
console.log(feat[0]);
feat[0].layer.popupEnabled = false;
feat[0].layer.popupEnabled = true;
});
}
});
};
So I tried to put popupenable to true, but it seems to be true foreach layers...
Do you have any ideas to open the feature popup (with focus) manually (without direct events on the map?)
Thanks 🙂
Solved! Go to Solution.
You can call the .open() method of the mapView's popup and pass in the feature or content you want to display. Might be something like this...
mapView.popup.open({ location: feat[0].geometry, features: [feat[0]] });
https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html#popup
https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Popup.html#open
Hm...It seems there was a problem with my method to get features, and also it seems to be useless:
Solution:
var query = {
objectIds: [event.data.objectid],
outFields: ["*"],
returnGeometry: true
};
featureLayer.queryFeatures(query)
.then(function(response){
// close view popup if it is open
view.popup.close();
// Open the new popup
var feat = response.features[0];
view.popup.open({ location: feat.geometry, features: [feat] });
});
// console
Special thanks to @TommyBramble 🙂
You can call the .open() method of the mapView's popup and pass in the feature or content you want to display. Might be something like this...
mapView.popup.open({ location: feat[0].geometry, features: [feat[0]] });
https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html#popup
https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Popup.html#open
Hey, sorry for the late feedback, i was absent for a week.
I've tried your solution and it seems to works but not really, in fact, my feat[0}.geometry seems to be null...
That's weird.
Hm...It seems there was a problem with my method to get features, and also it seems to be useless:
Solution:
var query = {
objectIds: [event.data.objectid],
outFields: ["*"],
returnGeometry: true
};
featureLayer.queryFeatures(query)
.then(function(response){
// close view popup if it is open
view.popup.close();
// Open the new popup
var feat = response.features[0];
view.popup.open({ location: feat.geometry, features: [feat] });
});
// console
Special thanks to @TommyBramble 🙂