最新公告
  • 欢迎您光临起源地模板网,本站秉承服务宗旨 履行“站长”责任,销售只是起点 服务永无止境!立即加入钻石VIP
  • mapbox.gl一些常用工具函数

    正文概述 掘金(用户9890038327737)   2021-04-01   790

    // 计算polygon的bounds /* map:地图实例对象 */

      fitPolygonBoundingBox(mapbox, coordinates) {
        // bounds [xMin, yMin][xMax, yMax]
        const bounds = [[], []];
        let polygon;
        let latitude;
        let longitude;
        // tslint:disable-next-line:prefer-for-of
        for (let i = 0; i < coordinates.length; i++) {
            if (coordinates.length === 1) {
                // Polygon coordinates[0][nodes]
                polygon = coordinates[0];
            } else {
                // Polygon coordinates[poly][0][nodes]
                polygon = coordinates[i][0];
            }
            // tslint:disable-next-line:prefer-for-of
            for (let j = 0; j < polygon.length; j++) {
                longitude = polygon[j][0];
                latitude = polygon[j][1];
            bounds[0][0] = bounds[0][0] < longitude ? bounds[0][0] : longitude;
            bounds[1][0] = bounds[1][0] > longitude ? bounds[1][0] : longitude;
            bounds[0][1] = bounds[0][1] < latitude ? bounds[0][1] : latitude;
            bounds[1][1] = bounds[1][1] > latitude ? bounds[1][1] : latitude;
        }
    }
    

    // console.log(bounds); mapbox.fitBounds(bounds, { padding: 200 }); }

    /// multepoly的bounds计算定位 /* map:地图实例对象 */

     getBoundingBox(data, map) {
      let bounds = {};
      let coords;
      let point;
      let latitude;
      let longitude;
       // We want to use the “features” key of the FeatureCollection (see above)
      data = data.features;
       // Loop through each “feature”
      // tslint:disable-next-line:prefer-for-of
      for (let i = 0; i < data.length; i++) {
         // Pull out the coordinates of this feature
         coords = data[i].geometry.coordinates[0];
         // For each individual coordinate in this feature's coordinates…
         // tslint:disable-next-line:prefer-for-of
         for (let j = 0; j < coords.length; j++) {
           point = coords[j];
           // tslint:disable-next-line:prefer-for-of
           for (let a = 0; a < point.length; a++){
             longitude = point[a][0];
             latitude = point[a][1];
           // Update the bounds recursively by comparing the current
           // xMin/xMax and yMin/yMax with the coordinate
           // we're currently checking
             bounds['xMin'] = bounds['xMin'] < longitude ? bounds['xMin'] : longitude;
             bounds['xMax'] = bounds['xMax'] > longitude ? bounds['xMax'] : longitude;
             bounds['yMin'] = bounds['yMin'] < latitude ? bounds['yMin'] : latitude;
             bounds['yMax'] = bounds['yMax'] > latitude ? bounds['yMax'] : latitude;
           }
         }
       }
       // Returns an object that contains the bounds of this GeoJSON
       // data. The keys of this object describe a box formed by the
       // northwest (xMin, yMin) and southeast (xMax, yMax) coordinates.
     // console.log(bounds);
      map.fitBounds([[bounds['xMin'], bounds['yMin']], [bounds['xMax'], bounds['yMax']]], 200);
     // return bounds;
     }
    

    // line bounds 计算定位

    /* map:地图实例对象 */

      fitLineBounds(map, coordinates){
        const bounds = coordinates.reduce( (bound, coord) => {
          return bound.extend(coord);
        },
        new mapboxgl.LngLatBounds(coordinates[0], coordinates[0]));
        console.log(bounds);
        map.fitBounds(bounds, {
          padding: 20
        });
      }
    

    // 得到鼠标点击时的屏幕坐标

    /* map:地图实例对象 */

      mousePos(map, e) {
        const canvas = map.getCanvasContainer();
        const rect = canvas.getBoundingClientRect();
        return new mapboxgl.Point(
        e.clientX - rect.left - canvas.clientLeft,
        e.clientY - rect.top - canvas.clientTop
        );
      }
    

    起源地下载网 » mapbox.gl一些常用工具函数

    常见问题FAQ

    免费下载或者VIP会员专享资源能否直接商用?
    本站所有资源版权均属于原作者所有,这里所提供资源均只能用于参考学习用,请勿直接商用。若由于商用引起版权纠纷,一切责任均由使用者承担。更多说明请参考 VIP介绍。
    提示下载完但解压或打开不了?
    最常见的情况是下载不完整: 可对比下载完压缩包的与网盘上的容量,若小于网盘提示的容量则是这个原因。这是浏览器下载的bug,建议用百度网盘软件或迅雷下载。若排除这种情况,可在对应资源底部留言,或 联络我们.。
    找不到素材资源介绍文章里的示例图片?
    对于PPT,KEY,Mockups,APP,网页模版等类型的素材,文章内用于介绍的图片通常并不包含在对应可供下载素材包内。这些相关商业图片需另外购买,且本站不负责(也没有办法)找到出处。 同样地一些字体文件也是这种情况,但部分素材会在素材包内有一份字体下载链接清单。
    模板不会安装或需要功能定制以及二次开发?
    请QQ联系我们

    发表评论

    还没有评论,快来抢沙发吧!

    如需帝国cms功能定制以及二次开发请联系我们

    联系作者

    请选择支付方式

    ×
    迅虎支付宝
    迅虎微信
    支付宝当面付
    余额支付
    ×
    微信扫码支付 0 元