Line in Feature Layer is 'stuck' after viewing Popup?

3974
1
Jump to solution
04-01-2016 10:03 AM
ZoeZaloudek
Frequent Contributor

I have two feature layers in my map.  I have separate info templates defined and assigned to each.  One feature layer is of contiguous polygons (counties), so clicking on one to show the info window popup is not difficult for the user. However, the other feature layer is lines, which requires some precision to click and see the info window popup. So, I added some code to create a buffer extent around the clicked map point.  However, I think this workaround had an unintended consequence. 

In addition to viewing the lines, I also have a few options (radio buttons, etc) on the side, so the user can filter which lines are viewed.  This is accomplished by having a ‘refresh’ function that runs when one of the filter options are used.  It calculates a definition query and assigns it to the lines feature layer.

My problem occurs when the user clicks a line (showing the popup), and then sets one of the filter options.  The line with the current popup gets ‘stuck’, and will show even if it does not match the definition query.  Once the user clicks on a different line, or on the map, then the problem line disappears. Any ideas as to what causes the line to be ‘stuck’ on?  Is it a graphic thing?

Here are the parts of my code that I think are relevant.  First the buffer & map onclick functions:

// Buffer function
function pointToExtent (map, point, toleranceInPixel) {
     var pixelWidth = map.extent.getWidth() / map.width;
     var toleranceInMapCoords = toleranceInPixel * pixelWidth;
     return new Extent(point.x - toleranceInMapCoords,
                    point.y - toleranceInMapCoords,
                    point.x + toleranceInMapCoords,
                    point.y + toleranceInMapCoords,
                    map.spatialReference);
}
                    
// Set up feature layer popups (to include buffer for tracks)
var query = new Query();
map.on("click", function (event) {
     if (rdo1.checked == true)  {
          query.geometry = pointToExtent(map, event.mapPoint, 8);
          var deferred = flyrTracks.selectFeatures(query, FeatureLayer.SELECTION_NEW); }
     else if (rdo2.checked == true)  {
          query.geometry = pointToExtent(map, event.mapPoint, 1);
          var deferred = flyrCounties.selectFeatures(query, FeatureLayer.SELECTION_NEW); }
     map.infoWindow.setFeatures([deferred]);
     map.infoWindow.show(event.mapPoint);
});

And the refresh function that runs to filter the lines:

function refresh()  {
     map.infoWindow.hide();
     // SET UP defquery STRING HERE
     flyrTracks.setDefinitionExpression(defquery);
     flyrTracks.redraw();
}
0 Kudos
1 Solution

Accepted Solutions
ZoeZaloudek
Frequent Contributor

...and, after getting lunch with another GIS-savvy co-worker, I figured out a solution.

The selections on my feature layers needed to be cleared.  I added two lines to the beginning of my refresh function, so now it looks like this:

function refresh()  {  
    map.infoWindow.hide();
    flyrTracks.clearSelection();
    flyrCounties.clearSelection();
    // SET UP defquery STRING HERE  
    flyrTracks.setDefinitionExpression(defquery); 
    flyrTracks.redraw(); 
} 

View solution in original post

1 Reply
ZoeZaloudek
Frequent Contributor

...and, after getting lunch with another GIS-savvy co-worker, I figured out a solution.

The selections on my feature layers needed to be cleared.  I added two lines to the beginning of my refresh function, so now it looks like this:

function refresh()  {  
    map.infoWindow.hide();
    flyrTracks.clearSelection();
    flyrCounties.clearSelection();
    // SET UP defquery STRING HERE  
    flyrTracks.setDefinitionExpression(defquery); 
    flyrTracks.redraw(); 
}