MCPcopy Index your code
hub / github.com/SuperMap/iClient-JavaScript / containsLonLat

Method containsLonLat

src/common/commontypes/Bounds.js:381–400  ·  view source on GitHub ↗

* @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)

Source from the content-addressed store, hash-verified

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

Callers 1

BoundsSpec.jsFile · 0.80

Calls 3

containsMethod · 0.95
roundMethod · 0.80
getWidthMethod · 0.45

Tested by

no test coverage detected