// 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.
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);
var thePolygon:Polygon = new Polygon(null, new SpatialReference(4326)); thePolygon.addRing(JSONUtil.decode(data.polygon)); var wmPoly:Polygon = WebMercatorUtil.geographicToWebMercator(thePolygon);
Daniel,
Just writing code of the top of my head, I would try something like this (of course this is missing the imports):var thePolygon:Polygon = new Polygon(null, new SpatialReference(4326)); thePolygon.addRing(JSONUtil.decode(data.polygon)); var wmPoly:Polygon = WebMercatorUtil.geographicToWebMercator(thePolygon);
Daniel,
Because those coordinates that you are getting are not web mercator, they look like WGS1984 lat Lon coordinates.
(com.esri.ags.geometry::Polygon)#0 hasM = false hasZ = false rings = (Array)#1 [0] (Array)#2 [0] (Array)#3 [0] 40.6701 [1] 73.94001 [1] (Array)#4 [0] 40.6724 [1] 73.94012 [2] (Array)#5 [0] 40.6902 [1] 74.02011 spatialReference = (com.esri.ags::SpatialReference)#6 vcsWkid = NaN wkid = 4326 wkt = (null) type = "esriGeometryPolygon"
Daniel,
Just writing code of the top of my head, I would try something like this (of course this is missing the imports):var thePolygon:Polygon = new Polygon(null, new SpatialReference(4326)); thePolygon.addRing(JSONUtil.decode(data.polygon)); var wmPoly:Polygon = WebMercatorUtil.geographicToWebMercator(thePolygon);
var wmPoly:Polygon = WebMercatorUtil.geographicToWebMercator(thePolygon) as Polygon;
Daniel,
Well, not much to go one there... So you do have the import for WebMercatorUtil right?
var geom:Geometry = WebMercatorUtil.geographicToWebMercator(thePolygon);