import nl.idgis.giclient.util.SynchListener; import nl.idgis.giclient.gis.Feature; import flash.external.ExternalInterface; /** * @author copierrj */ class nl.idgis.giclient.api.PropertiesResponseHandler implements SynchListener{ private var requestCounter; private var scriptMethod:String; private var layerName:String; private var features:Array; function PropertiesResponseHandler(layerName:String, scriptMethod:String) { this.layerName = layerName; this.requestCounter = 0; this.scriptMethod = scriptMethod; } function doRequests(features:Array):Void { this.features = features; for(var i:Number = 0; i < features.length; i++) { var currentFeature:Feature = Feature(features[i]); if(!hasProperties(currentFeature)) { currentFeature.requestProperties(this); requestCounter++; } } if(requestCounter == 0) { handleResponse(); } } private function hasProperties(feature:Feature):Boolean { var columnValues:Object = feature.getColumnValues(); for(var s:String in columnValues) { return true; } return false; } function onSynch(target : Object, action : String) : Void { requestCounter--; if(requestCounter == 0) { handleResponse(); } } private function handleResponse():Void { var objs:Array = new Array(); for(var i:Number = 0; i < features.length; i++) { var currentFeature:Feature = Feature(features[i]); var columnValues:Object = currentFeature.getColumnValues(); var attributes:Object = new Object(); for(var s:String in columnValues) { var value:Object = columnValues[s]; if(value != null) { var name:String = s; var index:Number = -1; index = name.indexOf(":"); while(index != -1) { name = name.substr(index + 1); index = name.indexOf(":"); } attributes[name] = value; } } objs.push({id: currentFeature.getID(), attributes: attributes}); } ExternalInterface.call(scriptMethod, layerName, objs); } }