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

Dynamically update layer source #536

Open
samuel-girard opened this issue Dec 13, 2017 · 5 comments
Open

Dynamically update layer source #536

samuel-girard opened this issue Dec 13, 2017 · 5 comments

Comments

@samuel-girard
Copy link
Contributor

samuel-girard commented Dec 13, 2017

Hello,

When I add a new image layer to the map, and create the source afterwards, the new source is not displayed on the globe (but it is on OpenLayers map).
Here is the code I use:

const view = new ol.View({
  center: ol.proj.transform([-112.2, 36.06], 'EPSG:4326', 'EPSG:3857'),
  zoom: 11
});

const layer = new ol.layer.Tile({
  source: undefined
});
// Add the source later:
setTimeout(function() {
  layer.setSource(new ol.source.OSM());
});
// Create the map
const ol2d = new ol.Map({
  layers: [layer],
  target: 'map2d',
  view,
  renderer: 'webgl'
});
// Enable 3d view
const ol3d = new olcs.OLCesium({map: ol2d, target: 'map3d'});
ol3d.setEnabled(true);

Is there a way to tell ol-cesium that my layer was updated?

Thanks

@samuel-girard
Copy link
Contributor Author

I did a jsfiddle to clearly explain the problem: https://jsfiddle.net/0nkc0kwd/4/
When the layer source is set with layer.setSource() after adding the layer to the map, it is updated on OL map but not on Cesium globe.

I can see that the function is defined in olcesium:

/**
 * Set the layer source.
 * @param {ol.source.Source} source The layer source.
 * @observable
 * @api
 */
ol.layer.Layer.prototype.setSource = function(source) {
  this.set(ol.layer.Property.SOURCE, source);
};

My guess is that the layer is not updated on Cesium side. Maybe there should be some more code here to synchronize the layer in Cesium.
Any idea on where to dig?

@gberaudo
Copy link
Member

Hello @samuel-girard, have you checked OL-Cesium registers a listener on 'change:source' on the layer? There may be missing cases. If it exists, you should check it is called.

@samuel-girard
Copy link
Contributor Author

Hello @gberaudo
I created #540 to solve this problem.
It will only solve the problem when the image layer is added as a root on the map (I mean not in a LayerGroup), which I need to investigate more.

The problem here is that if I add a layer with a source that is left uninitialized, and that I initialize the source later, this layer is skipped from Cesium because it was failed to be added in the first case.
The solution I bring is to check each time the layer is updated if it is valid to be added in Cesium.

@vsile
Copy link

vsile commented Aug 2, 2018

@samuel-girard, what file "olcesium.js" do you use?
Could you share a link?

@samuel-girard
Copy link
Contributor Author

Hi @vsile
The fix #540 has been merged, so it is included in any ol-cesium version since v1.36.

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

3 participants