Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jmgomezpoveda opened this issue Apr 11, 2016 · 7 comments
Open

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

jmgomezpoveda opened this issue Apr 11, 2016 · 7 comments

Comments

@jmgomezpoveda
Copy link
Contributor

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:

  • When using a clustered layer (with ol.source.Cluster), the cluster is not updated when the zoom level (altitude) changes).
  • The layer has to be created while the map is in 2D. Only then is it visible in 3D. If trying to enable the layer directly in 3D, the layer won't show until one goes to 2D and back to 3D. This may be linked to the issue of recalculating the clusters; maybe the layer is just not recalculated/redrawn.
@jmgomezpoveda
Copy link
Contributor Author

From #344 (comment):

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
Copy link
Contributor Author

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
Copy link
Member

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

@jmgomezpoveda
Copy link
Contributor Author

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
Copy link

wintersieck commented Feb 3, 2017

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
Copy link
Contributor

bkuster commented Jul 21, 2017

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
Copy link
Member

Thanks @bkuster for your feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants