Select to view content in your preferred language

FeatureLayer - "load"-event do not fire in some cases

929
3
03-24-2014 03:10 AM
ØyvindIdland
Deactivated User
I have a case where the "load" event is not being fired for a feature layer (v 3.7). This happens when the app is opened a new window or tab. When doing a full refresh, it triggers again. I do not get any errors-events on this.

Update: this happens in some instances of IE10, but it has happened in IE11 aswell.

Also, the docs on the "load"-event states the following:
Fires after layer properties for the layer are successfully populated. This event must be successful before the layer can be added to the map.

What does this mean, do I have to add the layer to the map inside the event handler for "load" ? If so, this is not what's being done in the examples (e.g. this).


Here is a stripped version of my code:

App.mainLayer = new FeatureLayer(mapConfig.featureServiceUrl + "/0", {
 id: mapConfig.featureLayerID,
 mode: FeatureLayer.MODE_ONDEMAND,
 outFields: ["*"],
 visible: true,

});
App.mainLayer.on("error", function (err) {
 console.error("Error loading layer: ", e.stack);
});

App.mainLayer.setDefinitionExpression(layerFilterExpression);

App.mainLayer.on("mouse-over", function () {
 App.map.setMapCursor("pointer");
});
App.mainLayer.on("mouse-out", function () {
 App.map.setMapCursor("default");
});
App.mainLayer.on("load", explLayerLoadedHandler);

function explLayerLoadedHandler(evt) {
 // sometimes not firing
 console.log("Layer loaded.");
 ...
}
0 Kudos
3 Replies
DeepikaJain
Occasional Contributor
Hey

On Map onload, you need to add this featurelayer to map. have you added this feature layer to map? the load event of featurelayer will be triggered once the layer is added to map.
0 Kudos
ØyvindIdland
Deactivated User
Hi,

yes, I do add it to the map. The layer is rendering too, including a DynamicMap and a few more FeatureLayers.

I just tested adding the layers in the map.on("load") event, but then the event is never fired anymore.

In the docs for map.onLoad:
Fires when the first or base layer has been successfully added to the map.


So, that means I have to add the layers first in order to have that event fired, which my test here confirmed.
0 Kudos
KenBuja
MVP Esteemed Contributor
Have you tried using the event map.on('layer-add-result') or map.on('layers-add-result') when you add the layer to your map?
0 Kudos