<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=us-ascii" http-equiv=Content-Type>
<META name=GENERATOR content="MSHTML 8.00.6001.19328"></HEAD>
<BODY>
<DIV dir=ltr align=left><SPAN class=593302316-11112012><FONT color=#0000ff 
size=2 face=Arial>some suggestions</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=593302316-11112012><FONT color=#0000ff 
size=2 face=Arial></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=593302316-11112012><FONT color=#0000ff 
size=2 face=Arial>you don't need to remove your kml_layer, you have only to 
refresh the layer with the new url to the kmlfile.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=593302316-11112012><FONT color=#0000ff 
size=2 face=Arial></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=593302316-11112012><FONT face=Arial>you can 
delete OpenLayers.Strategy.BBOX, because a kmlfile is always loaded in 
whole.</FONT></SPAN></DIV><SPAN class=593302316-11112012>
<DIV dir=ltr align=left><BR><FONT face=Arial>example how to refresh your 
layer</FONT></DIV>
<DIV dir=ltr align=left><FONT color=#0000ff size=2 face=Arial><A 
href="http://gis.ibbeck.de/ginfo/apps/OLExamples/OL212/protocol_refresh/protocol_refresh.asp">http://gis.ibbeck.de/ginfo/apps/OLExamples/OL212/protocol_refresh/protocol_refresh.asp</A></FONT></DIV>
<DIV dir=ltr align=left><FONT color=#0000ff size=2 
face=Arial></FONT> </DIV>
<DIV dir=ltr align=left><FONT face=Arial><FONT color=#0000ff><FONT size=2>R<SPAN 
class=593302316-11112012>egards,</SPAN></FONT></FONT></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial><FONT color=#0000ff><FONT size=2><SPAN 
class=593302316-11112012>Arnd</SPAN></FONT></FONT></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial><FONT color=#0000ff><FONT size=2><SPAN 
class=593302316-11112012><A 
href="http://gis.ibbeck.de">http://gis.ibbeck.de</A></SPAN></FONT></FONT></FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=593302316-11112012><FONT 
face=Arial></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=593302316-11112012><FONT face=Arial><FONT 
color=#0000ff size=2></FONT> </DIV></FONT></SPAN>
<DIV dir=ltr align=left>
<HR tabIndex=-1>
</DIV>
<DIV dir=ltr align=left><FONT size=2 face=Tahoma><B>Von:</B> 
openlayers-users-bounces@lists.osgeo.org 
[mailto:openlayers-users-bounces@lists.osgeo.org] <B>Im Auftrag von 
</B>robertico<BR><B>Gesendet:</B> Samstag, 10. November 2012 06:52<BR><B>An:</B> 
openlayers-users@lists.osgeo.org<BR><B>Betreff:</B> Re: [OpenLayers-Users] 
Problem dynamic loading a KML file (refresh)<BR></FONT><BR></DIV>
<DIV></DIV>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></BODY></HTML>