javascript - openlayers 中的 UTM 和 GeoJson

标签 javascript openlayers

我想实现这个例子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/

相关文章:

javascript - 为什么 vinyl.isVinyl() 对于 gulp 发出的乙烯基文件返回 false?

javascript - GetElementsByClassName 和正则表达式

javascript - 如何初始化像这样的 jQuery 小部件 : var newMap = xgis. map ('#map' ,选项);

javascript - 如何以编程方式显示图层面板?

ruby-on-rails - Openlayers 标记

javascript - 将样式图分配给单个向量

javascript - ol-ext Controller 中的控制栏和功能

javascript - Jquery表行计算,多行/列

javascript - 如何在谷歌地图中偏移 panTo

javascript - 如何在 JavaScript 中验证时间戳