百度地图的API虽说覆盖物多了能够用聚合,但聚合使用下来,性能并很差html
目前解决方案是,获取地图的左下角和右上角的经纬度,而后根据此经纬度范围,到数据库中搜索,把该区域内的覆盖物取出标注到地图上。git
生成地图时绑定事件,在移动和缩放时触发:ajax
- map.addEventListener("moveend", queryInRect);
-
- map.addEventListener("zoomend", queryInRect);
- function queryInRect (event) {
-
-
- var cp = map.getBounds();
- var sw = cp.getSouthWest();
- var ne = cp.getNorthEast();
-
- zoom = map.getZoom();
-
- if (zoom < defaultShowLampZoom) {
-
-
- var markers = getCurrentMarkers();
- for (var i=0; i<markers.length; i++) {
- map.removeOverlay(markers[i]);
- }
- return;
- }
-
-
- var param = {
- swlng : sw.lng,
- swlat : sw.lat,
- nelng : ne.lng,
- nelat : ne.lat
- };
- $.ajax( {
- type : "POST",
- url : "queryInRect.action",
- data : param,
- dataType : "json",
- success : function(jsonData) {
-
- if (jsonData.rtnMsg) {
- alert(jsonData.rtnMsg);
-
- return;
- }
- if (jsonData.controllerList) {
-
-
- var markers = getCurrentMarkers();
- for (var i=0; i<markers.length; i++) {
- map.removeOverlay(markers[i]);
- }
-
- $.each(jsonData.controllerList, function(i, controller) {
- var point = new BMap.Point(controller.longitude, controller.latitude);
- addMarker(point, controller, markers);
-
-
- insertOrUpdateDataCollection(controller);
-
- insertOrUpdateAlarm(controller);
-
- });
-
-
- if (find) {
- setTimeout(jumpIcon, 800);
- }
- }
- },
- error : function(XMLHttpRequest, textStatus, errorThrown) {
-
-
-
- alert('服务器异常');
- }
- });
- }