[OpenLayers-Users] Problem dynamic loading a KML file (refresh)
Arnd Wippermann
arnd.wippermann at web.de
Sun Nov 11 08:31:05 PST 2012
some suggestions
you don't need to remove your kml_layer, you have only to refresh the layer
with the new url to the kmlfile.
you can delete OpenLayers.Strategy.BBOX, because a kmlfile is always loaded
in whole.
example how to refresh your layer
http://gis.ibbeck.de/ginfo/apps/OLExamples/OL212/protocol_refresh/protocol_r
efresh.asp
Regards,
Arnd
http://gis.ibbeck.de
_____
Von: openlayers-users-bounces at lists.osgeo.org
[mailto:openlayers-users-bounces at lists.osgeo.org] Im Auftrag von robertico
Gesendet: Samstag, 10. November 2012 06:52
An: openlayers-users at lists.osgeo.org
Betreff: Re: [OpenLayers-Users] Problem dynamic loading a KML file (refresh)
After a night slogging, i found my solution;
I'd like to share my solution and any suggetion is appreciated.
I've created a function to add the (KML) vector layer;
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);
}
Also added the function to the 'onClick' event of the button;
<input type="button" value="Show Markers" onClick="AddLayer()">
The hardest part was to find the right way to remove an existing layer.
Tried several examples but this one works well.
_____
View this message in context: Re:
<http://osgeo-org.1560.n6.nabble.com/Problem-dynamic-loading-a-KML-file-refr
esh-tp5015133p5015310.html> Problem dynamic loading a KML file (refresh)
Sent from the OpenLayers
<http://osgeo-org.1560.n6.nabble.com/OpenLayers-Users-f3910695.html> Users
mailing list archive at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/openlayers-users/attachments/20121111/04ed01ae/attachment.html>
More information about the Users
mailing list