检查标记坐标是否在范围内 [英] Checking if marker coordinates are in bounds

查看:70
本文介绍了检查标记坐标是否在范围内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Angular 6应用程序中使用传单地图.我以

I'm using leaflet map in Angular 6 application. I get location info for each item as

[lat:xx,lng:xx]

我还获得了bounds对象,该对象描述了当前可见的地图区域.它随拖动和缩放而变化.bounds对象看起来像这样:

I also get the bounds object which describes what area of map is currently visible. It changes with dragging and zooming. The bounds object looks like this:

_northEast
    lat: 76.16399261609192
    lng: 111.00585937500001
_southWest
    lat: 18.646245142670608
    lng: -43.76953125

我知道我可以比较每个项目 lat 是否大于 southWest.lat 和小于 northEast.lat ,并与em> lng ,但是有什么更简单,更优雅的方法来适应它吗?

I know I could just compare each item lat whether it's bigger than southWest.lat and smaller than northEast.lat and same with lng, but is there any easier and more elegant way to fit it in the bounds?

是的,我在询问之前仔细阅读了传单文档:)

And yes, I looked through the leaflet docs before asking this :)

推荐答案

您需要 LatLngBounds.contains(LatLng)

https://leafletjs.com/reference-1.3.4.html#latlngbounds-contains

这篇关于检查标记坐标是否在范围内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆