我有一个名为mygeojson.json的GeoJSON文件,我想将其添加为openstreetmap图层顶部的OpenLayers 3中的图层。到目前为止,我可以显示openstreetmap世界,包括缩放等。但是由于某种原因,我无法在其上获取mygeojson.json。
geojson包含许多多边形,如下所示:
{
"type": "FeatureCollection",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
"features": [
{ "type": "Feature", "properties": { "DN": 2 }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 13.559093915055664, 52.545214330050563 ], [ 13.559633429050496, 52.545205649772548 ], [ 13.559633415380715, 52.545214636296755 ], [ 13.559093915055664, 52.545214330050563 ] ] ] } }
]
}
我的main.html:
<!doctype html>
<html lang="en">
<head>
<link rel='stylesheet' href='http://ol3js.org/en/master/css/ol.css'>
<style>
#map {
height: 100%;
width: 100%;
}
</style>
<title>OpenLayers 3 example</title>
<script src="ol3/ol.js" type="text/javascript"></script>
</head>
<body>
<h1>My Map</h1>
<div id="map"></div>
<script type="text/javascript">
var map = new ol.Map({
target: 'map',
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
}),
new ol.layer.Vector({
title: 'added Layer',
source: new ol.source.GeoJSON({
projection : 'EPSG:4326',
url: 'mygeojson.json'
})
})
],
view: new ol.View({
center:[52.5243700 , 13.4105300],
zoom:2
})
});
</script>
</body>
</html>
我也尝试删除投影信息,但没有用。