如何挤出高度的ol3-Cesium?

时间:2016-01-28 10:28:45

标签: openlayers-3 cesium

我有一个GeoJson,我可以在ol3中加载而没有任何问题。

 var layer = new ol.layer.Vector({
   source: new ol.source.Vector({
      format: new ol.format.GeoJson(),
      url: 'my_file.json',
   })
 });

我的GeoJson有一个属性(比方说foo)我想用extrudedHeight

我在Cesium中做过这个(参见Cesium例子):http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=GeoJSON%20and%20TopoJSON.html&label=Showcases

但是我找不到在ol3图层上执行此操作的方法。

有任何线索吗?

编辑:

我已经破解了一下并创建了我的FeatureConverter:

test = {};


function extend(base, sub) {
  // Avoid instantiating the base class just to setup inheritance
  // See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create
  // for a polyfill
  // Also, do a recursive merge of two prototypes, so we don't overwrite
  // the existing prototype, but still maintain the inheritance chain
  // Thanks to @ccnokes
  var origProto = sub.prototype;
  sub.prototype = Object.create(base.prototype);
  for (var key in origProto)  {
     sub.prototype[key] = origProto[key];
  }
  // Remember the constructor property was set wrong, let's fix it
  sub.prototype.constructor = sub;
  // In ECMAScript5+ (all modern browsers), you can make the constructor property
  // non-enumerable if you define it like this instead
  Object.defineProperty(sub.prototype, 'constructor', {
    enumerable: false,
    value: sub
  });
}



test.FeatureConverter = function(scene) {
  olcs.FeatureConverter.call(this, scene);
}

test.FeatureConverter.prototype = {
  olPolygonGeometryToCesium : function(layer, feature, olGeometry, projection, olStyle) {

    olGeometry = olcs.core.olGeometryCloneTo4326(olGeometry, projection);
    goog.asserts.assert(olGeometry.getType() == 'Polygon');

    var rings = olGeometry.getLinearRings();
    // always update Cesium externs before adding a property
    var hierarchy = {};
    var polygonHierarchy = hierarchy;
    goog.asserts.assert(rings.length > 0);

    for (var i = 0; i < rings.length; ++i) {
      var olPos = rings[i].getCoordinates();
      var positions = olcs.core.ol4326CoordinateArrayToCsCartesians(olPos);
      goog.asserts.assert(positions && positions.length > 0);
      if (i == 0) {
        hierarchy.positions = positions;
      } else {
        hierarchy.holes = {
          // always update Cesium externs before adding a property
          positions: positions
        };
        hierarchy = hierarchy.holes;
      }
    }

    var fillGeometry = new Cesium.PolygonGeometry({
      // always update Cesium externs before adding a property
      polygonHierarchy: polygonHierarchy,
      perPositionHeight: true,
      extrudedHeight: parseInt(feature.getProperties()['foo'])
    });

    var outlineGeometry = new Cesium.PolygonOutlineGeometry({
      // always update Cesium externs before adding a property
      polygonHierarchy: hierarchy,
      perPositionHeight: true
    });

    var primitives = this.wrapFillAndOutlineGeometries(
        layer, feature, olGeometry, fillGeometry, outlineGeometry, olStyle);

    return this.addTextStyle(layer, feature, olGeometry, olStyle, primitives);
  }
}

extend(olcs.FeatureConverter, test.FeatureConverter);

但它不起作用......(我不知道为什么......)。

0 个答案:

没有答案