外部文件与内部对象的GeoJSON投影
GeoJSON projection of external file vs. internal object
我有这个外部GeoJSON文件:
{"type": "FeatureCollection", "features": [ {"type":"Feature", "id":382, "properties":{"name":"Foo","description":"Bar"}, "geometry":{"type":"MultiPolygon","coordinates":[[[[100.51731551305,14.018177133438],[100.517959243205,14.0188303173272],[100.517133122834,14.0194652831494],[100.516628867536,14.0198920624699],[100.51755154744,14.0206831634993],[100.521199351693,14.0200794287498],[100.518087989239,14.0167692686143],[100.517798310678,14.0169176022848],[100.51731551305,14.018177133438]]]]}} ] }
如果我像这样使用它,它的位置是正确的:
var vectorSource = new ol.source.Vector({
url: 'data.geojson',
format: new ol.format.GeoJSON(),
projection : 'EPSG:4326',
});
var vectorLayer = new ol.layer.Vector({
source: vectorSource
});
var map = new ol.Map({
target: 'map',
layers: [
new ol.layer.Tile({
source: new ol.source.MapQuest({layer: 'sat'})
}),
vectorLayer
],
view: new ol.View({
center: ol.proj.transform([100.514,14.012], 'EPSG:4326', 'EPSG:3857'),
zoom: 11
})
});
然而,如果我尝试直接插入GeoJSON作为一个对象,层显示为一个小点在位置0,0:
var geojsonObject = {"type": "FeatureCollection", "features": [ {"type":"Feature", "id":382, "properties":{"name":"Foo","description":"Bar"}, "geometry":{"type":"MultiPolygon","coordinates":[[[[100.51731551305,14.018177133438],[100.517959243205,14.0188303173272],[100.517133122834,14.0194652831494],[100.516628867536,14.0198920624699],[100.51755154744,14.0206831634993],[100.521199351693,14.0200794287498],[100.518087989239,14.0167692686143],[100.517798310678,14.0169176022848],[100.51731551305,14.018177133438]]]]}} ] };
var vectorSource = new ol.source.Vector({
features: (new ol.format.GeoJSON()).readFeatures(geojsonObject),
projection : 'EPSG:4326'
});
var vectorLayer = new ol.layer.Vector({
source: vectorSource
});
var map = new ol.Map({
target: 'map',
layers: [
new ol.layer.Tile({
source: new ol.source.MapQuest({layer: 'sat'})
}),
vectorLayer
],
view: new ol.View({
center: ol.proj.transform([100.514,14.012], 'EPSG:4326', 'EPSG:3857'),
zoom: 11
})
});
怎么了?
在第二个示例中,向readFeatures调用添加投影选项:
features: (new ol.format.GeoJSON()).readFeatures(geojsonObject,
{dataProjection: 'EPSG:4326', featureProjection: 'EPSG:3857'}),
相关文章:
- 如何使用传单pip插件与纯GeoJSON数据
- 使用AJAX调用将GeoJSON数据拉入传单
- Mapbox JS,来自URL的GeoJSON featureCollection对象只添加了一个标记
- 使用D3.js和GeoJson在地图上的某些坐标上设置一个小图像
- 从传单数据到GeoJSON的多边形
- 在OpenNI中将Zigfu关节位置从真实世界转换为类似投影的位置
- 用于在ng映射中加载GeoJSON的回调
- 使用D3.js和GeoJson在地图上显示States上的一些文本
- 如何在D3.js中绘制地图投影上的点,并使用范围滑块过滤数据
- html画布中的等轴测立方体投影
- JS,使用geojson在googleapi中将标记显示为字符串
- 在传单上绘制GeoJSON
- 使用传单和geoJson监控对象
- 更新GeoJSON元素
- 是否可以使用不同投影的另一个WMS层显示OSM数据
- 基于唯一ID合并geojson
- Mapbox,无法在jquery回调中设置GeoJSON
- 将 GeoJSON 坐标转换为其他投影以用于草坪.js
- 外部文件与内部对象的GeoJSON投影
- 如何在openlayers3中指定GeoJSON的投影