我必须通过“ openlayers”在应用程序上做一个项目。目的是在地图上看到对象(例如垃圾桶),如果您走路并看到该对象,请单击它,它会更改应用程序的颜色(例如,它从绿色变为红色)。 为此,我被要求使用“ openlayers”库,并且我的数据采用“ geojson”格式。
我遇到几个问题:
- 我无法读取数据
- 我不知道如何为点击该对象进行编码
你能帮我吗?
我的代码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数据:
{ “特征” : [ { “ type”:“功能”, “ geometry”:{ “ type”:“ Point”, “坐标”:[0.473698,50.848808] }, “属性”:{ “ ID_ELE”:1 “ ID_etaT”:1 } }, { “ type”:“功能”, “ geometry”:{ “ type”:“ Point”, “坐标”:[0.473665,450.848177] }, “属性”:{ “ ID_ELE”:2 “ ID_etaT”:1 } ] }