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

Liesel bliesel at rocketmail.com
Wed Dec 19 06:15:19 PST 2012


Hey List,
i've got a problem with the http-protocol. It seems simple but I got a
an error-message:
Uncaught TypeError: Cannot call method 'equals' of null
OpenLayers.debug.js:43300

I had a look in the code. The first argument of the function,
mapProjection, is null thats right. And null.equals() cannot be
working.
The relevant function merge is in the OpenLayers.Strategy.Fixed class.

Maybe I have to set a projection of all layers added to my map. But it
still not working with that.
VectorFeatures comes from a geojson-file. I tried to add them by
myself. With vectorLayer.addFeatures() this works. But I would like to
use the fixedStrategy or the refreshStrategy. Therefor I have to use
the http-protocol in openLayers.

Does anybody have a clue why its not working? Where do I have to set
the projection? Anywhere else than in map and vectorLayer?

Thanks in advance.
Liesel


Thats the js-code:
function readFeatures(fun) {
    var read;
    $.get("pois", {}, function(data, textStatus, jqXHR) {
        if(textStatus == "success") {
            fun(data);
        } else {
            alert("Cannot receive POIs");
        }
    });
}

function loadMap() {
    map = new OpenLayers.Map('map', {
        projection: "EPSG:4326"
        displayProjection: "EPSG:4326"
    });

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

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

    map.setCenter(new OpenLayers.LonLat(7.6, 51.9), 13);


/* The following works as expected */
    map2 = new OpenLayers.Map('map2', {
        projection: "EPSG:4326"
        displayProjection: "EPSG:4326"
    });

    var vectorLayer2 = new OpenLayers.Layer.Vector("GeoJSON");
    map.addLayer(vectorLayer2);
    var geojson_format = new OpenLayers.Format.GeoJSON();
    readFeatures(function(data) {
            data = geojson_format.read(data_json);
            vectorLayer2.addFeatures(data);
    });
    map2.addLayer(osm);

    var osm2 = new OpenLayers.Layer.OSM("simple OSM", null);
    map2.addLayer(osm2);

    map2.setCenter(new OpenLayers.LonLat(7.6, 51.9), 13);

}


And the geoJson-File:
{"type": "FeatureCollection", "features": [ {"type": "Feature",
"geometry":{"type":"Point", "coordinates":[3.0, 5.0]}, "properties":
{"id": "1"}}, {"type": "Feature", "geometry":{"type":"Point",
"coordinates":[51.962944, 7.628694]}, "properties": {"id": "2"}},
{"type": "Feature", "geometry":{"type":"Point",
"coordinates":[7.6170653, 51.96770399999998]}, "properties": {"id":
"8"}}, {"type": "Feature", "geometry":{"type":"Point",
"coordinates":[3.0, 5.0]}, "properties": {"id": "15"}}, {"type":
"Feature", "geometry":{"type":"Point",
"coordinates":[-129.8626730292999, 90.0]}, "properties": {"id": "18"}},
{"type": "Feature", "geometry":{"type":"Point",
"coordinates":[-12.074459351599, 90.0]}, "properties": {"id": "19"}},
{"type": "Feature", "geometry":{"type":"LineString",
"coordinates":[[-129.8626730292999, 90.0], [-139.74427718669995, -90.0],
[-90.99020764604, -90.0], [116.78968704860017, 90.0], [122.28750441223,
90.0]]}, "properties": {"id": "20"}}, {"type": "Feature",
"geometry":{"type":"Polygon", "coordinates":[[[35.968871980900076,
90.0], [-148.97193009779994, 90.0], [128.43927301839005, 90.0],
[35.968871980900076, 90.0]]]}, "properties": {"id": "21"}}, {"type":
"Feature", "geometry":{"type":"Polygon",
"coordinates":[[[-15.657445058227, 50.172238148749], [-28.197895009071,
29.868652511388], [-39.544016391039, 45.992088165134],
[-15.657445058227, 50.172238148749]]]}, "properties": {"id": "22"}}]}


More information about the Users mailing list