2017-09-30 66 views
0

我跟在openlayers手冊的example上,在osf層頂部添加靜態圖像。它可以工作,但我的圖像(256x256)顯示爲矩形。我試圖與周圍的投影座標,並檢查了這裏的其他職位,但爲什麼圖像不顯示爲一個正方形,我不能讓我的頭周圍:圖像在osf層頂部的靜態圖像層上顯示錯誤

// Create map 
var map = new ol.Map({ 
    target: 'map', // The DOM element that will contains the map 
    renderer: 'canvas', // Force the renderer to be used 
    layers: [ 
    // Add a new Tile layer getting tiles from OpenStreetMap source 
    new ol.layer.Tile({ 
     source: new ol.source.OSM() 
    }) 
    ], 
    // Create a view centered on the specified location and zoom level 
    view: new ol.View({ 
    center: ol.proj.transform([16.3725, 48.208889], 'EPSG:4326', 'EPSG:3857'), 
    zoom: 4 
    }) 
}); 

// Create an image layer 
var imageLayer = new ol.layer.Image({ 
    opacity: 0.75, 
    source: new ol.source.ImageStatic({ 
    attributions: [ 
     new ol.Attribution({ 
     html: '' 
     }) 
    ], 
    url: 'https://placebear.com/256/256', 
    imageSize: [256, 256], 
    projection: map.getView().getProjection(), 
    imageExtent: ol.extent.applyTransform(
     [0, 0, 16.3725, 48.208889], ol.proj.getTransform("EPSG:4326", "EPSG:3857")) 
    }) 
}); 

map.addLayer(imageLayer); 

回答

1

ol.source.ImageStatic是爲了放地理參考圖像(例如歷史地圖的掃描)。這是你想到的嗎?如果您只想顯示圖像並將其定位到地圖上的某個位置,則最好使用ol.Overlayol.layer.Vector,並使用ol.style.Icon的功能。

也就是說,如果在ol.source.ImageStatic上設置的imageExtent導致投影地圖視圖上顯示一個正方形,那麼您的圖像將僅顯示爲方形。

+0

感謝您的澄清,實際上我想顯示一個覆蓋圖像,例如頂部的戰略地圖。關於圖像投影,我很困惑如何計算像素的緯度/經度座標。有沒有一種方法可以從起點計算經緯度,簡單地說,在南方走x米(如果我說像素是一米)? –

+0

我現在添加它作爲預期的事情。所以我的問題現在已經過時了。 –