I try to add GeoJSON layer to my openlayers 3 by the following code.

        new ol.layer.Vector({
            title: 'added Layer',
            source: new ol.source.GeoJSON({
               projection : 'EPSG:3857',
               url: 'poly1.json'

Getting the following error, Uncaught TypeError: ol.source.GeoJSON is not a constructor

1 Answer 1


to load a geojson file in OL3 use :

var yourVectorSource = new ol.source.Vector({
    projection : 'EPSG:3857',
    url: 'yourFile.geojson',
    format: new ol.format.GeoJSON()

for the source then set it to a vector layer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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