我是 openlayers 的新手,正在尝试在我的浏览器中显示 gml 层,其中包含硬盘驱动器中的所有内容。我已经尝试了以下代码,但我一生都无法让它工作。xml 文件可以从以下网址下载:ftp: //webftp.vancouver.ca/opendata/xml/weekendplayfieldstatus.xml。它与我的 html 文件位于同一目录中。提前感谢您的帮助。
担
<html>
<head>
<title>OpenLayers Example</title>
<script src="http://openlayers.org/api/OpenLayers.js"></script>
</head>
<body>
<div style="width:100%; height:100%" id="map"></div>
<script defer="defer" type="text/javascript">
var map = new OpenLayers.Map('map');
var wms = new OpenLayers.Layer.WMS( "OpenLayers WMS",
"http://vmap0.tiles.osgeo.org/wms/vmap0", {layers: 'basic'} );
var fromProjection = new OpenLayers.Projection("EPSG:4326"); // Transform from WGS 1984
var toProjection = new OpenLayers.Projection("EPSG:900913"); // to Spherical Mercator Projection
var layer = new OpenLayers.Layer.GML("GML", "weekendplayfieldstatus.xml");
var position = new OpenLayers.LonLat(-123.1000,49.2500);
var zoom = 11;
var markers = new OpenLayers.Layer.Markers( "Markers" );
map.addLayer(wms);
map.setCenter(position, zoom);
map.addLayer(markers);
markers.addMarker(new OpenLayers.Marker(position));
</script>
</body>
</html>