0

I'm having trouble creating an OpenLayers Vector layer with GeoJSON data in an MVC 4 application.

The GET request for my json file always comes back with a 404.3 error - page cannot be served because of the extension configuration.

I've followed every OpenLayers example creating the GeoJSON layer just as they have but I can't get mine to display. I've followed the steps in this post Trouble displaying GeoJSON file in OpenLayers and everything besides the GeoJSON layer works great.

So in my OpenLayers.aspx page I have the following code to initialize my vector layer.

var vector = new OpenLayers.Layer.Vector("GeoJSON", {
            projection: new OpenLayers.Projection("EPSG:900913"),
            strategies: [new OpenLayers.Strategy.Fixed()],
            protocol: new OpenLayers.Protocol.HTTP({
                url: "<%:this.Url.Content("~/Content/Delta_Parcels_2008.json") %>",
                format: new OpenLayers.Format.GeoJSON({
                    internalProjection: new OpenLayers.Projection("EPSG:900913"),
                    externalProjection: new OpenLayers.Projection("EPSG:4326")
                })
            }),
            styleMap: vector_style_map
        });

any suggestions would be much appreciated. thanks.

  • Can you get more details about the 404 error? – steko Mar 18 '13 at 23:14
0

IIS and IIS Express do not have the mime type for "json" by default. You need to add the mime type to your web server so it knows to server the JSON file. If you are using the built in web server (Cassini) then it does not have support and you will need to switch.

Here is how you do it:

IIS 7: http://www.uipress.com/add-json-handler-support-in-iis-7/#.UUds21eRfQM

IIS Express: http://michaellhayden.blogspot.com/2012/07/add-json-mime-type-to-iis-express.html

You can also do it in your web.config: https://stackoverflow.com/questions/5924647/setting-mime-types-using-the-asp-net-development-server

  • excellent, that did the trick. No longer getting the 404 error, now to just figure out why it isn't displaying I'm guessing the projection is off. Thanks again. – user501211 Mar 18 '13 at 20:06

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.