简体   繁体   中英

UTM and GeoJson in openlayers

I want to implement this example http://api.geoext.org/1.1/examples/feature-grid.html made of geoext and openlayers, that feature grid is populated of a geojson file

In my development I have a geojson file with utm format, this is a single feature of my file (the coordinates are utm)

{"geometry": {"type": "Point", "coordinates": [7535169.36, 402844.172]}, "type": "Feature", "properties": {"NOMBRE": "LA VICTORIA", "CODIGO": "1702"}, "id": "1702"}

I tried to show the points in my code, but I can't see anything, this is my code

// 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
            });

as you can see, I tried to specify the internal and external projection of the feature store, my implementation looks like the example of the link mentioned above, but when I select a city the map is located to a wrong place (the place is shown near south pole, but it has to be near south america)

Thanks in advance

For what reason FeatureStore..? Just define layer as following:

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
    })
});

Also register following event on map:

map.events.register("moveend", this, function (e) {
    vecCiudades.refresh({force:true});
});

That will reread GeoJSON anytime moved or zoomed map and request will contain bounding box of visible area so you can only send features that going to be visible not all of them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM