2017-10-14 90 views
0

我有一個geosjon來源:如何顯示在3D銫和olcesium多邊形

"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表面。

回答

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-銫的工作將是很好