[OpenLayers-Users] got an error when used geojson with http andfixedstrategy

Arnd Wippermann arnd.wippermann at web.de
Wed Dec 19 14:28:27 PST 2012


Sorry, the absent fileending has misleading me.

I don't no know, why the second case works.

But some hints for the first case:

OSM works only in EPSG:900913. Your declaration in the map object have no
effect
as the OSM layer will be added as baselayer and forces the projection to
EPSG:900913.

Add your baselayer first.
Transform your centerpoint from EPSG:4326 to the map projection (see above).

For test purposes use zoomlevel=0. Perhaps your features are added at a
location, 
where you would not assume them.

function loadMap()
{
    var p4326 = new OpenLayers.Projection("EPSG:4326");

    map = new OpenLayers.Map('map', {
        projection: "EPSG:900913",            //OSM have to be in
EPSG:900913
        displayProjection: "EPSG:4326"
    });

    var osm = new OpenLayers.Layer.OSM("simple OSM", null);

    var vec1_GeoJSON = new OpenLayers.Layer.Vector("vec1_GeoJSON", {
        projection: p4326,
        protocol: new OpenLayers.Protocol.HTTP({
            url: "pois",
            format: new OpenLayers.Format.GeoJSON({})
        }),
        strategies: [new OpenLayers.Strategy.Fixed()]
    });

    map.addLayers([osm, vec1_GeoJSON]);
    map.setCenter(new OpenLayers.LonLat(7.6, 51.9).transform(p4326,
map.getProjectionObject()), 1);
}

That would work for me.

Arnd


 



-----Ursprüngliche Nachricht-----
Von: Liesel [mailto:bliesel at rocketmail.com] 
Gesendet: Mittwoch, 19. Dezember 2012 18:12
An: arnd.wippermann at web.de
Betreff: Re: [OpenLayers-Users] got an error when used geojson with http
andfixedstrategy

On Wed, 19 Dec 2012 16:24:25 +0100, "Arnd Wippermann"
<arnd.wippermann at web.de> wrote:
> you have to provide an url and not a string:
> 
> url: "pois",

maybe i'm going to misunderstand you, but there is a url. there is no
difference, except the fileending, to this:
url: "/pois.json"

greetings,
liesel



More information about the Users mailing list