Select to view content in your preferred language

Creating  Multipoint and adding graphic through ActionScript

3480
9
Jump to solution
10-20-2012 10:27 PM
shabbirsiddiqui2
Deactivated User
Hi,

I am trying to create MultiPoint through ActionScript and want to add graphic on the map, but it throwing error,

TypeError: Error #1034: Type Coercion failed: cannot convert []@1022e3a1 to com.esri.ags.geometry.MapPoint.
at com.esri.ags.symbols::SimpleMarkerSymbol/draw()
at com.esri.ags::Graphic/drawWithSymbol()
at com.esri.ags::Graphic/commitProperties()
at mx.core::UIComponent/validateProperties()
at mx.managers::LayoutManager/validateProperties()
at mx.managers::LayoutManager/doPhasedInstantiation()
at mx.managers::LayoutManager/doPhasedInstantiationCallback()


can any one please suggest me what is the problem in this code to add graphic on the layer .

Here is my Code.

var myMulPoint:Multipoint = new Multipoint(
  [[
    new MapPoint(1447100, 7477200),
    new MapPoint(1447100, 7477200),
  ]],  new SpatialReference(102100));
               
var myGraphicMulPoint:Graphic = new Graphic();
myGraphicMulPoint.geometry = myMulPoint;
myGraphicMulPoint.symbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_TRIANGLE, 22, 0x009933);
myGraphicsLayer.add(myGraphicMulPoint);
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus
Shabbir,

   Glad you got it working. 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:

View solution in original post

0 Kudos
9 Replies
RobertScheitlin__GISP
MVP Emeritus
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:

0 Kudos
shabbirsiddiqui2
Deactivated User
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:




Dear Robert ,

After giving each geometries a spatial reference as you said,
same error is throwing as it was before, there is no any change in the error.

Regard,

Shabbir Ahmad Siddiqui
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
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>
0 Kudos
shabbirsiddiqui2
Deactivated User
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>


Dear Robert,

  I exicuited the test application ,even in this test application same error is throwing,
I am using the flexviewer 2.5

What may be the issue, although through MXML i can create the MultiPoint without error .

Regards,
Shabbir Ahmad Siddiqui
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Shabbir,

   Hmm... When you say
I executed the test application ,even in this test application same error is throwing,
I am using the flexviewer 2.5


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).
0 Kudos
shabbirsiddiqui2
Deactivated User
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).


Dear Robert,

I am using the the stand alone application, which i have attached , Please check what is the issue with it .

Regards,

Shabbir Ahmad Siddiqui
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
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);
0 Kudos
shabbirsiddiqui2
Deactivated User
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);


Dear Robert,

  Thanks Robert, its work now.


Regards,
Shabbir Ahmad Siddiqui
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Shabbir,

   Glad you got it working. 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:

0 Kudos