AnsweredAssumed Answered

layer onclick event only triggered sometimes

Question asked by tkgsmph on Dec 7, 2014
Latest reply on Dec 8, 2014 by HHeijenga-esristaff



I have jSAPI 3.11 map page containing a layer that loads a point feature class which has a relationship defined with another feature class as the origin. My objective is to perform a relationship query when a point feature is clicked so that the fields from the origin feature class can be display in the content of an InfoTemplate. Here is a snippet of my code:


// init code here

map.on('load', function() {
    var attributes_0000;
    var relQuery_0000 = new RelationshipQuery();

    var regency = new FeatureLayer(
            outFields: ['*'],
    var infoTemplate_0000 = new InfoTemplate('Information', '');
    layer_0000 = new FeatureLayer(
            infoTemplate: infoTemplate_0000,
            id:'LAYER 0000'

    // layer_0000.on('click', function(evt) {
    dojo.connect(layer_0000, 'onClick', function(evt){
        console.log('layer clicked!');
        attributes_0000 = evt.graphic.attributes;
        relQuery_0000.outFields = ['*'];
        relQuery_0000.relationshipId = 0;
        relQuery_0000.objectIds = [attributes_0000.OBJECTID];
        layer_0000.queryRelatedFeatures(relQuery_0000, function(result){
            var result1 = result[attributes_0000.OBJECTID];
            var result_feature = result1.features[0];
            var relQueryProv0000 = new RelationshipQuery();
            relQueryProv0000.outFields = ['*'];
            relQueryProv0000.relationshipId = 11;
            relQueryProv0000.objectIds = [result_feature.attributes.OBJECTID];
            regency.queryRelatedFeatures(relQueryProv0000, function(resultprov){
                var resultprov1 = resultprov[result_feature.attributes.OBJECTID];
                var result_feature_prov = resultprov1.features[0];      
                var content = '<table><tr><td>ATTR1</td><td> : </td> <td> '+attributes_0000.ATTR1+'</td></tr><tr><td>ATTR2</td><td> : </td> <td> '+attributes_0000.ATTR2+'</td></tr><tr><td>ATTR3</td><td> : </td> <td> '+attributes_0000.ATTR3+'</td></tr><tr><td>ATTR4</td><td> : </td><td> '+result_feature.attributes.ATTR4+'</td></tr><td>ATTR5</td><td> : </td><td> '+result_feature_prov.attributes.ATTR5+'</td></tr><tr><td colspan="3" style="text-align: right;"><a class="showPopupDetails" href="javascript:void(0);" data-id="' + attributes_0000.OBJECTID + '" data-fclass="featureclass" data-layerindex="0000" data-ATTR4="'+result_feature.attributes.ATTR4+'" data-ATTR5="'+result_feature_prov.attributes.ATTR5+'" data-hasattachment = true >show details</a></td></tr></table>';
      , 200);
            }); // province relationshipquery
        }); // regency relationshipquery
    }); // layer onclick
}); // map onload


As you can see from the code above there are two relationship queries performed (point feature class => regency feature class => province feature class). I can get the result from both relationship queries just fine.


My problem is: when I click on a point feature, the associated onclick event does not trigger consistently after the map page is refreshed. Sometimes the relationship queries execute and the results are shown in the InfoWindow as intended. However more often only an empty InfoWindow is shown (I don't get the "Layer clicked!" on line 31 in the browser's javascript console). I can also confirm that on Chrome 40 if I load the map in a new incognito window the onclick event triggers consistently, even between page refresh!


I would greatly appreciate if anyone has any idea what's going on with my code.