我有一个地图表示形式,我想添加一个基于 GEOJSON 的图层,但我不想直接从 GEOJSON 文件读取它,而是有一个包含我需要的确切 GEOJSON 字符串的变量,可以从变量而不是 url 加载它吗?
var map = new ol.Map({
target: 'map',
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
}),
new ol.layer.Vector({
title: 'bikesRented',
source: new ol.source.Vector({
url: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
format: new ol.format.GeoJSON()
}),
style: bikeStyle2
})
],
view: new ol.View({
center: ol.proj.fromLonLat([11.341868,44.494949]),
zoom: 14
})
});
Run Code Online (Sandbox Code Playgroud)