dojo.connect(featLayer, "onClick", function (evt) { map.infoWindow.setFeatures([evt.graphic]); map.infoWindow.show(evt.mapPoint); });
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.
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); }
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)
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.
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
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!
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.
map.removeLayer(featureLayer); featureLayer.setDefinitionExpression(qstring); map.addLayer(featureLayer);
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);