0 Replies Latest reply on Jun 25, 2011 4:59 AM by kanjiri

    Problem with polyline object

    kanjiri

      I have written a code that calles >KML file from server and upload that file on google map.The problem with my code is its not taking the Polyline object. Can anyone help me. here is a code:

      <mx:Script>
          <![CDATA[

              import com.google.maps.LatLng;
              import com.google.maps.LatLngBounds;
              import com.google.maps.Map;
              import com.google.maps.MapEvent;
              import com.google.maps.MapMouseEvent;
              import com.google.maps.MapType;
              import com.google.maps.controls.MapTypeControl;
              import com.google.maps.controls.ZoomControl;
              import com.google.maps.overlays.GroundOverlay;
              import com.google.maps.overlays.Marker;
              import com.google.maps.overlays.MarkerOptions;
              import com.google.maps.overlays.Polyline;
              import com.google.maps.overlays.PolylineOptions;
              import com.google.maps.styles.FillStyle;
              import com.google.maps.styles.StrokeStyle;

              import flash.net.URLLoader;
              import flash.net.URLRequest;
              import flash.utils.ByteArray;

              import mx.collections.ArrayCollection;
              import mx.controls.Alert;
              import mx.controls.TextArea;
              import mx.rpc.events.FaultEvent;
              import mx.rpc.events.ResultEvent;
              import mx.rpc.xml.SimpleXMLDecoder;
              import mx.utils.ObjectUtil;
              import mx.utils.XMLUtil;

              private var loader:URLLoader;
              private var urlRequest:URLRequest;


              private function onMapReady(event:Event):void {

                  map.setCenter(new LatLng(36.07954952145647,-112.2550785337791), 12, MapType.NORMAL_MAP_TYPE);
                  map.addControl(new ZoomControl());
                  map.addControl(new MapTypeControl());

                  loader = new URLLoader();
                  urlRequest = new URLRequest();

                  urlRequest.url = ".kml file on server";
                  loader.load(urlRequest);

                  var bytes:ByteArray = loader.data as ByteArray;

                  htp.send();            
                  //Alert.show("Show data: " + bytes.length);
              }

              private function myresult(event:ResultEvent):void
              {
                  var retxml:XML = XML(event.result);            
                  var retDoc:XMLDocument = new XMLDocument(retxml);
                  var decoder:SimpleXMLDecoder = new SimpleXMLDecoder();
                  var resultObj:Object = decoder.decodeXML(retDoc);
                  var resltTag:String = resultObj.kml.Document.Placemark.LineString.coordinates;

                  //Alert.show("Hi" + resltTag);

                  var Strsource:Array = new Array();             
                  Strsource = resltTag.split(" ");

                  //Alert.show("Hi" + Strsource[0]);

                  var subsource:String = "";
                  var strSubArray:Array = new Array();
                  var finalarray:Array = new Array();

                  var i:int;
                  for (i=0; i
      <Strsource.length; i++)
                  {
                     
      subsource = null;
                     
      strSubArray = null;                
                     
      subsource = Strsource[i];
                     
      strSubArray = subsource.split(",");

                     
      if (strSubArray.length == 3)
                      {
                         
      //Alert.show("lat" + strSubArray[0] + " lon: " + strSubArray[1]);
                         
      finalarray.push(new LatLng(strSubArray[0],strSubArray[1]));
                         
      //Alert.show("Final" + finalarray );
                      }                  
                  }
                 
      //-------------
                 
      //var polyline:Polyline = new Polyline(finalarray, new PolylineOptions({ strokeStyle: new StrokeStyle({
                     
      //color: 0xFF0000,
                     
      //thickness: 4,
                     
      //alpha: 0.7})
                 
      //}));

                 
      //map.addOverlay(polyline);

                 
      //--------------------
                 
      Alert.show("Final" + finalarray);      

                 
      var Polyopt:PolylineOptions = new PolylineOptions ({strokeStyle: new StrokeStyle({color: 0x987654}),
                     
      fillStyle: new FillStyle({color: 0x223344, alpha: 0.8}),
                     
      radius: 12, hasShadow: true})


                 
      var PolyA:Polyline = new Polyline(finalarray,Polyopt);
                 
      Alert.show("Hello" + PolyA);
                 
      map.addOverlay(PolyA); 
              }

          ]]
      >

      </mx:Script>

      <mx:HTTPService id = "htp"
                     
      resultFormat="e4x"
                     
      url=".kml file" 
                     
      result="myresult(event)" />

           

      </mx:Application>