百度地图动态添加数据及条件查询

2022-03-06 12:53:34 浏览数 (2)

效果图如下

代码:

代码语言:javascript复制
function initMapData(){
         
             var points = [];  // 添加海量点数据
             map.clearOverlays();
            // map1.clearOverlays();
             var year =document.getElementById("year").value;
             var provinceid =document.getElementById("sheng").value;
             var quota_1 =document.getElementById("quota_1").value;
             var quota_2 =document.getElementById("quota_2").value;
             var quota_3 =document.getElementById("quota_3").value;
             var quota_4 =document.getElementById("quota_4").value;
             
             var index = "";
             if(quota_1 != ""){index = quota_1};
             if(quota_2 != ""){index = quota_2};
             if(quota_3 != ""){index = quota_3};
             if(quota_4 != ""){index = quota_4};
             $.ajax({url:"./EnterpriseAnalysisFetcher.do?action=envmap",
                    type:"POST",dataType:"JSON",async:false,<br>            //传过去year,pronvinceid,index:指标  success到x,y的坐标
                    data:{"provinceid":provinceid,"year":year,"index":index},
                    success: function(datas){
                        $.each(datas,function(i,n){
                             if(n.lng!=null){<br>              //遍历查询到的值,put到points里面
                                points.push(new BMap.Point(parseFloat(n.lng), parseFloat(n.lat)));
                             }
                         });

public CompanyPosition[] getCompanyEnvData(int year, int provinceid,
            String index,DBSession session) throws JException {
         
        List<CompanyPosition> list = new ArrayList<CompanyPosition>();
        if (session == null) {
            session = Context.getDBSession();
 
        }
        IResultSet rs = null;
        try {
            Object[] paramObjects = new Object[]{};
            int[] paramTypes = new int[]{};
            String sql = "select b.cp_lng,cp_lat from env_pollutiondata a,env_company b where a.pd_company_ID=b.ID and " index ">0 ";
            if(year>0){
                sql = sql   " and a.pd_year =?";
            }
            if(provinceid>0){
                sql = sql   " and a.pd_Province_ID =?";
            }
            if(year>0&&provinceid>0){
                paramObjects = new Object[]{year,provinceid};
                paramTypes = new int[]{year,provinceid};
            }else if(year>0){
                paramObjects = new Object[]{year};
                paramTypes = new int[]{year};
            }else if(provinceid>0){
                paramObjects = new Object[]{provinceid};
                paramTypes = new int[]{provinceid};
            }
            sql = sql " GROUP BY a.pd_company_ID ";
            //sql = "SELECT * FROM env_pollutiondata WHERE ID = 1";
             
            //rs = session.executeQuery(sql, new Object[]{paramObjects}, new int[]{Types.DECIMAL});
            rs = session.executeQuery(sql, paramObjects, paramTypes);
            System.out.println(sql);
            while (rs.next()) {
 
                CompanyPosition position = new CompanyPosition();
                position.setLat(rs.getFloat("cp_lat"));
                position.setLng(rs.getFloat("cp_lng"));
                float po = rs.getFloat("cp_lat");
                float pl = rs.getFloat("cp_lng");
                list.add(position);
            }
        } catch (Exception e) {
            Logger.getProjLogger().error(e.getMessage(), e);
            return null;
        } finally {
            ResourceMgr.closeQuietly(rs);
            ResourceMgr.closeQuietly(session);
        }
        return list.toArray(new CompanyPosition[0]);
代码语言:javascript复制
	
var options = { size: BMAP_POINT_SIZE_BIGGER, shape: BMAP_POINT_SHAPE_WATERDROP, color: '#d340c3' } var pointCollection = new BMap.PointCollection(points, options);

0 人点赞