簡體   English   中英

打開第3層:如何僅顯示KML層

[英]Open Layers 3: how to display only a KML layer

我正在嘗試創建一個僅顯示KML圖層而沒有基礎地圖或基礎圖塊圖層的OpenLayers地圖。

KML圖層將是一個室內樓層地圖,但是它不必位於特定坐標位置的現有地圖之上。 我只需要單獨顯示樓層地圖,而無需顯示其他地圖。 我還將要設置平移限制,以使用戶無法平移地圖。

以下是一些我用來在現有基礎地圖上方成功顯示KML層的代碼。 我已經嘗試了很多方法來嘗試讓KML圖層自行顯示,但無濟於事。

任何人都可以幫忙解決這個問題,或者告訴我我需要對以下代碼進行更改以單獨顯示KML嗎?

var vector = new ol.layer.Vector({
        source: new ol.source.Vector({
            url: MAPS_URL + 'map1.kml',
            format: new ol.format.KML()
        })
    });

var map = new ol.Map({
           target: 'map',
           layers: [
              new ol.layer.Tile({
                  source: new ol.source.MapQuest({layer: 'sat'})
              }),
              vector
           ],
           view: new ol.View({
           center: ol.proj.transform([37.41, 8.82], 'EPSG:4326', 'EPSG:3857'),
           zoom: 2
       })
   });

map.addLayer(vector);

謝謝!

當Jonatas和Tsauerwein退出時,我只需要刪除平鋪層。

var vector = new ol.layer.Vector({
    source: new ol.source.Vector({
        url: MAPS_URL + 'map1.kml',
        format: new ol.format.KML()
    })
});

var map = new ol.Map({
       target: 'map',
       layers: [vector],
       view: new ol.View({
       center: ol.proj.transform([37.41, 8.82], 'EPSG:4326', 'EPSG:3857'),
       zoom: 2
   })
});

map.addLayer(vector);

您檢查過是否可以讀取KML文件嗎? 可能存在CORS問題。

我建議使用AJAX調用來加載KML,然后使用ol.format.KML讀取功能並將其添加到源中。

sourceVector = new ol.source.Vector();
layerVector = new ol.layer.Vector({
  source: sourceVector
  });
formatKML = new ol.format.KML({extractStyles: false});
$.ajax('http://storage.googleapis.com/dbauszus-file-bucket/rtmLmpHg.kml',{
  type: 'GET',
  contentType: 'application/vnd.google-earth.kml+xml', 
  success : function(response) {
    features = formatKML.readFeatures(response,{
      dataProjection: 'EPSG:4326',
      featureProjection: 'EPSG:3857'
    });
    sourceVector.addFeatures(features);
    }
  });

如果您無法讀取此類文件,請在Firebugz NET選項卡中檢查CORS問題。 在此處輸入圖片說明

暫無
暫無

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

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