gpt4 book ai didi

javascript - OpenLayers => 特征为空

转载 作者:行者123 更新时间:2023-11-30 18:37:58 25 4
gpt4 key购买 nike

这是我的 GeoJSON 结果。 PasteBin但是当我加载它时,我在 firebug 中得到的结果是 feature is null。为什么会这样,我的结果有没有错误? JSON 中的坐标是用 WGS84 投影写的,在代码中我也将 externalProjection 设置为 WGS84。那么为什么我会得到返回“feature is null”呢?我用来管理 map 的代码是:

$(document).ready(function() {
var wgs84 = new OpenLayers.Projection('EPSG:4326');
var layer = null;
var map = new OpenLayers.Map('map',{projection: wgs84});
layer = new OpenLayers.Layer.OSM( "Simple OSM Map");
var baseProjection = layer.projection;
map.addLayer(layer);
map.setCenter(new OpenLayers.LonLat(10,10), 4);
map.events.register("moveend", null, function(){

if(map.zoom == 10)
{
var bounds = map.getExtent();
console.log(bounds);
var ne = new OpenLayers.LonLat(bounds.right,bounds.top).transform(map.getProjectionObject(),wgs84);
var sw = new OpenLayers.LonLat(bounds.left,bounds.bottom).transform(map.getProjectionObject(),wgs84);
var vectorLayer = new OpenLayers.Layer.Vector();
map.addLayer(vectorLayer);
$.getJSON('ajax.php?a=markers&type=json&sw=('+sw.lon+','+sw.lat+')&ne=('+ne.lon+','+ne.lat+')',function(data){
//$.getJSON('test.json',function(data){
var geojson_format = new OpenLayers.Format.GeoJSON({
'externalProjection': wgs84,
'internalProjection': baseProjection
});
vectorLayer.addFeatures(geojson_format.read(data));
});
}
});
});

最佳答案

您的示例 OpenLayer 代码工作正常,问题出在您的 GeoJSON 中:您将 coordinates 拼错为 "coordninates"

关于javascript - OpenLayers => 特征为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7702641/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com