OpenLayers 3.13v:ol.format.GeoJSON()问题

时间:2016-03-11 16:32:36

标签: javascript openlayers-3

在OpenLayers 3.13v中,我使用ol-debug.js获取// Create the module once angular.module('newApp', ['angularSpinner', 'ui.bootstrap']); // Reference it by invoking it with just one parameter angular.module('newApp').controller('newController', ...); angular.module('newApp').factory('utilityFactory', ...); ,而使用ol.js获取Uncaught AssertionError: Assertion failed: format must be set when url is set

我通过替换Uncaught TypeError: Cannot read property 'V' of undefined in this example

来使用以下代码
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
  });

1 个答案:

答案 0 :(得分:1)

您必须将实例传递给源format选项:

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
});

另请注意,projection没有ol.source.Vector选项。

如果要创建空来源,则不应设置format

var bbox = new ol.layer.Vector({
  source: new ol.source.Vector()
});

要向上面的源添加要素,您需要在视图投影中使用几何图形创建它们,例如使用bbox.getSource().addFeatures