configuration - Host and load KML File in Flex project (IGN) -
i'm looking @ tutorial display placemarks using kml file on flex application. i'm using ign api (openscales) in flex project.
the example works (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()}"/>
but when i'm hosting same kml file on server :
<os:kml url="http://www.cycom.org/velib.kml" proxy="http://openscales.org/proxy.php?url=" numzoomlevels="20" style="{style.getdefaultcirclestyle()}"/>
placemarks don't show on map. tried host kml file on different hosts doesn't change. have clue ?
thank you.
you need add crossdomain.xml server side (in root folder) allow application access kml file. example, if want allow access server ips , domain names use simple wild card below in crossdomain.xml file:
<?xml version="1.0"?> <cross-domain-policy> <allow-access-from domain="*" /> </cross-domain-policy>
for more information using crossdomain file see: transfering data accross domains using crossdomain.xml
if don't have access server or if solution doesn't work you, have modify kml.as class in openscales (found in org.openscales.core.layer package).
change line 19
private var _request: xmlrequest = null;
to
private var _request :urlloader = null;
here entire modified kml class:
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 urlloader; // avoid errors if server 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 ) 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 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; } }
}
Comments
Post a Comment