Javascript 将geojson添加到openlayer3

Javascript 将geojson添加到openlayer3,javascript,openlayers,geojson,Javascript,Openlayers,Geojson,将geojson添加到平铺WMS地图时遇到问题。当我删除geojson时,函数“tiledWMS”起作用。在这里,我还添加了我的geojson文件: 下面我添加了我的脚本: 测试 项目4.defs('EPSG:2180',“+proj=tmerc+lat_0=0+lon_0=19+k=0.9993+x_0=500000+y_0=-5300000+ellps=GRS80+units=m+no_defs”); 函数init() { var p=ol.proj.get('EPSG:2180');

将geojson添加到平铺WMS地图时遇到问题。当我删除geojson时,函数“tiledWMS”起作用。在这里,我还添加了我的geojson文件: 下面我添加了我的脚本:


测试
项目4.defs('EPSG:2180',“+proj=tmerc+lat_0=0+lon_0=19+k=0.9993+x_0=500000+y_0=-5300000+ellps=GRS80+units=m+no_defs”);
函数init()
{
var p=ol.proj.get('EPSG:2180');
var mapTiles=新ol.Map({
目标:“地图”,
渲染器:“画布”,
图层:[
新ol.layer.Tile({
来源:新ol.source.TileWMS({
网址:'http://mapy.geoportal.gov.pl/wss/service/img/guest/ORTO/MapServer/WMSServer',
参数:{
“图层”:“光栅”,
‘CRS’:‘EPSG:2180’,
“版本”:“1.1.1”
}
}),
isBaseLayer:是的,
投影:p
}),
新ol.layer.Vector({
标题:“添加图层”,
来源:new ol.source.GeoJSON({
投影:‘EPSG:2180’,
url:'test.geojson'
})
})
],
视图:新ol.view({
中心:ol.proj.transform([19,52],'EPSG:4326','EPSG:2180'),
缩放:6,
投影:p
})
});
}

我是初学者,请告诉我一个建议。

您的数据不是GeoJSON,而是某种无效的GML。另外,我注意到您使用的是一个过时的OpenLayers版本。v3.14.0是最新版本。一旦您有了有效的GeoJSON,此提琴中的代码应该可以为您工作:。是的,我看到了TileWMS,但GeoJSON仍然不可用。您是否生成了新的有效GeoJSON文件?是的,在有效的投影中。以下是文件:。我只看到地图,没有看到geojson/Proj4.js不知道您正在使用的SRS字符串,因此在定义EPSG:2180:
Proj4.defs('urn:ogc:def:crs:EPSG::2180','EPSG:2180')后必须设置别名
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>test</title>
<script src="http://openlayers.org/en/v3.7.0/build/ol.js" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.3.12/proj4-src.js" type="text/javascript"></script>
<script>

proj4.defs('EPSG:2180', "+proj=tmerc +lat_0=0 +lon_0=19 +k=0.9993 +x_0=500000 +y_0=-5300000 +ellps=GRS80 +units=m +no_defs");

function init()
{
    var p = ol.proj.get('EPSG:2180');

    var mapTiles = new ol.Map({
        target: 'map',
        renderer: 'canvas',
        layers: [
            new ol.layer.Tile({
                source: new ol.source.TileWMS({
                    url: 'http://mapy.geoportal.gov.pl/wss/service/img/guest/ORTO/MapServer/WMSServer',
                    params: {
                        'LAYERS': 'Raster',
                        'CRS': 'EPSG:2180',
                        'VERSION': '1.1.1'
                    }
                }),
                isBaseLayer: true,
                projection: p
            }),
             new ol.layer.Vector({
      title: 'added Layer',
      source: new ol.source.GeoJSON({
         projection : 'EPSG:2180',
         url: 'test.geojson'
      })
  })
        ],




        view: new ol.View({
            center: ol.proj.transform([19, 52], 'EPSG:4326', 'EPSG:2180'),
            zoom: 6,
            projection: p
        })
    });
    }

</script>
</head>
<body onload="init()">
    <div id="map"></div>
</body>
</html>