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>');
});
})();