Cesium中加载geojson数据,根据数据中的属性做等级展示

cesium加载GeoJson数据,并做等级显示

效果
Cesium中加载geojson数据,根据数据中的属性做等级展示_第1张图片

const promise = viewer.dataSources.add(Cesium.GeoJsonDataSource.load(urlChina));//默认是黄色
promise.then(function (dataSource) {
    _this.jsonDatas[keydataSource] = dataSource;
    const entities = dataSource.entities.values;
    if (entities[0]._polygon) {
        (_this.jsonDataArray).concat(entities);
    }
    const colorHash = {};
    const operation = {
        showColor: function () { //显示颜色
            for (let i = 0; i < entities.length; i++) {
                const entity = entities[i];
                entity.properties = {...urlChina.features[i]};  // 将每条数据的属性添加到模型的属性的properties中
                let szxz = (entity.properties._szxx2019._value).trim(); //水资源等级
                let featureType = entity.properties._geometry._value.type;
                let color = colorHash[szxz];
                if (!color) {
                    if (szxz == '1') {
                        color = new Cesium.Color(76 / 255, 230 / 255, 0, 1);  // #4ce600
                    } else if (szxz == '2') {
                        color = new Cesium.Color(56 / 255, 168 / 255, 0, 1);  //#38a800
                    } else if (szxz == '3') {
                        color = new Cesium.Color(168 / 255, 168 / 255, 0, 1);  // #a8a800
                    } else if (szxz == "4") {
                        color = new Cesium.Color(230 / 255, 152 / 255, 0, 1);  // #e69800
                    } else if (szxz == "5") {
                        color = new Cesium.Color(255 / 255, 255 / 255, 0, 1);  // #ffff00
                    } else if (szxz == "6") {
                        color = new Cesium.Color(168 / 255, 0, 0, 1);  // #a80000
                    } else {
                        color = new Cesium.Color(130 / 255, 130 / 255, 130 / 255, 1);  // #828282
                    }

                    colorHash[szxz] = color;
                }
// 判断加载的空间数据点线面类型   赋值颜色
                if (featureType == "MultiPolygon") {
                    entity.polygon.material = color;
                } else if (featureType == "MultiLineString") {
                    entity.polyline.material = color;
                    entity.polyline.width = _this.initPolylineWidth;
                } else if (featureType == "MultiPoint") {
                    entity.point.material = color;
                }
                entity.beOf = "水环境";
            }
        }
    };

    operation.showColor();

你可能感兴趣的:(WebGIS)