Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I using a Vector Layer with the HTTP protocol to request GeoJSON from my web server, and am trying to get this GeoJSON to display on my map. The GET request appears to be working correctly, as I can see the example JSON I requested in Firebug. However, I am getting an error telling me that "this.format is null Openlayers.js (line 1186)". Unfortunately, the OpenLayers.js file is essentially unreadable so I am having a hard time figuring out what my problem might be.

I set the format for the Vector Layer to GeoJSON. My code for the layer is below:

var newLayer = new OpenLayers.Layer.Vector("Filtered by Zoom Level", {
                        strategies: [new OpenLayers.Strategy.BBOX(), 
                                    refresh,
                                    ],

                        protocol: new OpenLayers.Protocol.HTTP({
                            url: "http://server:8080/test-webapp/servlet",
                        }),

                        filter: filter,

                        styleMap: styleMap,
                        format: new OpenLayers.Format.GeoJSON({
                            externalProjection: new OpenLayers.Projection("EPSG:4326"),
                            internalProject: new OpenLayers.Projection("EPSG:900913")
                        })

                    });

Does anybody have any ideas as to what the issue might be?

Thanks,

-Rob

share|improve this question
1  
To look a bit deeper into what OL sees, you could try pointing to OpenLayers.debug.js instead of OpenLayers.js. They are both at the top level of the OL directory. –  katahdin Dec 28 '12 at 20:21
    
Have you looked at your traffic? Is the request to the server failing? –  Jamie Dec 28 '12 at 20:38
    
Thanks katahdin, I will take a look at that. Jamie, the request to the server appears to be working. In Firebug, the Response for the GET request is correct. –  robc89 Dec 28 '12 at 20:41
    
Any chance to see the geoJSON ? And do give us your openlayers versions please. –  Glenn Plas Dec 28 '12 at 21:15
    
The geoJSON response looks like this: {"features":[{"type":"Point","coordinates":[15.8,4.1]}],"type":"FeatureCollectio‌​n"} It is possible that I am not adhering to the geoJSON standards. I am using OpenLayers version 2.12. Thanks. –  robc89 Jan 2 '13 at 15:00
show 1 more comment

2 Answers

up vote 0 down vote accepted

It turns out that I also needed to add a format field to the protocol object, not just in the layer object. The working code is:

var newLayer = new OpenLayers.Layer.Vector("Filtered by Zoom Level", {
                    strategies: [new OpenLayers.Strategy.BBOX(), 
                                refresh,
                                ],

                    protocol: new OpenLayers.Protocol.HTTP({
                        url: "http://server:8080/test-webapp/servlet",
                        format: new OpenLayers.Format.GeoJSON({
                            externalProjection: new OpenLayers.Projection("EPSG:4326"),
                            internalProject: new OpenLayers.Projection("EPSG:900913")
                        })
                    }),

                    filter: filter,

                    styleMap: styleMap,
                    format: new OpenLayers.Format.GeoJSON({
                        externalProjection: new OpenLayers.Projection("EPSG:4326"),
                        internalProject: new OpenLayers.Projection("EPSG:900913")
                    })

                });

Thank you to everybody for the suggestions!

share|improve this answer
add comment

I edited a GeoJSON map of my own to match your loading strategy. The map also failed to load for me. I got rid of the "refresh" command and the map loaded as normal. I'd try that.

So:

var newLayer = new OpenLayers.Layer.Vector("Filtered by Zoom Level", {
                    strategies: [new OpenLayers.Strategy.BBOX()],

                    protocol: new OpenLayers.Protocol.HTTP({
                        url: "http://server:8080/test-webapp/servlet",
                    }),

                    filter: filter,

                    styleMap: styleMap,
                    format: new OpenLayers.Format.GeoJSON({
                        externalProjection: new OpenLayers.Projection("EPSG:4326"),
                        internalProject: new OpenLayers.Projection("EPSG:900913")
                    })

                });
share|improve this answer
    
Thanks for the suggestion bshender. Unfortunately, removing the refresh strategy did not fix the problem. I didn't include the code for the strategy, but I have used it successfully in another situation. –  robc89 Jan 2 '13 at 14:58
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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