1

I've been able to successfully load a KML file and overlay the data on a map. However if I move the files to a new server (and update all references to the new server) none of my kml file data gets displayed. I've got it to work in one location but when I move it no kml data. I've checked references to images, and file location.

I'm also using Layerswitcher https://github.com/walkermatt/ol3-layerswitcher

After checking and double checking references, I still got nothing.

My layerswitcher script:

var mapMinZoom = 6;
var mapMaxZoom = 21;

var mapBounds = [ -76.644773, 42.424805, -76.357081, 42.631565 ];
var centerLat = (mapBounds[1] + mapBounds[3]) / 2;
var centerLng = (mapBounds[0] + mapBounds[2]) / 2;

var xml_data = 'http://www.myserver.com/data/assets/rep_short.kml';
(function() {

    var map = new ol.Map({
        target : 'map',
        layers : [ new ol.layer.Group({
            'title' : 'Base maps',
            layers : [ new ol.layer.Tile({
                title : 'Base Map',
                type : 'base',
                visible : true,
                source : new ol.source.OSM()
            }) ]
        }), new ol.layer.Group({
            title : 'Overlays',
            layers : [ new ol.layer.Vector({
                title : 'Properties',
                source : new ol.source.KML({
                    projection : 'EPSG:3857',
                    url : xml_data
                })
            }) ]
        }) ],
        view : new ol.View({
            projection : 'EPSG:3857',
            center : ol.proj.transform([ centerLng, centerLat ], 'EPSG:4326',
                    'EPSG:3857'),
            zoom : 12
        })
    });

    var layerSwitcher = new ol.control.LayerSwitcher({
        tipLabel : 'Légende' // Optional label for button
    });
    map.addControl(layerSwitcher);

    var popup = new ol.Overlay.Popup();
    //map.addOverlay(popup);

    map.on('singleclick', function(evt) {
        var prettyCoord = ol.coordinate.toStringHDMS(ol.proj.transform(
                evt.coordinate, 'EPSG:3857', 'EPSG:4326'), 2);
        popup.show(evt.coordinate, '<div><h2>Coordinates</h2><p>' + prettyCoord
                + '</p></div>');
    });

})();
1

I'm using a content management system that generates a system url

Since my reference to the kml file was different than: var xml_data = 'http://www.myserver.com/data/assets/rep_short.kml';

Openlayers seemed to have a problem with the different urls as a cross domain conflict? Not sure.

If I reference the kml in Openlayers with a url like: http://www.myserver.com/data/index.php/mycontroller/xml_data

Openlayers plots the kml data.

  • Probably a CORS issue, the problem is not Openlayers. Verify that the request has the correct CORS headers. – oterral Jun 10 '15 at 7:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.