Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

After some hunting, it seems that if I have an a geojson file, I NEED the data and map to be on a server in order to view this in OpenLayers because of the protocol class. I saw an example where I can basically read the file as a javascript object by inserting it into my code. But there must be a way to simple throw my .json file without a server - right? I was able to do it with leaflet... I'm a newbie at this so any help would be much appreciated!

share|improve this question
up vote 3 down vote accepted

If by "there must be a way to simple throw my .json file", you mean load your .json file on to your map as features...

You can do it like this:

vectorLayer = new OpenLayers.Layer.Vector("MyLayer");

function handler(request) {

    var geojson_format = new OpenLayers.Format.GeoJSON({
        'internalProjection': map.baseLayer.projection,
        'externalProjection': new OpenLayers.Projection("EPSG:4326")


var request = OpenLayers.Request.GET({
    url: "geojson.json",
    callback: handler
share|improve this answer

Your Answer


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.