ol-cesium
ol-cesium copied to clipboard
ol.source.vector's loader function is not getting triggered. Can you tell when it doesn't get trigger?
_createLayer:function(){ var strategy = ol.loadingstrategy.all; this.source = new ol.source.Vector({ format : new ol.format.GeoJSON(), loader : jQuery.proxy(this.loadFeatures,this), strategy : strategy }); this.setGISLayer(new ol.layer.Vector({ title : this.getLayerId(), source : this.source, style : jQuery.proxy(this.styleFunction, this) })); },
Such after adding the layer to the map, loadfeatures is not getting called. Hence it is getting called only when both map objects(open layers and ol-cesium) having the same target (such that same
What do you mean by:
Hence it is getting called only when both map objects(open layers and ol-cesium) having the same target (such that same element) else if one of them not having target loader will not get triggered.
Sorry for the incomprehensible explanation. What I meant that I created two objects, one of map through open layers and other of ol-cesium and a vector layer. var vectorSource = new ol.source.Vector({ format : new ol.format.GeoJSON(), loader : jQuery.proxy(this.loadFeatures,this) }); const vectorLayer = new ol.layer.Vector({ style: styleFunction, source : vectorSource }); this._map = new ol.Map({ layers : [this.getBaseMapLayer(baseMap),vectorLayer], target: 'mapDiv', controls : ol.control.defaults({ attributionOptions : /** @type {olx.control.AttributionOptions} */( { collapsible : true }), zoom : false }), view : this.olView }); this._map3d = new olcs.OLCesium({ map: this._map, // target: 'mapDiv' }); Here If I don't mention target in both the objects, loader specified in ol.source.vector will not get triggered. Such that if I specify target only in ol.Map not in olcs.OLCesium ,such that map is loaded but the loader of ol.source.vector is not getting called. I tried doing the same way as explained in the Old-fashioned example.
Thanks Gaurav
OK, I understand now. OL-Cesium has two modes:
- stacked mode: either OpenLayers or Cesium is displayed (no target used for OL-Cesium);
- side-by-side mode: moth OpenLayers and Cesium are displayed at the same time (a target is used for OL-Cesium).
In side-by-side mode OpenLayers is fully active so it will fetch the source data. In stacked mode OpenLayers is partially active: it will not fetch new data and thus they will not be converted to Cesium.
I see 2 solutions: 1- implement fetching of vector source data in OL-Cesium based on the area displayed in Cesium (most complicate); 2- load the data in the vector source yourself (easy).
With 2 you should get the features and add them to the source:
vectorSource.setFeatures(theFeaturesYouLoadedManually);
I think I am following side-by-side mode in the above example. If the target is specified only for OL-Cesium but not for ol.Map, the loadFeatures callback method is not getting triggered, such that as soon as the layer is added on the map I want to query the features and add to the source, this dynamic behavior can be observed if the loader get executed. Thanks for your explanation! Gaurav.