Hi,
I have a problem when using graphicsUtils.graphicsExtent with an Array that contains a reference to some Graphics of my FeatureLayer.
Here's the code that puts the reference to the graphics that I want in an array, creates an extent for them and then zooms the map with this extent:
groupGraphics: null,
/**
* Zoom the map for the active contacts
*
* @param {Object} parameters
*
* parameters:
* {String} layerId The name of the GraphicsLayer
* {String} attributeName
*/
zoomFeatureGroup: function (parameters) {
util.log('MapArcGIS::zoomFeatures');
var graphicsLayer = this.map.getLayer(parameters.layerId);
this.groupGraphics = [];
array.forEach(graphicsLayer.graphics, lang.hitch(this, function(graphic){
if (graphic.attributes[parameters.attributeName] !== this.RendererValue.DEFAULT){
this.groupGraphics.push(graphic);
}
}));
var extent = graphicsUtils.graphicsExtent(this.groupGraphics);
this.map.setExtent(extent, true);
}
This by itself works, but afterwards when trying to use something like graphic.getDojoShape().moveToBack() in another function, I noticed that all the graphics in the GraphicsLayer have null _shape property (not just those of my subgroup). This creates the following error in Chrome:
Uncaught TypeError: Cannot read property 'moveToBack' of null MapArcGIS.js:776
This only seems to happen if I do both things: 1) create a sub-array of Graphics and 2) use graphicsUtils.graphicsExtent on them. If I do only one or the other, _shape is fine.
I'm not sure if I'm doing something wrong. Any idea?
Edit: After some further debugging I think that _shape is null whenever the Graphic is not visible on the map. So if I zoom and some Graphics are not visible, if I try to iterate on all Graphics and try to call getDojoShape() on them, it will generate an error for those not visible.
I guess I can protect myself with something like this to prevent JavaScript errors and making the whole site unstable:
if ( graphic.getDojoShape() ){
graphic.getDojoShape().moveToBack()
}
Thanks,
Yohan