openlayers / ol-cesium

OpenLayers - Cesium integration
http://openlayers.org/ol-cesium/
BSD 2-Clause "Simplified" License
1.01k stars 329 forks source link

Vector feature “flashes” after geometry update #900

Open zsoooc opened 3 years ago

zsoooc commented 3 years ago

I would like to append new points to a vector polygon geometry in OpenLayers v6.5.0 and Ol-Cesium v2.12 (Cesium v1.77).

My UpdatePolygon function will be called in every seconds or more frequently with new parameters. In 2D mode (if the cesViewer is disabled) it works perfectly. However, in 3D mode (cesViewer enabled) the polygon flashes after every update. It is annoying because the polygon will be updated in every second or more frequently and the view is following the polygon, thus it seem like flashing continuously. The "camera" height is very low (zoom level is the highest), and the view is "moving" continuously, like a car navigation in 3D view. The user constantly sees the polygon. The feature is a single, simple polygon with only one, exterior ring.

Is it a bug in OL-Cesium? Do you have any suggestions how to fix it?

This is the relevant part of my code:

function updatePolygon(x_prev,y_prev,x,y,polygonLeftSideDistance,polygonRightSideDistance){

heading = turf.bearing(prev_position, current_position);

//Calculate new coordinates
var currentGeom = source.getFeatureById(currentID).getGeometry().getCoordinates()[0];
currentGeom.pop();
currentGeom.push(turf.toMercator(turf.destination(current_position,polygonLeftSideDistance,heading-90)).geometry.coordinates);
currentGeom.unshift(turf.toMercator(turf.destination(current_position,polygonRightSideDistance,heading-90)).geometry.coordinates);
currentGeom.push(currentGeom[0]);

//Update the geometry
source.getFeatureById(currentID).getGeometry().setCoordinates([currentGeom]);
}

//Source
var source = new ol.source.Vector( {overlaps: false,strategy: ol.loadingstrategy.bbox});
var format = new ol.format.GeoJSON();
//Vector layer definition
var vectorLayer = new ol.layer.Vector({
        renderMode: 'image',        
        source: source,
        disableHitDetection: true,
        style:  function(feature, resolution) {
    const name = feature.get('category');
    return name == "1" ? style1 : style2;
  }
 });

//Map Creation
        var map = new ol.Map({
        renderer: 'webgl',
            controls: controls,
            interactions: interactions,
            updateWhileInteracting: true,
            updateWhileAnimating: true,
            target: 'olCesMap',
            layers: [basemapTileLayer, vectorLayer],
            view: new ol.View({
                center: center,
                zoom: zoom
            })
        });
        //Cesium Viewer constructed based on Ol.Map
        var cesViewer = new olcs.OLCesium({
            map: map,
            sceneOptions: {
                mapProjection: new Cesium.WebMercatorProjection()
            }
        });
        //Cesium Viewer scene
        var scene = cesViewer.getCesiumScene();
        //Cesium Viewer enable
        cesViewer.setEnabled(false);

        //Cesium Viewer depthtest
        scene.globe.depthTestAgainstTerrain = false;

         function setCesViewer3D(){
        if(!cesViewer.getEnabled()){
            cesViewer.setEnabled(true);
            cesViewer.scene_.debugShowFramesPerSecond = true;
cesViewer.scene_.requestRenderMode = true;cesViewer.enableAutoRenderLoop();
        }
FerretAngel commented 1 month ago

Have you figured out this problem? It's been a while and I'm still struggling with it, trying to find a solution.