Multiple Feature in the "Info" Popup

9823
9
03-27-2012 11:18 PM
demdeberanz
New Contributor II
Hi everybody,
   I'm facing an issue with the Popup window. When I click on a layer with multiple overlapped features I'm not able to display in the same popup window the information related to these features (allowing the user to slide the information for the different overlapped features with arrows button like in the following example http://help.arcgis.com/en/webapi/javascript/arcgis/demos/fl/fl_popup.html). I'm using the following code to do this:

dojo.connect(featLayer, "onClick", function (evt) {
                        map.infoWindow.setFeatures([evt.graphic]);
                        map.infoWindow.show(evt.mapPoint);
});


It is able to find all the overlapped features but not to set the correct visualization of their information in the popup.

How can I sort out this issue?

Thank you everybody.
0 Kudos
9 Replies
demdeberanz
New Contributor II
Hi everybody,
   I'm facing an issue with the Popup window. When I click on a layer with multiple overlapped features I'm not able to display in the same popup window the information related to these features (allowing the user to slide the information for the different overlapped features with arrows button like in the following example http://help.arcgis.com/en/webapi/javascript/arcgis/demos/fl/fl_popup.html). I'm using the following code to do this:

dojo.connect(featLayer, "onClick", function (evt) {
                        map.infoWindow.setFeatures([evt.graphic]);
                        map.infoWindow.show(evt.mapPoint);
});


It is able to find all the overlapped features but not to set the correct visualization of their information in the popup.

How can I sort out this issue?

Thank you everybody.


A quick clarification the multiple popUp works properly in another feature layer...in the one where it doesn't work I've sat a definitionExpression to show only some features...can this be the source of the problem?
Furthermore I discovered that the evt.graphic contains only one feature although there are two overlapping features. Why?
0 Kudos
ChadWilcomb
New Contributor III
The default behavior only returns the graphic "on top" I believe.

Try something like this:

dojo.connect(map, "onClick", function (evt) {
    var query = new esri.tasks.Query();
    query.geometry = pointToExtent(map, evt.mapPoint, 10); //buffers click point by number of pixels(10)

    var select = featureLayer.selectFeatures(query, esri.layers.FeatureLayer.SELECTION_NEW);
    select.then(function(features) {
            console.log("select features result: ", features);
            map.infoWindow.setFeatures(features);
            map.infoWindow.show(e.mapPoint);
          }, function(err) {
            console.log("select features error: ", err);
    });
});

//this is just a function that buffers the click point by number of pixels and returns an Extent.
function pointToExtent(map, point, toleranceInPixel) {
    var pixelWidth = map.extent.getWidth() / map.width;
    var toleraceInMapCoords = toleranceInPixel * pixelWidth;
    return new esri.geometry.Extent(point.x - toleraceInMapCoords,
                    point.y - toleraceInMapCoords,
                    point.x + toleraceInMapCoords,
                    point.y + toleraceInMapCoords,
                    map.spatialReference);
}


Hat tip to Derek Swingley and his help here (http://gis.stackexchange.com/q/22025/5282)
0 Kudos
demdeberanz
New Contributor II
I've figured out what the problem is! when I change the definition expression in my feature layer,
the old features remain on the layer for a while (until I click on another "new" feature), so if I've got overlappend features and I click on a "new" one the function find two feature at the same point (the old one and the new). I don't get this behavior if I first click on a "new" not-overlapped feature and then I click on the "new overlapped"  feature.
I hope I was clear.
What do you think about?

Thank you very much.

The default behavior only returns the graphic "on top" I believe.

Try something like this:

dojo.connect(map, "onClick", function (evt) {
    var query = new esri.tasks.Query();
    query.geometry = pointToExtent(map, evt.mapPoint, 10); //buffers click point by number of pixels(10)

    var select = featureLayer.selectFeatures(query, esri.layers.FeatureLayer.SELECTION_NEW);
    select.then(function(features) {
            console.log("select features result: ", features);
            map.infoWindow.setFeatures(features);
            map.infoWindow.show(e.mapPoint);
          }, function(err) {
            console.log("select features error: ", err);
    });
});

//this is just a function that buffers the click point by number of pixels and returns an Extent.
function pointToExtent(map, point, toleranceInPixel) {
    var pixelWidth = map.extent.getWidth() / map.width;
    var toleraceInMapCoords = toleranceInPixel * pixelWidth;
    return new esri.geometry.Extent(point.x - toleraceInMapCoords,
                    point.y - toleraceInMapCoords,
                    point.x + toleraceInMapCoords,
                    point.y + toleraceInMapCoords,
                    map.spatialReference);
}


Hat tip to Derek Swingley and his help here (http://gis.stackexchange.com/q/22025/5282)
0 Kudos
ChadWilcomb
New Contributor III
Hard to tell why that would be happening, but maybe you just need to do something like this when setting your definition expression?

map.removeLayer(featureLayer);
featureLayer.setDefinitionExpression(qstring);
map.addLayer(featureLayer);


I've figured out what the problem is! when I change the definition expression in my feature layer,
the old features remain on the layer for a while (until I click on another "new" feature), so if I've got overlappend features and I click on a "new" one the function find two feature at the same point (the old one and the new). I don't get this behavior if I first click on a "new" not-overlapped feature and then I click on the "new overlapped"  feature.
I hope I was clear.
What do you think about?

Thank you very much.
0 Kudos
demdeberanz
New Contributor II
Hard to tell why that would be happening, but maybe you just need to do something like this when setting your definition expression?

map.removeLayer(featureLayer);
featureLayer.setDefinitionExpression(qstring);
map.addLayer(featureLayer);


cwilcomb, I tested your solution but it doesn't work. However the first solution you suggested should work, but not, and the behavior of the application it's very strange...I think about two chances:
-I'm doing something wrong in the way I use the DefinitionExpression,
-It is a bug in the javascript API.

So, please, someone of the ESRI Support Provide me Help!I'll be glad to you!

And a special thanks to cwilcomb xD
0 Kudos
ChadWilcomb
New Contributor III
cwilcomb, I tested your solution but it doesn't work. However the first solution you suggested should work, but not, and the behavior of the application it's very strange...I think about two chances:
-I'm doing something wrong in the way I use the DefinitionExpression,
-It is a bug in the javascript API.

So, please, someone of the ESRI Support Provide me Help!I'll be glad to you!

And a special thanks to cwilcomb xD


I have all of the code that I posted working in my application so it's not a bug in the API. You should probably post a reproduce-able code sample to get more/better responses. I just jumped in because I was working on something very similar this week. You'll get it worked out eventually!
0 Kudos
demdeberanz
New Contributor II
I have all of the code that I posted working in my application so it's not a bug in the API. You should probably post a reproduce-able code sample to get more/better responses. I just jumped in because I was working on something very similar this week. You'll get it worked out eventually!


The code you posted (the first) works very well, the issue I get is the one that comes out only when I've got overlapped features and I change the definitionExpression.

I've figured out what the problem is! when I change the definition expression in my feature layer,
the old features remain on the layer for a while (until I click on another "new" feature), so if I've got overlappend features and I click on a "new" one the function find two feature at the same point (the old one and the new). I don't get this behavior if I first click on a "new" not-overlapped feature and then I click on the "new overlapped" feature.
I hope I was clear.
What do you think about?

Thank you very much.
0 Kudos
demdeberanz
New Contributor II
Cwclimb, I tested the following code, the result is that when the layer has been readded (with the definitionExpression set) are shown all the feature of the layer...In your application is it working correctly?(the definition expression is honored)

map.removeLayer(featureLayer);
featureLayer.setDefinitionExpression(qstring);
map.addLayer(featureLayer);
0 Kudos
ChadWilcomb
New Contributor III
Cwclimb, I tested the following code, the result is that when the layer has been readded (with the definitionExpression set) are shown all the feature of the layer...In your application is it working correctly?(the definition expression is honored)

map.removeLayer(featureLayer);
featureLayer.setDefinitionExpression(qstring);
map.addLayer(featureLayer);


Yes, this is working as expected in my applications, where qstring represents a valid WHERE statement, like "FIELD_NAME='Value'".
0 Kudos