GML和GeoJSON矢量图层无法在Firefox和Chrome中显示

时间:2012-11-11 15:37:57

标签: vector openlayers geojson gml

我有以下代码。它在IE中完美运行(加载了GML和GeoJSON矢量图层),但在Firefox和Chrome中没有注意到任何错误。请帮我解决这个问题。

以下是带有GML矢量图层的代码(我刚刚在Geoserver中使用了内置图层,因此您无需任何修改即可下载并测试它):

<!DOCTYPE html>
<html>
<head>
<title>Creating a simple map</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- Include OpenLayers library -->
<script type="text/javascript" src="http://openlayers.org/api/2.11/OpenLayers.js"></script>
<style>
    html, body {
        width: 100%;
        height: 100%;
        margin: 0;
        padding: 0;
    }
</style>
<!-- The magic comes here -->
<script type="text/javascript">
    var map;
    function init() {
        var bounds = new OpenLayers.Bounds(
            -124.73142200000001, 24.955967,
            -66.969849, 49.371735
        );
        var options = {
            controls: [],
            maxExtent: bounds,
            maxResolution: 0.22563114453125,
            projection: "EPSG:4326",
            units: 'degrees'
        };

        map = new OpenLayers.Map("ch3_wfs",options);

        var baseLayer = new OpenLayers.Layer.WMS("Basic","http://localhost:8080/geoserver/wms",
        {
            layers: "topp:states",
        });    
        map.addLayer(baseLayer);

        var statesLayer = new OpenLayers.Layer.Vector("States", {
            protocol: new OpenLayers.Protocol.HTTP({
                url: "http://localhost:8080/geoserver/topp/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=topp:states&maxFeatures=50",
                format: new OpenLayers.Format.GML()
            }),
            strategies: [new OpenLayers.Strategy.Fixed()],
        });

        map.addLayer(statesLayer);

        map.addControl(new OpenLayers.Control.LayerSwitcher());
        map.setCenter(new OpenLayers.LonLat(0,0), 2);
        map.zoomToMaxExtent();

    }

</script>
</head>
<body onload="init()">
    <div id="ch3_wfs" style="width: 100%; height: 100%;"></div><br>
</body>
</html>

以下是GeoJSON矢量图层的代码(我刚在Geoserver中使用了内置图层,因此您无需任何修改即可下载并测试它):

<!DOCTYPE html>
<html>
<head>
<title>Creating a simple map</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- Include OpenLayers library -->
<script type="text/javascript" src="http://openlayers.org/api/2.11/OpenLayers.js"></script>
<style>
    html, body {
        width: 100%;
        height: 100%;
        margin: 0;
        padding: 0;
    }
</style>
<!-- The magic comes here -->
<script type="text/javascript">
    var map;
    function init() {
        var bounds = new OpenLayers.Bounds(
            -124.73142200000001, 24.955967,
            -66.969849, 49.371735
        );
        var options = {
            controls: [],
            maxExtent: bounds,
            maxResolution: 0.22563114453125,
            projection: "EPSG:4326",
            units: 'degrees'
        };

        map = new OpenLayers.Map("ch3_wfs",options);

        var baseLayer = new OpenLayers.Layer.WMS("Basic","http://localhost:8080/geoserver/wms",
        {
            layers: "topp:states",

        });    
        map.addLayer(baseLayer);

        var statesLayer = new OpenLayers.Layer.Vector("States", {
            protocol: new OpenLayers.Protocol.HTTP({
                url: "http://localhost:8080/geoserver/topp/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=topp:states&maxFeatures=50&outputFormat=json",
                format: new OpenLayers.Format.GeoJSON()
            }),
            strategies: [new OpenLayers.Strategy.Fixed()],
        });
        map.addLayer(statesLayer);

        map.addControl(new OpenLayers.Control.LayerSwitcher());
        map.setCenter(new OpenLayers.LonLat(0,0), 2);
        map.zoomToMaxExtent();
    }

</script>
</head>
<body onload="init()">
    <div id="ch3_wfs" style="width: 100%; height: 100%;"></div><br>
</body>
</html>

0 个答案:

没有答案