cesium加载geojson

1. 数据加载

 showRegionExtent: function (feature) {
        var that = this; 
        var dataSource = Cesium.GeoJsonDataSource.load(feature, {
            clampToGround: true,
            stroke: new Cesium.Color.fromCssColorString("#ffffff"),
            strokeWidth: 2,
            fill: new Cesium.Color.fromCssColorString("#ffff00").withAlpha(0.5)
        });
        dataSource.then(function (dataSource) {
            that.viewer.dataSources.add(dataSource);
            that.last_region = dataSource;

            that.viewer.flyTo(dataSource.entities.values, { duration: 2 });
        }).otherwise(function (error) {
            toastr.error(error);
        });
   
    },

2. 数据删除

//显示行政区划边界
    last_region: null,
    clearLastRegion: function () {
        if (this.last_region != null) {
            this.viewer.dataSources.remove(this.last_region);
            this.last_region = null;
        }
        if (this.last_timetemp != -1) {
            clearTimeout(this.last_timetemp);
            this.last_timetemp = -1;
        }
    },

你可能感兴趣的:(cesium加载geojson)