camptocamp / cgxp

22 stars 22 forks source link

Prevent ghost rendering by removing/add feature on undo #1025

Closed pgiraud closed 8 years ago

pgiraud commented 8 years ago

One need to be careful when changing the geometry of a feature in OpenLayers because it may result in ghost geometries still being displayed on the screen. This is due to the fact that OpenLayers relies on geometries ids to check whether a DOM Element should be re-drawn or not. Using the same id for the geometry object as @arnaud-morvan did doesn't work in case when the geometry is a multi one. Instead it's better to remove the feature and re-add it to the layer.

Please review.

ochriste commented 8 years ago

mmm, OL has a vectorlayer.refresh({force:true});

One need to be careful when changing the geometry of a feature in OpenLayers because it may result in ghost geometries still being displayed on the screen. This is due to the fact that OpenLayers relies on geometries ids to check whether a DOM Element should be re-drawn or not. Using the same id for the geometry object as @arnaud-morvan https://github.com/arnaud-morvan did doesn't work in case when the geometry is a multi one. Instead it's better to remove the feature and re-add it to the layer.

Please review.


    You can view, comment on, or merge this pull request online at:

https://github.com/camptocamp/cgxp/pull/1025

    Commit Summary

— Reply to this email directly or view it on GitHub https://github.com/camptocamp/cgxp/pull/1025.

Camptocamp SA Oliver Christen PSE A, EPFL CH-1015 Lausanne

www.camptocamp.com

+41 21 619 10 23 (direct) +41 21 619 10 10 (centrale) +41 21 619 10 00 (fax)


L'absence de virus dans ce courrier électronique a été vérifiée par le logiciel antivirus Avast. https://www.avast.com/antivirus

pgiraud commented 8 years ago

@ochriste Sorry but, no, refresh doesn't work as you can expect. See http://bl.ocks.org/pgiraud/6c40c8617f6717f4122d

Do you think of an other way to use it?

ochriste commented 8 years ago

I guess I was confused im pretty sure we had this problem in the past, but i fear I dont remember how it was solved, maybe simply as you did with a delete/add

also

OL doc seems to suggest drawFeature can redraw feature. did you try to call it without doing a delete before to see if it would be enough? (just asking)

@ochriste https://github.com/ochriste Sorry but, no, |refresh| doesn't work as you can expect. See http://bl.ocks.org/pgiraud/6c40c8617f6717f4122d

Do you think of an other way to use it?

— Reply to this email directly or view it on GitHub https://github.com/camptocamp/cgxp/pull/1025#issuecomment-145524012.

Camptocamp SA Oliver Christen PSE A, EPFL CH-1015 Lausanne

www.camptocamp.com

+41 21 619 10 23 (direct) +41 21 619 10 10 (centrale) +41 21 619 10 00 (fax)


L'absence de virus dans ce courrier électronique a été vérifiée par le logiciel antivirus Avast. https://www.avast.com/antivirus

pgiraud commented 8 years ago

Using drawFeature will effectively redraw the feature as soon as the geometry is modified ie. that it's not a new geometry. In our case, the geometry is a new object. In this case, OpenLayers doesn't know that DOM Elements need to be removed because link to geometry ids is lost.

ochriste commented 8 years ago

ic