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

Polygons are not rendered #350

Closed
jmgomezpoveda opened this issue Apr 28, 2016 · 15 comments
Closed

Polygons are not rendered #350

jmgomezpoveda opened this issue Apr 28, 2016 · 15 comments

Comments

@jmgomezpoveda
Copy link
Contributor

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
        })]
    })
});
@gberaudo
Copy link
Member

Are you using terrain?

@jmgomezpoveda
Copy link
Contributor Author

No, I am not using terrain. In any case, I just tested it with a terrain, and the polygon is not rendered either.

@gberaudo
Copy link
Member

Yyou are not setting any style so maybe this is the reason why nothing is showing up.

@jmgomezpoveda
Copy link
Contributor Author

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.

@gberaudo
Copy link
Member

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.

@jmgomezpoveda
Copy link
Contributor Author

Unfortunately, I have just tested setting a style, but polygons are still not rendered.

@gberaudo
Copy link
Member

gberaudo commented May 2, 2016

Strange. Have you compared with what is done in the vectors example?

@jmgomezpoveda
Copy link
Contributor Author

In fact, polygons are rendered fine in the vectors example. I will debug that one and update this ticket with any findings.

@jmgomezpoveda
Copy link
Contributor Author

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?

@gberaudo
Copy link
Member

gberaudo commented May 2, 2016

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).

@jmgomezpoveda
Copy link
Contributor Author

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.

@gberaudo gberaudo closed this as completed May 2, 2016
@gberaudo
Copy link
Member

gberaudo commented May 2, 2016

Added a limitation section to the README.md pointing to this issue.

@AhammadAliPK
Copy link

@jmgomezpoveda could you please share the code which is working for you , Im still having the same issue

@jmgomezpoveda
Copy link
Contributor Author

@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);

@AhammadAliPK
Copy link

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.

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