时间:2010-07-23 19:25:51

标签: flex configuration hosting kml

1 个答案:

答案 0 :(得分:1)

您需要将crossdomain.xml添加到服务器端(在根文件夹中)以允许应用程序访问您的KML文件。例如,如果您想允许您的服务器访问所有IP和域名,只需在crossdomain.xml文件中使用如下的简单通配符:

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

有关使用crossdomain文件的详细信息,请参阅:Transfering Data Accross Domains Using crossdomain.xml

如果您无权访问服务器或此解决方案不适合您,则必须在openscales中修改KML.as类(在org.openscales.core.layer包中找到)。

更改第19行

private var _request: XMLRequest = null;

private var _request :URLLoader = null;

以下是整个修改过的KML类:

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;
    }

}

}