* @function Bounds.prototype.containsLonLat * @description 判断传入的坐标是否在范围内。 * @example * var bounds1 = new Bounds(-50,-50,40,40); * //isContains1 = true * //这里的第二个参数可以直接为 boolean 类型,也就是inclusive * var isContains1 = bounds.containsLonLat(new LonLat(40,40),true); *
(ll, options)
| 379 | * @returns {boolean} 传入坐标是否包含在范围内。 |
| 380 | */ |
| 381 | containsLonLat(ll, options) { |
| 382 | if (typeof options === "boolean") { |
| 383 | options = {inclusive: options}; |
| 384 | } |
| 385 | options = options || {}; |
| 386 | var contains = this.contains(ll.lon, ll.lat, options.inclusive), |
| 387 | worldBounds = options.worldBounds; |
| 388 | //日界线以外的也有可能算包含, |
| 389 | if (worldBounds && !contains) { |
| 390 | var worldWidth = worldBounds.getWidth(); |
| 391 | var worldCenterX = (worldBounds.left + worldBounds.right) / 2; |
| 392 | //这一步很关键 |
| 393 | var worldsAway = Math.round((ll.lon - worldCenterX) / worldWidth); |
| 394 | contains = this.containsLonLat({ |
| 395 | lon: ll.lon - worldsAway * worldWidth, |
| 396 | lat: ll.lat |
| 397 | }, {inclusive: options.inclusive}); |
| 398 | } |
| 399 | return contains; |
| 400 | } |
| 401 | |
| 402 | /** |
| 403 | * @function Bounds.prototype.containsPixel |
no test coverage detected