[OpenLayers-Users] Problem dynamic loading a KML file (refresh)
Arnd Wippermann
arnd.wippermann at web.de
Sun Nov 11 12:46:31 PST 2012
you try to get an url for a kmlfile with input type="file" (lets you choose
a file in your filesystem and not an url), which delivers in Firefox only
the filename without the path. As far as you load a file from the same path
as your page, this will work on your local system.
In IE and Chrome a fakepath is added to the filename.
That' from Chrome
Not allowed to load local resource:
file:///C:/fakepath/Santiago_Calatrava.kml
and with IE it's the same.
Details zum Fehler auf der Webseite
Meldung: Ungültiges Argument.
Zeile: 747
Zeichen: 153
Code: 0
URI: <http://localhost/OpenLayers/OpenLayers-2.12/OpenLayers.js>
OpenLayers-2.12/OpenLayers.js
Add an alert(filename) to your function AddLayer() to see what will
returned.
Good luck
Arnd
_____
Von: openlayers-users-bounces at lists.osgeo.org
[mailto:openlayers-users-bounces at lists.osgeo.org] Im Auftrag von robertico
Gesendet: Sonntag, 11. November 2012 19:16
An: openlayers-users at lists.osgeo.org
Betreff: Re: [OpenLayers-Users] Problem dynamic loading a KML file (refresh)
I changed it this way;
<!DOCTYPE html>
<html>
<head>
<title>Loading a KML File</title>
<meta http-equiv="Content-Type" content="text/html;
charset=UTF-8">
<script type="text/javascript" src="OpenLayers.js"></script>
<style>
<!--
html, body
{
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
-->
</style>
<script type="text/javascript">
var filename = "";
var map;
var kml_layer;
function init()
{
var options = {
minResolution: "auto",
minExtent: new OpenLayers.Bounds(-1, -1, 1, 1),
maxResolution: "auto",
maxExtent: new OpenLayers.Bounds(-180, -90, 180,
90),
controls: [
new
OpenLayers.Control.LayerSwitcher({'ascending':false}),
new OpenLayers.Control.Navigation(),
new OpenLayers.Control.PanZoom(),
new OpenLayers.Control.KeyboardDefaults()
],
numZoomLevels: 19,
units: 'm',
projection: new
OpenLayers.Projection("EPSG:900913"),
displayProjection: new
OpenLayers.Projection("EPSG:4326")
};
map = new OpenLayers.Map("map", options);
var osm_layer = new OpenLayers.Layer.OSM();
map.addLayer(osm_layer);
kml_layer = new OpenLayers.Layer.Vector("KML", {
projection: map.displayProjection,
strategies: [new OpenLayers.Strategy.Fixed()],
protocol: new OpenLayers.Protocol.HTTP({
url: filename,
format: new OpenLayers.Format.KML({
extractStyles: true,
extractAttributes: true,
maxDepth: 10
})
})
});
map.addLayer(kml_layer);
map.zoomToMaxExtent();
}
function AddLayer()
{
// get KML file
filename = document.getElementById('theFile').value;
if(filename == "")
{
alert("Select KML file");
}
else
{
kml_layer.refresh({url: filename });
}
}
</script>
</head>
<body onload="init()">
<div id="top" style="width: 100%; height: 15pt; padding: 5px;">
<input type="file" id="theFile" size="100" />
<input type="button" value="Show Markers"
onClick="AddLayer()">
</div>
<div id="map" style="width: 100%; height: 100%;"></div>
</body>
</html>
Works excellent in Mozilla Firefox but again not in IE and Chrome.
Error message in IE:
Webpage error details
Message: Invalid argument.
Line: 747
Char: 153
Code: 0
URI: file:///D:/openlayers/OpenLayers.js
This part from OpenLayers.js
(a[1]||a[7])){b=parseInt(a[1],10)||0;var
c=parseInt(a[2],10)-1||0,d=parseInt(a[3],10)||1;b=new
Date(Date.UTC(b,c,d));if(c=a[7]){var
d=parseInt(a[4],10),e=parseInt(a[5],10),f=parseFloat(a[6]),g=f|0,f=Math.roun
d(1E3*(f-g));b.setUTCHours(d,e,g,f);"Z"!==c&&(c=parseInt(c,10),a=parseInt(a[
8],10)||0,b=new Date(b.getTime()+-1E3*(60*60*c+
char: 153 starts at;
e=parseInt(a[5...
What's going wrong ????
_____
View this message in context: Re:
<http://osgeo-org.1560.n6.nabble.com/Problem-dynamic-loading-a-KML-file-refr
esh-tp5015133p5015436.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/9fea32c9/attachment.html>
More information about the Users
mailing list