How do I outsource a dynamic KML file using JavaScript in OpenLayers 2.10?
I want to refresh every 7 seconds.
Below are snippet of the given codes:
<script type='text/javascript'>
var map;
OpenLayers.IMAGE_RELOAD_ATTEMPTS = 3;
function init() {
map = new OpenLayers.Map({
allOverlays: true,
controls: [
new OpenLayers.Control.Navigation(),
new OpenLayers.Control.PanZoom(),
]
});
var osm_layer = new OpenLayers.Layer.OSM();
map.addLayer(osm_layer);
var MyKML = "http://www.xyz.com/tld/mypath/myfile.kml"
map.addLayer(new OpenLayers.Layer.GML("KML", MyKML,
{
format: OpenLayers.Format.KML,
formatOptions: {
extractStyles: true,
extractAttributes: true,
maxDepth: 1
}
}));
// Adding controls to map
map.addControl(new OpenLayers.Control.ScaleLine());
map.render('map_element');
map.setCenter(
new OpenLayers.LonLat(101.587008,3.021612).transform(
new OpenLayers.Projection("EPSG:4326"),
map.getProjectionObject()
), 17
);
}
</script>
The KML file could refresh automatically in Google Earth but not in OpenLayers. That is the real problem.
And one huge complication is that I cannot visualize the KML layer in OpenLayers. Either I use static or passive KML file is quite successful.