// JavaScript var inputObject = { polygon: [ [40.6701, 73.94001], [40.6724, 73.94012], [40.6902, 74.02011] ], title: "My Selected Region" } document.getElementById("myMap").SetSelectedPolygonFunction(inputObject);
// Flex map code // In initialization function: // .... ExternalInterface.addCallback("SetSelectedPolygon", setSelectedPolygon); // ....etc private function setSelectedPolygon(data:Object = null):void { var thePolygon:Polygon = doSomethingOrOtherTo(data.polygon); // What do I do to data.polygon to make this function work? var myGraphic:Graphic = new Graphic(); myGraphic.geometry = thePolygon; myGraphicsLayer.add(myGraphic); }
Solved! Go to Solution.
Daniel,
Sure that is right. For debugging try this to see if you get past this line of code:var geom:Geometry = WebMercatorUtil.geographicToWebMercator(thePolygon);
var mpArr:Array = []; var pArr:Array = JSONUtil.decode(data.polygon); for (var p:int=0; p<pArr.length; p++){ var mp:MapPoint(pArr [0],pArr [1], new SpatialReference(4326)); mpArr.push(mp); } thePolygon.addRing(mpArr);
Daniel,
That sounds likely. I think you are going to have to parse the JSON further as the more I think about it the addRing is expecting an array of MapPoints not an array of numbers.
once again this is me free handing this code so there maybe mistakesvar mpArr:Array = []; var pArr:Array = JSONUtil.decode(data.polygon); for (var p:int=0; p<pArr.length; p++){ var mp:MapPoint(pArr [0],pArr [1], new SpatialReference(4326)); mpArr.push(mp); } thePolygon.addRing(mpArr);
Daniel,
The other thing that occurs to me is where are those coordinates shose to be in the world? For both the lat and Lon to be positive numbers you would be talking about some where in Asia if you are paasing Lat then Lon?..