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.

Greetings lovers of GIS,

I came across this error whilst doing my JSON file.

"Error in loading GML file"

Everything works fine in localhost but dramatically wrong in my server. Any helping hands?

These are my JavaScript codes. Thanks in advance.

var map, wms, vectors;
    function init(){
    map = new OpenLayers.Map("map", {numZoomLevels: 5});
    OpenLayers.Feature.Vector.style['default']['fillOpacity'] = 0.9;
    //var MyJSON ="internet_users_2005.json.fixed"
    vectors = new OpenLayers.Layer.GML("Internet Users", "internet_users_2005.json.fixed", {
    format: OpenLayers.Format.GeoJSON,
    styleMap: build_style(),
    isBaseLayer: true,
    projection: new OpenLayers.Projection("EPSG:4326"),
    attribution: "<a href='http://www.gis.com.my/' >GISI</a>"});
    map.addLayers([vectors]);
    map.zoomToMaxExtent();
    var options = {
    hover: true,
    onSelect: function(feature) {
    $("info").innerHTML = feature.attributes.name + ": "+ feature.attributes.value;
    }
    };
    var select = new OpenLayers.Control.SelectFeature(vectors, options);
    map.addControl(select);
    select.handler.stopDown = false;
    select.handler.stopUp = false;
    select.activate();
    }
    function build_style() {
    var theme = new OpenLayers.Style();
    var ruleHigh = new OpenLayers.Rule(
    {
    filter: new OpenLayers.Filter.Comparison({
    type: OpenLayers.Filter.Comparison.GREATER_THAN_OR_EQUAL_TO,
    property: "value",
    value: 50 }),
    symbolizer: {"Polygon": {'fillColor': '#ff0000'}}
    });
    var ruleMed1 = new OpenLayers.Rule({filter: new OpenLayers.Filter.Logical({
    type: OpenLayers.Filter.Logical.AND,
    filters: [
    new OpenLayers.Filter.Comparison({
    type: OpenLayers.Filter.Comparison.LESS_THAN,
    property: "value",
    value: 50
    }),
    new OpenLayers.Filter.Comparison({
    type: OpenLayers.Filter.Comparison.GREATER_THAN,
    property: "value",
    value: 20
    })
    ]
    }),
    symbolizer: {"Polygon": {'fillColor': '#ff6600'}}
    });
    var ruleMed2 = new OpenLayers.Rule({filter: new OpenLayers.Filter.Logical({
    type: OpenLayers.Filter.Logical.AND,
    filters: [
    new OpenLayers.Filter.Comparison({
    type: OpenLayers.Filter.Comparison.LESS_THAN,
    property: "value",
    value: 20
    }),
    new OpenLayers.Filter.Comparison({
    type: OpenLayers.Filter.Comparison.GREATER_THAN,
    property: "value",
    value: 10
    })
    ]
    }),
    symbolizer: {"Polygon": {'fillColor': '#ffcc00'}}
    });
    var ruleLow = new OpenLayers.Rule({filter: new OpenLayers.Filter.Comparison({
    type: OpenLayers.Filter.Comparison.LESS_THAN, 
    property: "value",
    value: 10
    }),
    symbolizer: {"Polygon": {'fillColor': '#ffff66'}}
    });
    theme.addRules([ruleLow, ruleMed1, ruleMed2, ruleHigh]);
    var stylemap = new OpenLayers.StyleMap({'default':theme, 'select': {'strokeColor': '#0000ff', 'fillColor': '#0000ff', 'strokeWidth': 2}});
    return stylemap;
    }
share|improve this question
    
I'm hesitating to start a new question on this, but I have the problem, just the other way around: A map with custom tiles and one GeoJSON polygon layer works perfectly in FF, but won't show the polygons in IE (already validated the GeoJSON, no trailing commas involved). The file itself is loaded successfully by both browsers (according to Firebug/IE9 dev tools). But IE9 keeps complaining about some "c=JSON.parse(a,b)" error within OpenLayers.js (I use the full version for debug purposes) - I can't imagine this is really an issue, as it works in FF? –  SAnderka Dec 21 '12 at 16:37

2 Answers 2

up vote 2 down vote accepted

GeoJSON is not GML, so this won't work.

vectors = new OpenLayers.Layer.GML("Internet Users", "internet_users_2005.json.fixed", {
    format: OpenLayers.Format.GeoJSON,

Since you are reading your data from a file, you will need to read in the json into a variable. In your internet_users_2005.json.fixed file, change it so it's set as a variable:

var data = ...json...

Load the json into the map script with:

<script type="text/javascript" src="internet_users_2005.json.fixed"></script>

then replace the GML provider with this:

// create GeoJSON parser    
var geojson_format = new OpenLayers.Format.GeoJSON();
// create vector layer
var vectors = new OpenLayers.Layer.Vector(); 
// parse GeoJSON
vectors.addFeatures(geojson_format.read(data));

map.addLayer(vectors);
share|improve this answer
1  
- It's actually perfectly valid to load the JSON file through GML layer. e.g. docs.openlayers.org/library/…. I still wonder if @zearth is having issues with the file path. –  Vadim Jul 18 '11 at 14:11
    
you're right, I stand corrected –  sophia Jul 18 '11 at 15:40
    
I do not have problem with my file path. Only syntax error, actually. –  zearth Aug 3 '11 at 7:14

Check in Firebug (Firefox) or Fiddler (IE) if your file internet_users_2005.json.fixed is in fact being loaded. I suspect there's a problem with the path.

share|improve this answer
    
Of course @Vadim. There's nothing odd in my Firebug. As we can view them locally. Path is 100% correct. Beforehand, I did mentioned that it is a online problematic. Any other brilliant ideas? –  zearth Jul 18 '11 at 2:41
2  
@zearth - heads up - that kind of attitude will not get you help on this board. Your path may be fine on localhost, but maybe you didn't deploy the file to production? Maybe you have a .htaccess that's it blocking access to the *.fixed extension. Who knows?! You should check firebug while running on Production not on your dev/test environment. –  Vadim Jul 18 '11 at 2:46
3  
@zearth - and you have way too much code in your example. Try to slim it down to just the file loading and basic display of data. i.e. Symbolizer and SelecFeature debugging should come after you can just load a basic file in dev/test and production. –  Vadim Jul 18 '11 at 2:52
1  
@zearth, I am not too sure having a quick case of the smarts is the best way to get help here. Reign it in please. –  Hairy Jul 18 '11 at 9:51
1  
By the way, if you are working on Windows OS locaaly, your path is not case sensitive but it would probably be online on UNIX server. –  simo Jul 18 '11 at 15:35

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.