javascript - OpenLayers can't draw geoJSON on map -


i'm trying draw simple shapes (mostly lines) on open street map using openlayers 3. code i’m using directly copied example on site, doesn't seem work me.

var vectorsource = new ol.source.vector({   features: (new ol.format.geojson()).readfeatures(arr[i].geojson) });  var vectorlayer = new ol.layer.vector({   source: vectorsource,   style: stylefunction });  map.addlayer(vectorlayer); 

where stylefunction same function in example, , arr[i].geojson valid geojson object.

the problem is, doesn't draw anything. doing wrong?

you need provide options readfeatures method. geojson projection using 4326 while web map in 3857.

try call:

(new ol.format.geojson()).readfeatures(arr[i].geojson,{     featureprojection:"epsg:3857" }); 

Comments