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 am learning to use GeoExt and OpenLayers, and I want to reproduce one of the examples given at the geoExt website. The script call a GeoJSON containg the position of Alp summits. I downloaded it via wget and put it in data/summits.json.

I copy pasted the javascript file in a local folder, but when I run it in Firefox, I get a not well formed error. I got the same error with several other examples involving a json file. I looked for similar problems on the web, but couldn't find an answer. What am I missing?

The part of the script adding the layer from the json file is

var summits = new OpenLayers.Layer.Vector("Summits",{
    strategies: [new OpenLayers.Strategy.Fixed()],
    protocol: new OpenLayers.Protocol.HTTP({
        url: "data/summits.json",
        format: new OpenLayers.Format.GeoJSON()
    }),
    styleMap: new OpenLayers.StyleMap(new OpenLayers.Style({},{rules: rules}))
});

I used the same bit of code in several other examples provided by the website (modulo the styleMap part) with always the same error.

Thanks

share|improve this question
    
I think you may need to pull the json file from a web server not a file (or at least a full URL) –  iant May 29 '13 at 8:47
2  
Try validating your geojson: geojsonlint.com –  atlefren May 29 '13 at 9:02

1 Answer 1

up vote 1 down vote accepted

Your problem may be the line 10 of your vector-legend.html, you're probably using:

<script type="text/javascript" src="../script/GeoExt.js"></script>

but you need to download that file to your pc first with:

wget http://api.geoext.org/1.1/GeoExt/script/GeoExt.js

and then edit the HTML like:

<script type="text/javascript" src="GeoExt.js"></script>

or even easier, simply use:

<script type="text/javascript" src="http://api.geoext.org/1.1/GeoExt/script/GeoExt.js"></script>

that should do the trick. BTW, the summits.json works perfectly after using wget.

Hope this helps,

share|improve this answer
    
Okay, apparently the problem was elsewhere. The GeoExt.js I was using was coming from an Opengeo workshop. By using the script directly from api.geoext.org, the json appears correctly. The "not well formed" is still there though. I used @atlefren website, and it did not return any error –  Bulkilol May 29 '13 at 11:45
    
so probably the opengeo workshop is the problem. Please consider upvoting if the answer helped you. –  Gery May 29 '13 at 11:49

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.