Mapbox GL JS-setData

Mapbox GL JS-setData,mapbox,mapbox-gl-js,Mapbox,Mapbox Gl Js,我正在使用setData URL来提高MapBox的性能: (source as GeoJSONSource).setData('http://localhost:8888/api/tracking/all'); 但是,API没有发送MapBox可以直接读取的GeoJson。因此,为了避免更新后端部分,我想在前端做一些转换 但是我找不到办法,你知道吗 我试过这个,但不起作用: (source as GeoJSONSource).setData('http://localhost:8888/ap

我正在使用setData URL来提高MapBox的性能:

(source as GeoJSONSource).setData('http://localhost:8888/api/tracking/all');
但是,API没有发送MapBox可以直接读取的GeoJson。因此,为了避免更新后端部分,我想在前端做一些转换

但是我找不到办法,你知道吗

我试过这个,但不起作用:

(source as GeoJSONSource).setData('http://localhost:8888/api/tracking/all').map(this.aisDataService.transformBackend)
提前感谢你的帮助

Damien

由于该方法需要一个正确的geo-json作为对象或一个带有正确geo-json的URL行,因此您需要:

1) 获取远程json 2) 将其转换为geo-json 3) 设置数据

例如:


[]

如何使用图层id使用setDate?
  axios
    .get(remoteDataURL)
    .then(function(res) {
      var geojson = {
        "type": "FeatureCollection",
        "features": res.data.map(transformBackend)
      }
      map.getSource('data').setData(geojson)
    })