Solved! Go to Solution.
var sr:SpatialReference = new SpatialReference(102100); var myMulPoint:Multipoint = new Multipoint( [[ new MapPoint(1447100, 7477200, sr), new MapPoint(1447400, 7477600, sr), ]], sr); var myGraphicMulPoint:Graphic = new Graphic(); myGraphicMulPoint.geometry = myMulPoint; myGraphicMulPoint.symbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_TRIANGLE, 22, 0x009933); myGraphicsLayer.add(myGraphicMulPoint);
Shabbir,
You should give each one of your geometries a spatial reference always. This code works:var sr:SpatialReference = new SpatialReference(102100); var myMulPoint:Multipoint = new Multipoint( [[ new MapPoint(1447100, 7477200, sr), new MapPoint(1447400, 7477600, sr), ]], sr); var myGraphicMulPoint:Graphic = new Graphic(); myGraphicMulPoint.geometry = myMulPoint; myGraphicMulPoint.symbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_TRIANGLE, 22, 0x009933); myGraphicsLayer.add(myGraphicMulPoint);
Don't forget to click the Mark as answer check on this post and to click the top arrow (promote).
Follow these steps as shown in the below graphic:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:esri="http://www.esri.com/2008/ags"
xmlns:s="library://ns.adobe.com/flex/spark">
<fx:Script>
<![CDATA[
import com.esri.ags.Graphic;
import com.esri.ags.geometry.MapPoint;
import com.esri.ags.geometry.Multipoint;
import com.esri.ags.SpatialReference;
import com.esri.ags.symbols.SimpleMarkerSymbol;
private function init(evt:Event):void
{
var sr:SpatialReference = new SpatialReference(102100);
var myMulPoint:Multipoint = new Multipoint(
[[
new MapPoint(1447100, 7477200, sr),
new MapPoint(1447400, 7477600, sr),
]], sr);
var myGraphicMulPoint:Graphic = new Graphic();
myGraphicMulPoint.geometry = myMulPoint;
myGraphicMulPoint.symbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_TRIANGLE, 22, 0x009933);
myGraphicsLayer.add(myGraphicMulPoint);
}
]]>
</fx:Script>
<esri:Map id="myMap">
<esri:ArcGISTiledMapServiceLayer url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer" load="init(event)"/>
<esri:GraphicsLayer id="myGraphicsLayer" />
</esri:Map>
</s:Application>
Shabbir,
You have something else wrong in your code then as I tested this and it works fine. Here is the whole test app I did.<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:esri="http://www.esri.com/2008/ags" xmlns:s="library://ns.adobe.com/flex/spark"> <fx:Script> <![CDATA[ import com.esri.ags.Graphic; import com.esri.ags.geometry.MapPoint; import com.esri.ags.geometry.Multipoint; import com.esri.ags.SpatialReference; import com.esri.ags.symbols.SimpleMarkerSymbol; private function init(evt:Event):void { var sr:SpatialReference = new SpatialReference(102100); var myMulPoint:Multipoint = new Multipoint( [[ new MapPoint(1447100, 7477200, sr), new MapPoint(1447400, 7477600, sr), ]], sr); var myGraphicMulPoint:Graphic = new Graphic(); myGraphicMulPoint.geometry = myMulPoint; myGraphicMulPoint.symbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_TRIANGLE, 22, 0x009933); myGraphicsLayer.add(myGraphicMulPoint); } ]]> </fx:Script> <esri:Map id="myMap"> <esri:ArcGISTiledMapServiceLayer url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer" load="init(event)"/> <esri:GraphicsLayer id="myGraphicsLayer" /> </esri:Map> </s:Application>
I executed the test application ,even in this test application same error is throwing,
I am using the flexviewer 2.5
Shabbir,
Hmm... When you say
The test add I made is a Flex API stand alone application nothing to do with Flex Viewer and was built and tested using the Flex 2.5 API so I know for a fact that it works without error. I am really unsure what issue you are having.
When you say you are trying to use your code in Flexviewer 2.5, are you adding it to a widget or what? Maybe you should share all of the code that you are using in your viewer (i.e the widget or where ever you are attempting to add the code to).
var myMulPoint:Multipoint = new Multipoint( [[ new MapPoint(1447100, 7477200, sr), new MapPoint(1447400, 7477600, sr), ]], sr);
var myMulPoint:Multipoint = new Multipoint([ new MapPoint(1447100, 7477200, sr), new MapPoint(1447400, 7477600, sr)], sr);
Shabbir,
I am not sure why, but the code I posted wrapped the points array in another array for some reason and this caused the issue.
Bad code:var myMulPoint:Multipoint = new Multipoint( [[ new MapPoint(1447100, 7477200, sr), new MapPoint(1447400, 7477600, sr), ]], sr);
Working code:var myMulPoint:Multipoint = new Multipoint([ new MapPoint(1447100, 7477200, sr), new MapPoint(1447400, 7477600, sr)], sr);