2

I have an OpenStreetMap (OSM) map with a vector layer fetching data from a Node.js server setup on my local machine on port 9000. The data is in GeoJSON format.

Here is the whole code:

        var fromProjection = new OpenLayers.Projection("EPSG:4326");
        var toProjection = new OpenLayers.Projection("EPSG:3857");

        var map = new OpenLayers.Map("map");

        var vectorFormat = new OpenLayers.Format.GeoJSON();
        var vectorProtocol = new OpenLayers.Protocol.HTTP({
            url: "http://localhost:9000/getcoords",
            format: vectorFormat,
            params: {
                "city":"PARIS",
                "city_code":3
            }
        });
        var refresh = new OpenLayers.Strategy.Refresh({ force: true, active: true });
        var vectorStrategies = [new OpenLayers.Strategy.Fixed(), refresh];

        var osm = new OpenLayers.Layer.OSM();

        var vectors = new OpenLayers.Layer.Vector({
            protocol: vectorProtocol,
            strategies: vectorStrategies,
            format: vectorFormat
        });

        map.addLayers([osm, vectors]);
        map.setCenter(new OpenLayers.LonLat(2.3983034, 47.078038).transform(fromProjection, toProjection), 6);

My problem is that my map is displayed, but the url defined in my protocol is never called. In firebug, I can't see any access to this url, so I can't see my vector layer.

What am I doing wrong?

2

Ok, just found the problem : I forgot the parameter "name" in my Vector constructor... My bad

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.