如何从 JavasCript 对象在 OpenLayers 6.5 中创建矢量源?

How to create a VectorSource in OpenLayer 6.5 from a JavasSript object?

我想创建一个使用 OpenLayer 6.5 的网络应用程序。我想动态标记一些位置,所以我不能在我的服务器上保留一些“.geojson”文件。我该怎么办?

我正在尝试从 JavaScript GeoJson 对象创建 VectorSource,但它总是显示错误的位置!这段代码有什么问题?

var GeoJSONObject = {
    type: "FeatureCollection",
    features: [
      {
        type: "Feature",
        properties: {},
        geometry: {
          type: "Point",
          coordinates: [
            70.33447265624999,
            55.541064956111036
          ]
        }
      }
    ]
  };

var vectorSource = new ol.source.Vector({
        features: new ol.format.GeoJSON().readFeatures(GeoJSONObject)
});

var vectorLayer = new ol.layer.Vector({
    renderMode: 'image',
    source: vectorSource,
    visible: true,
    title: "Plant",
    style: new ol.style.Style({
        image: circleStyle
    })
});

map.addLayer(vectorLayer);

我使用 ol.style.Icon 而不是 Vector 解决了这个问题!如果你有这个问题,看看这个:https://openlayers.org/en/latest/examples/icon.html