After a night slogging, i found my solution;<br>
I'd like to share my solution and any suggetion is appreciated.<br>
I've created a function to add the (KML) vector layer;<br>
<pre> function AddLayer()
{
// If layer (kml_layer) already exists, remove it before adding the new one
if (kml_layer)
{
map.removeLayer(kml_layer);
//kml_layer.destroyFeatures(); // not sure if this is necessary. Works well without it.
}
// Get file name (.kml file)
filename = document.getElementById('theFile').value;
kml_layer = new OpenLayers.Layer.Vector("KML", {
projection: map.displayProjection,
strategies: [new OpenLayers.Strategy.Fixed(),
new OpenLayers.Strategy.BBOX({resFactor: 1.1}),
//new OpenLayers.Strategy.Cluster()], // only usefull if you want to cluster your markers
protocol: new OpenLayers.Protocol.HTTP({
url: filename,
format: new OpenLayers.Format.KML({
extractStyles: true,
extractAttributes: true,
maxDepth: 10
})
})
});
map.addLayer(kml_layer);
}</pre><br>
Also added the function to the 'onClick' event of the button;<br>
<pre><input type="button" value="Show Markers" onClick="AddLayer()"></pre><br>
The hardest part was to find the right way to remove an existing layer. Tried several examples but this one works well.<br><br>
<br/><hr align="left" width="300" />
View this message in context: <a href="http://osgeo-org.1560.n6.nabble.com/Problem-dynamic-loading-a-KML-file-refresh-tp5015133p5015310.html">Re: Problem dynamic loading a KML file (refresh)</a><br/>
Sent from the <a href="http://osgeo-org.1560.n6.nabble.com/OpenLayers-Users-f3910695.html">OpenLayers Users mailing list archive</a> at Nabble.com.<br/>