我正在处理谷歌地图相关工作,想实现一个功能,用户可以使用鼠标画一个框/矩形选择地图上的某个区域(就像在Windows中选择多个文件一样)。选择后,我想获取所有在该区域内的标记。我搜索了谷歌地图API和其他资源,但未找到解决方案。我尝试使用jQuery Selectable进行选择,但它只返回一堆divs,无法确定是否选择了任何标记。
我正在处理谷歌地图相关工作,想实现一个功能,用户可以使用鼠标画一个框/矩形选择地图上的某个区域(就像在Windows中选择多个文件一样)。选择后,我想获取所有在该区域内的标记。我搜索了谷歌地图API和其他资源,但未找到解决方案。我尝试使用jQuery Selectable进行选择,但它只返回一堆divs,无法确定是否选择了任何标记。
var prj = null;
function DragZoom(map, opt_zoomOpts) {
var ov = new google.maps.OverlayView();
var me = this;
ov.onAdd = function () {
me.init_(map, opt_zoomOpts);
};
ov.draw = function () {
};
ov.onRemove = function () {
};
ov.setMap(map);
this.prjov_ = ov;
google.maps.event.addListener(map, 'idle', function () {
prj = ov.getProjection();
});
}
将DragZoom.prototype.onMouseUp_函数移至
DragZoom.prototype.onMouseUp_ = function (e) {
this.mouseDown_ = false;
if (this.dragging_) {
var left = Math.min(this.startPt_.x, this.endPt_.x);
var top = Math.min(this.startPt_.y, this.endPt_.y);
var width = Math.abs(this.startPt_.x - this.endPt_.x);
var height = Math.abs(this.startPt_.y - this.endPt_.y);
var points={
top: top,
left: left,
bottom: top + height,
right: left + width
};
var prj = this.prjov_.getProjection();
// 2009-05-29: since V3 does not have fromContainerPixel,
//needs find offset here
var containerPos = getElementPosition(this.map_.getDiv());
var mapPanePos = getElementPosition(this.prjov_.getPanes().mapPane);
left = left + (containerPos.left - mapPanePos.left);
top = top + (containerPos.top - mapPanePos.top);
var sw = prj.fromDivPixelToLatLng(new google.maps.Point(left, top + height));
var ne = prj.fromDivPixelToLatLng(new google.maps.Point(left + width, top));
var bnds = new google.maps.LatLngBounds(sw, ne);
//this.map_.fitBounds(bnds);
this.dragging_ = false;
this.boxDiv_.style.display = 'none';
/**
* This event is fired when the drag operation ends.
* Note that the event is not fired if the hot key is released before the drag operation ends.
* @name DragZoom#dragend
* @param {GLatLngBounds} newBounds
* @event
*/
google.maps.event.trigger(this, 'dragend', points);
}
};