0

Possible Duplicate:
Problems adding KML layer in OpenLayers

I'm trying to add the following KML to my Openlayers project: http://www.marinetraffic.com/ais/ge_marinetraffic.kml

using this code:

function init() {
        map = new OpenLayers.Map('map');

        var wms = new OpenLayers.Layer.OSM();

            var sundials = new OpenLayers.Layer.Vector("sundials", {
            projection: map.displayProjection,
            strategies: [new OpenLayers.Strategy.Fixed()],
            protocol: new OpenLayers.Protocol.HTTP({
                url: "sundials.kml",
                format: new OpenLayers.Format.KML({
                    extractStyles: true,
                    extractAttributes: true
                })
            })
        });

        var marine = new OpenLayers.Layer.Vector("marine", {
            projection: map.displayProjection,
            strategies: [new OpenLayers.Strategy.Fixed()],
            protocol: new OpenLayers.Protocol.HTTP({
            url: "http://www.marinetraffic.com/ais/ge_marinetraffic.kml",
                format: new OpenLayers.Format.KML({
                    extractStyles: true,
                    extractAttributes: true

                })
            })
        });          

        map.addLayers([wms, sundials, marine]);
        map.addControl(new OpenLayers.Control.LayerSwitcher());
        map.zoomToMaxExtent();
    }

and I don't see the KML. In Chrome I get error :

XMLHttpRequest cannot load http://www.marinetraffic.com/ais/ge_marinetraffic.kml. Origin localhost:57551 is not allowed by Access-Control-Allow-Origin.

so I tried saving the KML locally , but still nothing showed (maybe because KML has urls inside it).

Is there a way to show it on the map ? (probably proxy?!) if so , Can someone please post example for the easiest/fastest way to do it .

thank you.

marked as duplicate by Ian Turton, R.K., whuber Nov 13 '12 at 16:42

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • you require a cross domain xml to accomplish solution stackoverflow.com/questions/3321690/… – Mapperz Nov 13 '12 at 14:23
  • if you are behind proxy see this trac.osgeo.org/openlayers/wiki/… – rkm Nov 13 '12 at 14:44
  • I'm not behind proxy , but I need to be able to get the kml content from different domain. Question is what is the kml contains more links inside to other domains ? is it possible to work? – Alophind Nov 13 '12 at 15:40
  • Mapperz - I don't have access to the kml server , its from a provider in the internet. I can't put files on his server. – Alophind Nov 13 '12 at 15:45

Browse other questions tagged or ask your own question.