1

如何通过ol-ext Viglino向切换器添加 KML 层?

当我添加:

var vectorSource = new ol.layer.Vector({
  source: new ol.source.Vector({
  url: "IG1.kml",
  format: new ol.format.KML()
})

该图层不会出现在地图上。

4

2 回答 2

2

要出现在图层切换器中,图层必须具有标题属性

var vectorSource = new ol.layer.Vector({
  title: "KML Layer",
  source: new ol.source.Vector({
    url: "IG1.kml",
    format: new ol.format.KML()
  })
})

如果图层未出现在地图上,请检查.kml您的服务器 MIME 类型中是否启用了扩展。

于 2021-08-11T11:35:14.623 回答
0

尝试 :

import KML from 'ol/format/KML';
import VectorSource from 'ol/source/Vector';
import {Vector as VectorLayer} from 'ol/layer';

const vector = new VectorLayer({
  source: new VectorSource({
    url: 'IG1.kml',
    format: new KML(),
  }),
});
于 2021-08-11T11:22:46.073 回答