In OpenLayers 3.13v, I obtain Uncaught AssertionError: Assertion failed: format must be set when url is set
with ol-debug.js, while Uncaught TypeError: Cannot read property 'V' of undefined
with ol.js
I use the following code by replacing ol.source.GeoJSON
in this example
var vectorEuropa = new ol.layer.Vector({
id: 'europa',
source: new ol.source.Vector({
format: ol.format.GeoJSON(),
projection: 'EPSG:3857',
url: '../assets/data/nutsv9_lea.geojson'
}),
style: defaultEuropa
});
Moreover, I have the same issue if I try to create an empty layer like in this example
var bbox = new ol.layer.Vector({
source: new ol.source.Vector({
format: ol.format.GeoJSON()
})
});
You have to pass an instance to the source's format
option:
var vectorEuropa = new ol.layer.Vector({
id: 'europa',
source: new ol.source.Vector({
format: new ol.format.GeoJSON(),
url: '../assets/data/nutsv9_lea.geojson'
}),
style: defaultEuropa
});
Also note that there is no projection
option for ol.source.Vector
.
If you want to create an empty source, you should not be setting a format
:
var bbox = new ol.layer.Vector({
source: new ol.source.Vector()
});
To add features to the source above, you will need to create them with geometries in the view projection, and eg use bbox.getSource().addFeatures
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.