How do I load GeoJSON file, which is in my laptop, into my HTML code to include some features into my OpenLayers map?


Load it into a vector source with an URL relative to the location of your Javascript/HTML file:

var vectorSource = new ol.source.Vector({
    url: "layers/features.geojson",
    format: new ol.format.GeoJSON()

See this example for more details.


You can refre this answer Solved Answer.

You can include openlayers-3 in your html code and include the following code

var gjson_source=new ol.source.Vector({
                    url: "geojson.txt,      
                    format: new ol.format.GeoJSON()
var gjson = new ol.layer.Vector({
                    source: gjson_source

url will be your Geojson file but extension as txt.

Pleaser refer Geojson Example

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.