Drawing a circle with the radius in miles/meters with Mapbox GL JS

后端 未结 4 1611
自闭症患者
自闭症患者 2020-12-08 00:15

I\'m in the process of converting a map from using mapbox.js to mapbox-gl.js, and am having trouble drawing a circle that uses miles or met

4条回答
  •  醉酒成梦
    2020-12-08 00:59

    Lucas and fphilipe answers works perfectly ! For those working with react-native-mapbox and drawing over the map you must take into account the pixel density of the screen as follow :

      pixelValue(latitude: number, meters: number, zoomLevel: number) {
        const mapPixels = meters / (78271.484 / 2 ** zoomLevel) / Math.cos((latitude * Math.PI) / 180);
        const screenPixel = mapPixels * Math.floor(PixelRatio.get());
        return screenPixel;
      }
    

提交回复
热议问题