将geojson添加到openlayer3

时间:2016-02-28 21:14:28

标签: javascript openlayers geojson

我在将geojson添加到我的tileWMS地图时遇到了问题。当我删除geojson函数" tilesWMS"作品。在这里,我还添加了我的geojson文件: http://www.speedyshare.com/vpapQ/test.geojson 下面我添加了我的脚本:

https://jsfiddle.net/w25b66rv/1/#&togetherjs=V6IbjQ1Jn0

<!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>

我是初学者,请提出建议。

0 个答案:

没有答案