0

我必须通过“openlayers”在应用程序上做一个项目。目标是在地图上查看对象(例如垃圾),如果您走路并看到该对象,则单击它并在应用程序上更改颜色(例如,它从绿色变为红色)。为此,我被要求使用“openlayers”库,并且我的数据采用“geojson”格式。

我遇到几个问题:

  1. 我无法读取我的数据
  2. 我不知道如何为点击对象编写代码

你能帮我吗?

我的代码js:

var image = new CircleStyle({
 radius: 10,
 fill: new Fill({color: 'green'})
 });

var vectorPoints = new VectorLayer({
    id: 'paris',
    source: new VectorSource({
        url: '/data_v2.geojson',
        projection: 'EPSG:3857',
        format: new GeoJSON()
    }),
    style: new Style({
        image: image
    })
   });

   var view = new View({
center: [0,0],
zoom: 2
    });

    var map = new Map({

target: 'map',
layers: [
    new TileLayer({
        source: new OSM()
    }),
    vectorPoints
],
view: view
    });

我的geojson数据:

{“特征”:[{“类型”:“特征”,“几何”:{“类型”:“点”,“坐标”:[0.473698,50.848808]},“属性”:{“ID_ELE”:1, “ID_ETAT”:1 } },{“类型”:“特征”,“几何”:{“类型”:“点”,“坐标”:[0.473665,450.848177] },“属性”:{“ID_ELE”: 2,“ID_ETAT”:1 } ] }

4

0 回答 0