我有一个像这样的图块地图。我想知道纬度和经度值(41.850033,-87.6500523)位于哪个tileBounds内部?
正在获取每个图块的图块边界值。但我不知道如何检查纬度是否在特定tileBound值的范围内。如何找到?
这是我的代码的工作副本
http://jsfiddle.net/doktormolle/55Nke/
var div = ownerDocument.createElement('div');
div.innerHTML =
'<pre><strong>tile:\n['+tile.x+','+tile.y+']</strong>\
\nbounds:{\nsw:['+tileBounds.sw.lat+','+tileBounds.sw.lng+'],\
\nne:['+tileBounds.ne.lat+','+tileBounds.ne.lng+']\n}</pre>';
div.style.width = this.tileSize.width + 'px';
div.style.height = this.tileSize.height + 'px';
div.style.fontSize = '10';
div.style.borderStyle = 'solid';
div.style.borderWidth = '1px';
div.style.borderColor = '#AAAAAA';
if(lat === 41.850033 && lng === -87.6500523){ //if latitude and longitude value inside that tile bounds set color as red
div.style.backgroundColor='red';
}
return div;
};
如何在这里检查我的经度和纬度是否位于tileBounds.sw和tileBounds.ne中?
var setTileBackground =
this.mapDataPoints.some(function(el){
return (tileBounds.sw.lat <= el.latitude <= tileBounds.ne.lat && tileBounds.sw.lng <= el.longitude <= tileBounds.ne.lng)
}) // never returns true ...
我用这张支票解决了我的问题
var setTileBackground = this.mapDataPoints.some(function(el){
return (el.latitude > tileBounds.sw.lat && el.latitude < tileBounds.ne.lat && el.longitude > tileBounds.sw.lng &&
el.longitude < tileBounds.ne.lng)
});