2010-07-23 7 views
2

플렉스 애플리케이션에서 KML 파일을 사용하여 장소 표시를 표시하는 방법을 살펴 보았습니다. 플렉스 프로젝트에서 IGN API (openscales)를 사용하고 있습니다. .Flex 프로젝트의 호스트 및 KML 파일 (IGN)

예는 완벽하게 (http://openscales.org/userguide/examples/srcview/source/KMLExample.mxml

<os:KML url="http://www.parisavelo.net/velib.kml" 
       proxy="http://openscales.org/proxy.php?url=" 
       numZoomLevels="20" 
       style="{Style.getDefaultCircleStyle()}"/> 

작동하지만 그런 내 서버에서 동일한 KML 파일을 호스팅하고있을 때 :

<os:KML url="http://www.cycom.org/velib.kml" 
       proxy="http://openscales.org/proxy.php?url=" 
       numZoomLevels="20" 
       style="{Style.getDefaultCircleStyle()}"/> 

는 위치 표시지도에 표시되지 않습니다 . 다른 호스트에서 kml 파일을 호스트하려고했지만 변경되지 않습니다.

감사합니다.

답변

1

애플리케이션이 KML 파일에 액세스 할 수 있도록 서버 측 (루트 폴더에 있음)에 crossdomain.xml을 추가해야합니다. 참조 교차 도메인 파일을 사용하는 방법에 대한 자세한 내용은

<?xml version="1.0"?> 
<cross-domain-policy> 
    <allow-access-from domain="*" /> 
</cross-domain-policy> 

: 모든 IP를 도메인 이름으로 서버에 대한 액세스를 허용 할 경우 예를 들어, 당신의 crossdomain.xml 파일에 다음과 같이 간단한 와일드 카드를 사용 Transfering Data Accross Domains Using crossdomain.xml

서버에 액세스 할 수 없거나이 솔루션이 작동하지 않는 경우 openscales (org.openscales.core.layer 패키지에 있음)에서 KML.as 클래스를 수정해야합니다.

package org.openscales.core.layer 

{ 
import flash.events.Event; 
import flash.events.IOErrorEvent; 
import flash.net.URLLoader; 
import flash.net.URLRequest; 
import flash.net.URLRequestMethod; 

import org.openscales.core.Trace; 
import org.openscales.core.feature.Feature; 
import org.openscales.core.format.KMLFormat; 
import org.openscales.core.request.XMLRequest; 
import org.openscales.geometry.basetypes.Bounds; 


public class KML extends FeatureLayer 
{ 
    private var _url :String = ""; 
    private var _request :URLLoader = null; 
    private var _kmlFormat :KMLFormat = null; 
    private var _xml :XML = null; 

    public function KML (name :String, 
     url :String, 
     bounds :Bounds = null) 
    { 
     this._url = url; 
     this.maxExtent = bounds; 

     super(name); 
     this._kmlFormat = new KMLFormat(); 
    } 

    override public function destroy() :void 
    { 
     if (this._request) 
      this._request = null; 

     this.loading = false; 
     super.destroy(); 
    } 

    override public function redraw (fullRedraw :Boolean = true) :void 
    { 
     if (!displayed) 
     { 
      this.clear(); 
      return; 
     } 

     if (!this._request) 
     { 
      this.loading = true; 
      this._request = new URLLoader(); 
      this._request.addEventListener(Event.COMPLETE, onSuccess); 
      this._request.addEventListener(IOErrorEvent.IO_ERROR, onFailure); 
      this._request.load(new URLRequest(url)); 
     } 
     else 
     { 
      this.clear(); 
      this.draw(); 
     } 
    } 

    public function onSuccess (event :Event) :void 
    { 
     this.loading = false; 
     var loader :URLLoader = event.target as URLLoader; 

     // To avoid errors if the server is dead 
     try 
     { 
      this._xml = new XML(loader.data); 

      if (this.map.baseLayer.projection != null && this.projection != null && this.projection.srsCode != this.map.baseLayer.projection.srsCode) 
      { 
       this._kmlFormat.externalProj = this.projection; 
       this._kmlFormat.internalProj = this.map.baseLayer.projection; 
      } 
      this._kmlFormat.proxy = this.proxy; 
      var features :Vector.<Feature> = this._kmlFormat.read(this._xml) as Vector.<Feature>; 
      this.addFeatures(features); 

      this.clear(); 
      this.draw(); 
     } 
     catch (error :Error) 
     { 
      Trace.error(error.message); 
     } 
    } 

    protected function onFailure (event :Event) :void 
    { 
     this.loading = false; 
     Trace.error("Error when loading kml " + this._url); 
    } 

    public function get url() :String 
    { 
     return this._url; 
    } 

    public function set url (value :String) :void 
    { 
     this._url = value; 
    } 

    override public function getURL (bounds :Bounds) :String 
    { 
     return this._url; 
    } 

} 

}

:

변경 선 (19)

private var _request: XMLRequest = null; 

여기

private var _request :URLLoader = null; 

전체 수정 KML 클래스입니다

관련 문제