簡體   English   中英

OpenLayers 3.13v:ol.format.GeoJSON() 問題

[英]OpenLayers 3.13v: issue with ol.format.GeoJSON()

在 OpenLayers 3.13v 中,我獲得了Uncaught AssertionError: Assertion failed: format must be set when url is set with ol-debug.js,而Uncaught TypeError: Cannot read property 'V' of undefined with ol.js

我通過替換本例中的ol.source.GeoJSON 使用以下代碼

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

此外,如果我嘗試像本例中那樣創建一個空層,我也會遇到同樣的問題

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

您必須將實例傳遞給源的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
});

另請注意, ol.source.Vector沒有projection選項。

如果要創建空源,則不應設置format

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

要向上面的源添加功能,您需要在視圖投影中使用幾何圖形創建它們,例如使用bbox.getSource().addFeatures

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM