我使用OpenLayers從json數據製作地圖。我必須加載它(使用PHP)來檢查時間戳並驗證信息。那時候,我寧願輸出一個javascript變量,只讓OL使用它。我似乎無法在文檔中完成此操作。Openlayers:來自本地變量的矢量圖層
理想情況下,我只希望改變'url': 'latest.json'
爲類似'local': json_variable
var pointsSource = new ol.source.GeoJSON({
'projection': map.getView().getProjection(),
'url': 'latest.json'
});
var pointsLayer = new ol.layer.Vector({
source: pointsSource,
style: new ol.style.Style({
image: new ol.style.Icon(({
anchor: [0.5, 40],
anchorXUnits: 'fraction',
anchorYUnits: 'pixels',
src: 'openlayers/marker-icon.png',
}))
})
});
map.addLayer(pointsLayer);
工作就像一個魅力,乾杯! – frogg3862