如何用铯和olcesium在3d中显示多边形

时间:2017-10-14 09:27:51

标签: openlayers cesium

我有一个geosjon来源:

"geometry": {
            "type": "Polygon",
            "coordinates": [
                [
                    [
                        12.671038571165692,
                        55.64399279138965,
                        85.8672
                    ],
                    [
                        12.685366241531373,
                        55.63688636891217,
                        85.8672
                    ],
...

我试过以下

 var ol3d = new olcs.OLCesium({ map: this.map}); // map is the ol.Map instance
            var scene = ol3d.getCesiumScene();
            ol3d.setEnabled(true);
            let datasources = ol3d.getDataSources();
            console.log(datasources);
            let f = new ol.format.GeoJSON({ defaultDataProjection: "EPSG:4326", featureProjection: this.map.getView().getProjection() });
            for (let feature of this._limModel.visualizationSource.getFeatures()) {
                feature.set("altitudeMode","relativeToGround");
            }
            let geojson = JSON.parse(f.writeFeatures(this._limModel.visualizationSource.getFeatures()));

            var dataSource = Cesium.GeoJsonDataSource.load(geojson, { clampToGround:false}).then(
                function (dataSource) {
                    var p = dataSource.entities.values;
                    for (var i = 0; i < p.length; i++) {
                        p[i].polygon.perPositionHeight = true;  

                    }
                    datasources.add(dataSource);


                }
            );

但olcesium从我的ol地图转换的同步矢量图层和geojson数据源都绘制在椭圆/地面上,而不是上面显示的geojson源中z坐标的高度。

如何在3d中将多边形显示为曲面。

1 个答案:

答案 0 :(得分:0)

我能够使用以下代码制作原型。

            var dataSource = new Cesium.CustomDataSource('myData');

            function addPolygon(coordinates) {
                let flatten = [].concat.apply([], coordinates);
                console.log([flatten.length, flatten]);
                var orangePolygon = dataSource.entities.add({
                    name: 'Orange polygon with per-position heights and outline',
                    polygon: {
                        hierarchy: Cesium.Cartesian3.fromDegreesArrayHeights(
                            flatten),
                        extrudedHeight: 0,
                        perPositionHeight: true,
                        material: Cesium.Color.ORANGE.withAlpha(0.5),
                        outline: true,
                        outlineColor: Cesium.Color.BLACK
                    }
                });
            }
            for (let feature of this._limModel.visualizationSource.getFeatures()) {
                let coordinates : Array < Array<number>>;
                let geom = feature.getGeometry();
                if (geom instanceof ol.geom.Polygon) {

                    addPolygon(geom.getCoordinates()[0].map(c => ol.proj.toLonLat(c)));

                } else if (geom instanceof ol.geom.MultiPolygon) {


                    for (let poly of geom.getCoordinates()) {
                        addPolygon(poly[0].map(c => ol.proj.toLonLat(c)));
                    }
                }


            }
            datasources.add(dataSource);

但如果这只适用于ol-cesium

会很好