Polygons are not rendered
jmgomezpoveda opened this issue · 15 comments
I have created a vector layer, which is visible in OpenLayers (2D mode). However, when I enable the 3D mode (Cesium), the polygons are not visible.
I am creating the vector layer as:
var geometry = new ol.geom.Polygon([
[ [10.689697265625, -25.0927734375], [34.595947265625, -20.1708984375], [38.814697265625, -35.6396484375],
[13.502197265625, -39.1552734375], [10.689697265625, -25.0927734375] ]
]);
geometry.transform('EPSG:4326', 'EPSG:3857');
var vectorLayer = new ol.layer.Vector({
map: this.map,
source: new ol.source.Vector({
features: [new ol.Feature({
geometry: geometry
})]
})
});
Are you using terrain?
No, I am not using terrain. In any case, I just tested it with a terrain, and the polygon is not rendered either.
Yyou are not setting any style so maybe this is the reason why nothing is showing up.
OpenLayers uses a default style when one is not defined. I.e. the above code does render a trapezoid.
In any case, I will set a style and test if that way it works in 3D mode. Thanks for the suggestion.
At the beginning of OL3-Cesium, it was not possible to retrieve the OL3 default style (OL3 internal).
It may be possible now; PR welcomed. See #353.
Unfortunately, I have just tested setting a style, but polygons are still not rendered.
Strange. Have you compared with what is done in the vectors example?
In fact, polygons are rendered fine in the vectors example. I will debug that one and update this ticket with any findings.
Ok, I have identified the cause. I am first creating the map, and then creating an unmanaged vector layer referencing the map. But the map does not reference the layer. Calling map.addLayer() makes the polygons to appear in the 3D map.
The reason I am doing it this way is that it seems easier to add and remove the layer when necessary.
I have reproduced the same in the vectors sample, just by removing the vectorLayers from the creation of the map object, and referencing the map object in the creation of vectorLayers instead (moving its declaration to after that of the map). Again, that is fixed if I call map.AddLayer().
Now, the question is, is this by design, and my code was not doing things right (it always should add the layer on the definition of the map or call map.addLayer(), even if it works in OpenLayers without it), or is this just a case that is not being handled by ol3-cesium at the moment?
It is a limitation/design decision of OpenLayers: unmanaged layers are considered internal and are not made discoverable. As a consequence there is no way for OL3-Cesium to detect them and synchronize them automatically. You should either not use unmanaged layers or you could synchronize them yourself (you may want to use the low level facilities from OL3-Cesium for this).
Thanks a lot. I have amended the code on my side; feel free to close this issue if you feel ol3-cesium works as intended/designed, or leave it open if you would like it to keep track of it.
Added a limitation section to the README.md pointing to this issue.
@jmgomezpoveda could you please share the code which is working for you , Im still having the same issue
@AhammadAliPK following the original code snippet, the fix would be as follows:
var geometry = new ol.geom.Polygon([
[ [10.689697265625, -25.0927734375], [34.595947265625, -20.1708984375], [38.814697265625, -35.6396484375],
[13.502197265625, -39.1552734375], [10.689697265625, -25.0927734375] ]
]);
geometry.transform('EPSG:4326', 'EPSG:3857');
var vectorLayer = new ol.layer.Vector({
source: new ol.source.Vector({
features: [new ol.Feature({
geometry: geometry
})]
})
});
this.map.addLayer(vectorLayer);
Thanks , It is working fine, but the problem is when we load 3D as default view , it's not adding the layer . But when we switch 2D and then switch to 3D back and it's working fine.