arcgis for js 3.x 添加格点值

arcgis for js 3.x 添加格点值

1、地图缩放级别所需要的参数’

var lods = [
		{"level" : 0, "resolution" : 0.0409782872197041, "scale" : 17221668.21968845},
		{"level" : 1, "resolution" : 0.0341349132540135, "scale" : 14345649.62700048},
		{"level" : 2, "resolution" : 0.0284343827405933, "scale" : 11949926.1392914},
		{"level" : 3, "resolution" : 0.0236858408229142, "scale" : 9954288.474029739},
		{"level" : 4, "resolution" : 0.0197303054054875, "scale" : 8291922.298866772},
		{"level" : 5, "resolution" : 0.0164353444027711, "scale" : 6907171.274956021},
		{"level" : 6, "resolution" : 0.0136906418875083, "scale" : 5753673.672038366},
		{"level" : 7, "resolution" : 0.0114043046922944, "scale" : 4792810.168807959},
		{"level" : 8, "resolution" : 0.0094997858086813, "scale" : 3992410.87061703},
		{"level" : 9, "resolution" : 0.0079133215786315, "scale" : 3325678.255223986},
		{"level" : 10, "resolution" : 0.006591796875, "scale" : 2770289.98660158},
		{"level" : 11, "resolution" : 0.0054931640625, "scale" : 2308574.98883465},
		{"level" : 12, "resolution" : 0.00457763671875, "scale" : 1923812.490695542},
		{"level" : 13, "resolution" : 0.003814697265625, "scale" : 1603177.075579618},
		{"level" : 14, "resolution" : 0.0031789143880208, "scale" : 1335980.896316348},
		{"level" : 15, "resolution" : 0.0026490953233507,"scale" : 1113317.413596957},
		{"level" : 16, "resolution" : 0.0022075794361256,"scale" : 927764.5113307975},
		{"level" : 17, "resolution" : 0.0018396495301047,"scale" : 773137.0927756646},
		{"level" : 18, "resolution" : 0.0015330412750872,"scale" : 644280.9106463872},
		{"level" : 19, "resolution" : 0.001277534395906,"scale" : 536900.7588719893},
		{"level" : 20, "resolution" :0.0010646119965883,"scale" : 447417.2990599911},
		{"level" : 21, "resolution" :0.000887141176757,"scale" : 372832.8353066906},
		{"level" : 22, "resolution" :0.000739254742592,"scale" : 310681.6016610653},
		{"level" : 23, "resolution" :0.000616020977002,"scale" : 258890.9786641657},
		{"level" : 24, "resolution" :0.0005133302801358,"scale" : 215733.8525208493},
		{"level" : 25, "resolution" :0.0004277581224372,"scale" : 179771.0193056237},
		{"level" : 26, "resolution" :0.0003564508434269,"scale" : 149803.1903873762},
		{"level" : 27, "resolution" :0.0002970304878276,"scale" : 124786.0575926844},
		{"level" : 28, "resolution" :0.0002475155055067,"scale" : 103984.2217919839},
		{"level" : 29, "resolution" :0.0002062546707387,"scale" : 86650.05201926019},
		{"level" : 30, "resolution" :0.0001718720171266,"scale" : 72205.48834764952}
	];
	
	map = new esri.Map(map, {
		slider: false, //隐藏放大缩小按钮
		lods:lods, //地图上将lods添加
	
		extent: extent
	});

2、监听地图缩放事件

 map.on("zoom-end", function(evt){
        addPartDatasToMap(gdz_points);    //gdz_points添加的点数据(后端接收)
    });

3、添加格点值方法

// 想地图添加格点值方法
let gdzLayer = "";
function addPartDatasToMap(points) {
    if (gdzLayer) {
        map.removeLayer(gdzLayer);
    }
    //格点
    if (points.length > 0) {
        var level = map.getLevel();
        if(level == -1){
            level = 6;
		}
        if (level >=0 && level < 2) {
            num = 35;
        } else if (level >=2 && level < 4) {
            num = 30;
        } else if (level >= 4 && level < 6) {
            num = 25;
        } else if (level >= 6 && level < 8) {
            num = 20;
        } else if (level >= 8 && level < 10) {
            num = 15;
        } else if (level >= 10 && level < 13) {
            num = 10;
        } else if (level >= 13 && level < 16) {
            num = 5;
        } else if (level >= 16 && level < 19) {
            num = 3;
        }
        else if (level >= 19 && level < 23) {
            num = 2;
        }
        else {
            num = 1;
        }

        // create a text symbol 文字太多了把数据间隔设置一下吧i+=50
        gdzLayer = new esri.layers.GraphicsLayer({
            id: "gdz_num_0"
        });

        function addGdData(info) {
            var point = new esri.geometry.Point({
                "x": info.longitude,
                "y": info.latitude
            });
            var textSymbol = new esri.symbol.TextSymbol({
                xoffset: info.xoffset,
                yoffset: info.yoffset,
                text: info.text,
                font: {
                    size: info.size,
                    family: "微软雅黑"
                }
            });
            textSymbol.setColor(new esri.Color(info.color));
            var textGraphic = new esri.Graphic(point, textSymbol);
            gdzLayer.add(textGraphic);
            map.addLayer(gdzLayer); // 添加到地图中
        }

        var xmin = map.extent.xmin;
        var ymin = map.extent.ymin;
        var xmax = map.extent.xmax;
        var ymax = map.extent.ymax;

        var lat = "";
        var t = -1; // 定义一个经度计数器,表示该纬度上点的个数....
        var n = 0; // 定义一个纬度计数器,表示纬度上的点的个数
        for (var i = 0; i < points.length; i++) {
            if (points[i].lat != lat) {
                lat = points[i].lat;
                t++;
                n = 0;
                if (t % num == 0) {
                    // 仅加载屏幕部分
                    if (points[i].lon >= xmin && points[i].lon <= xmax && points[i].lat >= ymin && points[i].lat <= ymax) {
                        var info = new Object();
                        info.size = 12;
                        info.color = "#16ea06";
                        info.yoffset = 0;
                        info.xoffset = 0;
                        info.longitude = points[i].lon;
                        info.latitude = points[i].lat;
                        //info.text = mapdata[i].val+"("+mapdata[i].lon+","+mapdata[i].lat+")";
                        info.text = points[i].value.toFixed(1);
                        addGdData(info);
                        //MapFun.buildGraphicByTextSymbol(info, graphicsLayer);
                    }
                }
                n++;
            } else {
                if (n % num == 0 && t % num == 0) {
                    // 仅加载屏幕部分
                    if (points[i].lon >= xmin && points[i].lon <= xmax && points[i].lat >= ymin && points[i].lat <= ymax) {
                        var info = new Object();
                        info.size = 12;
                        info.color = "#16ea06";
                        info.yoffset = 0;
                        info.xoffset = 0;
                        info.longitude = points[i].lon;
                        info.latitude = points[i].lat;
                        //info.text = mapdata[i].val+"("+mapdata[i].lon+","+mapdata[i].lat+")";
                        info.text = points[i].value.toFixed(1);
                        addGdData(info);
                        //MapFun.buildGraphicByTextSymbol(info, graphicsLayer);
                    }
                }
                n++;
            }
        }
    }

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

qq_42208679

生命不息,写作不止,求打赏!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值