Da es schwierig genug für mich war, Informationen dazu zu finden, würde ich Folgendes hinzufügen:
1)
Erstellen Sie die KML-Ebene:
//Define your KML layer
var MyKmlLayer= new OpenLayers.Layer.Vector("This Is My KML Layer", {
//Set your projection and strategies//
projection: new OpenLayers.Projection("EPSG:4326"),
strategies: [new OpenLayers.Strategy.Fixed()],
//set the protocol with a url//
protocol: new OpenLayers.Protocol.HTTP({
//set the url to your variable//
url: mykmlurl,
//format this layer as KML//
format: new OpenLayers.Format.KML({
//maxDepth is how deep it will follow network links//
maxDepth: 1,
//extract styles from the KML Layer//
extractStyles: true,
//extract attributes from the KML Layer//
extractAttributes: true
})
})
});
2)
Legen Sie die URL für die KML-Ebene fest:
//note that I have host equal to location// //Math.Random will stop caching//
var mykmlurl= 'http://' + host + '/KML?key=' + Math.random();
3)
Legen Sie das Intervall fest, in dem Ihre Ebene aktualisiert werden soll:
//function called// //timer// //layer to refresh//
window.setInterval(UpdateKmlLayer, 5000, MyKmlLayer);
4)
Die Funktion zum Aktualisieren der Ebene:
function UpdateKmlLayer(layer) {
//setting loaded to false unloads the layer//
layer.loaded = false;
//setting visibility to true forces a reload of the layer//
layer.setVisibility(true);
//the refresh will force it to get the new KML data//
layer.refresh({ force: true, params: { 'key': Math.random()} });
//- <3 from Thqr -//
}
Ich hoffe, das macht es einigen anderen da draußen leichter. Viel Glück.