GML - openlayers

时间:2013-09-15 18:08:48

标签: xml openlayers gml

我是openlayers的新手,我正试图在浏览器中显示gml图层,其中包含硬盘驱动器中的所有内容。我已经尝试了以下代码,但在我的生活中无法让它工作。可以从ftp://webftp.vancouver.ca/opendata/xml/weekendplayfieldstatus.xml下载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>

1 个答案:

答案 0 :(得分:0)

我相信您只是错过了将GML图层添加到地图的调用。

var layerGML = new OpenLayers.Layer.GML("GML", "weekendplayfieldstatus.xml");    
map.addLayer(layerGML);