欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 文旅 > 明星 > vue + 百度地图GL版判断一个点位是否在地图可视区内

vue + 百度地图GL版判断一个点位是否在地图可视区内

2024/10/25 3:31:10 来源:https://blog.csdn.net/m0_74149462/article/details/142923918  浏览:    关键词:vue + 百度地图GL版判断一个点位是否在地图可视区内

利用BMapGLLib中isPointInRect

因为没有找到官方文档因此直接下载了该工具的源码,复制以下部分到自己的项目中,避免再次引用完整的BMapGLLib脚本

 关键方法

    isPointInRect(point, bounds) {if (!(point.toString() === "Point" || point.toString() === "LatLng") ||!(bounds instanceof BMapGL.Bounds)) {return false;}var sw = bounds.getSouthWest(); // 西南脚点var ne = bounds.getNorthEast(); // 东北脚点return (point.lng >= sw.lng &&point.lng <= ne.lng &&point.lat >= sw.lat &&point.lat <= ne.lat);},

使用

   isPointInViewport(params = {}) {const {sw, ne, point} = params;const swGL = new BMapGL.Point(sw.lng, sw.lat);const neGL = new BMapGL.Point(ne.lng, ne.lat);const pointGL = new BMapGL.Point(point.lng, point.lat);if (this.isPointInRect(pointGL, new BMapGL.Bounds(swGL, neGL))) {console.log("在区域内");return true} else {console.log("不再区域内");return false}},searchRadarInViewport(config) {// 参考:// this.bdMap = new BMapGL.Map("map-container"); // 创建Map实例// let bounds = this.bdMap.getBounds(); //获取地图可视区域console.log(config, "config"); // config 是从其他组件接收到的地图boundsthis.isPointInViewport({sw: config.WS,ne: config.EN,point: {lng: 111.75963626067835, lat: 41.57808734176302}})},

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com