我想实现这个例子http://api.geoext.org/1.1/examples/feature-grid.html由 geoext 和 openlayers 组成,该特征网格由 geojson 文件填充
在我的开发中,我有一个 utm 格式的 geojson 文件,这是我的文件的一个特征(坐标是 utm)
{"geometry": {"type": "Point", "coordinates": [7535169.36, 402844.172]}, "type": "Feature", "properties": {"NOMBRE": "LA VICTORIA", "CODIGO": "1702"}, "id": "1702"}
我试图在我的代码中显示这些点,但我什么也看不到,这是我的代码
// create feature store, binding it to the vector layer
store = new GeoExt.data.FeatureStore({
layer: vecCiudades,
fields: [
{ name: 'NOMBRE' },
{ name: 'CODIGO' }
],
proxy: new GeoExt.data.ProtocolProxy({
protocol: new OpenLayers.Protocol.HTTP({
url: "data/summits.json",
format: new OpenLayers.Format.GeoJSON({
ignoreExtraDims: true,
internalProjection: new OpenLayers.Projection("EPSG:900913"),
externalProjection: new OpenLayers.Projection("EPSG:4326")
})
})
}),
autoLoad: true
});
如您所见,我尝试指定特征存储的内部和外部投影,我的实现看起来像上面提到的链接示例,但是当我选择一个城市时, map 位于错误的位置(位置显示在南极附近,但必须在南美洲附近)
提前致谢
最佳答案
为什么 FeatureStore..?只需定义层如下:
var vecCiudades = new OpenLayers.Layer.Vector('MyLayer', {
strategies:[new OpenLayers.Strategy.BBOX()],
isBaseLayer:false,
projection:new OpenLayers.Projection("EPSG:900913"),
styleMap:new OpenLayers.StyleMap(null),
transitionEffect:'resize',
protocol:new OpenLayers.Protocol.HTTP({
url: "data/summits.json",
format:new OpenLayers.Format.GeoJSON({
ignoreExtraDims:true
}),
readWithPOST:false,
updateWithPOST:false,
srsInBBOX:true
})
});
同时在 map 上注册以下事件:
map.events.register("moveend", this, function (e) {
vecCiudades.refresh({force:true});
});
这将在任何时候移动或缩放 map 时重新读取 GeoJSON,并且请求将包含可见区域的边界框,因此您只能发送将要显示的要素,而不是所有要素。
关于javascript - openlayers 中的 UTM 和 GeoJson,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10883503/