openlayers / ol-cesium

OpenLayers - Cesium integration
http://openlayers.org/ol-cesium/
BSD 2-Clause "Simplified" License
968 stars 321 forks source link

Problems when using a KML/vector layer in 3D mode #346

Open jmgomezpoveda opened 8 years ago

jmgomezpoveda commented 8 years ago

Using a Vector/KML layer in OpenLayers 3, with a Cluster. When using ol3-cesium in 3D mode this is somewhat working, but I have observed the following issues:

jmgomezpoveda commented 8 years ago

From https://github.com/openlayers/ol3-cesium/issues/344#issuecomment-208307019:

gberaudo commented 19 minutes ago

The 2D OL3 interactions are not made available in 3D.

OL3 ol.source.Cluster source is not adapted to the tilted views or 3D. You may try to trigger change events on the cluster source to force redraws or have a look to https://github.com/gberaudo/ol3-cluster-tool.

jmgomezpoveda commented 8 years ago

I have tried to have the layer redrawn, but have been unsuccessful so far.

map3d.getCamera().updateView();
map3d.getOlMap().changed();
map3d.getOlMap().render();
map3d.getOlMap().renderSync();
map3d.getOlMap().updateSize();
map3d.getOlMap().getLayers().forEach(function (l) { l.changed(); }, this);

None of the above do update the cluster or make the kml layer appear (if enabled while in 3D). The only workaround I have found so far is to disable the 3D map and re-enable it, but that causes a noticeable flicker:

map3d.setEnabled(false);
setTimeout(function() { map3d.setEnabled(true); }, 0);
gberaudo commented 8 years ago

Have you tried to trigger the change event on the source?

jmgomezpoveda commented 8 years ago

Thanks for the suggestion. I have just tried the following:

kmlLayer.values_.source.changed();
kmlLayer.values_.source.source_.changed();

But there is no update on the Vector layer.

wintersieck commented 7 years ago

Far from a full solution, but to help troubleshoot, both of these issues are solved if you comment out some code in setEnabled like so:

olcs.OLCesium.prototype.setEnabled = function(enable) {
  if (this.enabled_ === enable) {
    return;
  }
  this.enabled_ = enable;

  // some Cesium operations are operating with canvas.clientWidth,
  // so we can't remove it from DOM or even make display:none;
  this.container_.style.visibility = this.enabled_ ? 'visible' : 'hidden';
  var interactions;
  if (this.enabled_) {
    this.throwOnUnitializedMap_();
    if (this.isOverMap_) {
      interactions = this.map_.getInteractions();
      interactions.forEach(function(el, i, arr) {
        this.pausedInteractions_.push(el);
      }, this);
      interactions.clear();

      // var rootGroup = this.map_.getLayerGroup();
      // if (rootGroup.getVisible()) {
      //   this.hiddenRootGroup_ = rootGroup;
      //   this.hiddenRootGroup_.setVisible(false);
      // }
    }
    this.camera_.readFromView();
    this.render_();
  } else {
    if (this.isOverMap_) {
      interactions = this.map_.getInteractions();
      this.pausedInteractions_.forEach(function(interaction) {
        interactions.push(interaction);
      });
      this.pausedInteractions_.length = 0;

      // if (!goog.isNull(this.hiddenRootGroup_)) {
      //   this.hiddenRootGroup_.setVisible(true);
      //   this.hiddenRootGroup_ = null;
      // }
    }

    this.camera_.updateView();
  }
};
bkuster commented 6 years ago

I did some digging into the use of ol.source.Cluster. I did find the reason for the source not updating, when the camera position changes. The cluster source uses the resolution to determine the mapDistance for which to cluster features. Once you switch into 3D mode, the resolution no longer gets updated on the 2D maps view. If the resolutions stays the same, the cluster source will not re-cluster.

I found a work-around which did deliver somewhat satisfactory results. By using the cameras position and the frustum to calculate the pixel dimension using the cameras height. With the pixels dimensions in meters, I reset the resolution on the 2D map. This forces the cluster to be re-rendered.

Potentially, such a fix could also solve the problem of not being able to initialize the cluster source in 3D, but I did not investigate this.

What I did experience, was a drastic drop in performance. Since every change to the altitude forces the entire cluster source to re-evaluate its features, thus clearing all the features first and then adding them again. So I am now trying to solve the issue via the use of Cesiums own clustering capabilities.

gberaudo commented 6 years ago

Thanks @bkuster for your feedback.