Polygon with callbackproperty hierarchy low performance

Hello.
I am trying to update a polygon hierarchy with a CallbackProperty but it really slows down the fps and the browser.

I’ve been trying to look for a good solution but I wasn’t able to find it.
Am I using it bad? In that case, how should I use it?

I made a simple demo to show what I mean in which I hardcoded the polygon hierarchy and just used a callbackproperty to return it. Notice that I used It with the isConstant property set as false since In my real scenario I need this hierarchy to be dynamic.

var viewer = new Cesium.Viewer("cesiumContainer");
const hardcoded = [new Cesium.Cartesian3(1356073.8752736934, 2877271.1863374263, -5509846.221236188),new Cesium.Cartesian3(-6170054.062895637, 1545564.3357834257, -469901.27436282113),new Cesium.Cartesian3(1356073.8752736934, 2877271.1863374263, -5509846.221236188),new Cesium.Cartesian3(1332405.8905874696, 2730725.9986101203, -5627775.074870241),new Cesium.Cartesian3(1320306.2344815582, 2567945.2557267956, -5740588.557434357),new Cesium.Cartesian3(1322191.432040397, 2385435.961453803, -5847278.805454662),new Cesium.Cartesian3(1341761.4638045765, 2177942.1290133186, -5946247.547332951),new Cesium.Cartesian3(1385177.2536474057, 1936847.6468501762, -6034752.308577691),new Cesium.Cartesian3(1464169.7207538225, 1645979.6597793847, -6107431.927662798),new Cesium.Cartesian3(1607442.4660527539, 1266294.7631258257, -6150852.373289625),new Cesium.Cartesian3(1971230.374501735, 588366.0138082728, -6090045.674648562),new Cesium.Cartesian3(-6379024.975992628, -920203.2418644205, -726091.1696163155),new Cesium.Cartesian3(-6465583.218336843, -299468.00741292164, -885799.2570634726),new Cesium.Cartesian3(-6478445.772297881, 93165.4867601879, -919335.4924959447),new Cesium.Cartesian3(-6464433.692063347, 399729.87603307515, -906766.3661243338),new Cesium.Cartesian3(-6434985.75710217, 655773.6619461365, -867680.4976849649),new Cesium.Cartesian3(-6395034.233483175, 876994.561224468, -810536.3308097925),new Cesium.Cartesian3(-6347222.253219523, 1072022.9420504682, -739873.7470886055),new Cesium.Cartesian3(-6293147.675062693, 1246225.290664196, -658442.1193670966),new Cesium.Cartesian3(-6233852.9790161075, 1403215.0473054834, -568038.8645086195),new Cesium.Cartesian3(-6170054.062895637, 1545564.3357834257, -469901.27436282113),new Cesium.Cartesian3(-6137570.01530509, 1665189.0506352037, -590112.7305670287),new Cesium.Cartesian3(-6103215.72380337, 1778073.4654060043, -705462.8115045726),new Cesium.Cartesian3(-6067220.885404135, 1884980.2971305922, -816492.2859265916),new Cesium.Cartesian3(-6029769.092004055, 1986529.9919939674, -923642.7361322623),new Cesium.Cartesian3(-5991009.304477975, 2083235.3778722733, -1027280.590284368),new Cesium.Cartesian3(-5951063.913479306, 2175526.1369228326, -1127714.1166719273),new Cesium.Cartesian3(-5910034.548080815, 2263766.5345358215, -1225205.7510368582),new Cesium.Cartesian3(-5868006.354174846, 2348268.548042409, -1319981.2371529248),new Cesium.Cartesian3(-5825051.20641869, 2429301.7766365074, -1412236.5354426373),new Cesium.Cartesian3(-5781230.160267514, 2507101.048563309, -1502143.1332716346),new Cesium.Cartesian3(-5736595.351819163, 2581872.3483502567, -1589852.1880484503),new Cesium.Cartesian3(-5691191.489367407, 2653797.4969074875, -1675497.8030053694),new Cesium.Cartesian3(-5645057.038319556, 2723037.8912744448, -1759199.6483774837),new Cesium.Cartesian3(-5598225.172568146, 2789737.525311403, -1841065.08155182),new Cesium.Cartesian3(-5550724.545707056, 2854025.4535268024, -1921190.8788318932),new Cesium.Cartesian3(-5502579.921656685, 2916017.818633903, -1999664.6626410708),new Cesium.Cartesian3(-5453812.694403604, 2975819.533684712, -2076566.0873642191),new Cesium.Cartesian3(-5404441.319425711, 3033525.6880457513, -2151967.8320520334),new Cesium.Cartesian3(-5354481.67414196, 3089222.7306084223, -2225936.437192913),new Cesium.Cartesian3(-5303947.360841379, 3142989.4718111083, -2298533.0145484805),new Cesium.Cartesian3(-5252849.962629978, 3194897.9371547736, -2369813.8528643698),new Cesium.Cartesian3(-5201199.26072035, 3245014.098123532, -2439830.937558247),new Cesium.Cartesian3(-5149003.419693574, 3293398.501222238, -2508632.3988674283),new Cesium.Cartesian3(-5096269.146051014, 3340106.8118093833, -2576262.9001286756),new Cesium.Cartesian3(-5043001.824351231, 3385190.286251284, -2642763.9756655805),new Cesium.Cartesian3(-4989205.634423077, 3428696.1834379956, -2708174.3260253854),new Cesium.Cartesian3(-4934883.652508674, 3470668.124727156, -2772530.0769294687),new Cesium.Cartesian3(-4880037.938682251, 3511146.4098044895, -2835865.007200133),new Cesium.Cartesian3(-4824669.612482013, 3550168.294678144, -2898210.750038242),new Cesium.Cartesian3(-4768778.918362556, 3587768.236995317, -2959596.9713070877),new Cesium.Cartesian3(-4712365.282306323, 3623978.1130301915, -3020051.5278910603),new Cesium.Cartesian3(-4655427.360712757, 3658827.410004329, -3079600.6087166276),new Cesium.Cartesian3(-4597963.082502931, 3692343.396834485, -3138268.86062699),new Cesium.Cartesian3(-4539969.685226746, 3724551.2759320326, -3196079.50097261),new Cesium.Cartesian3(-4481443.745835414, 3755474.3182881437, -3253054.4185068756),new Cesium.Cartesian3(-4422381.206676299, 3785133.983750306, -3309214.2639466505),new Cesium.Cartesian3(-4362777.397179011, 3813550.028120745, -3364578.531365188),new Cesium.Cartesian3(-4302627.051626207, 3840740.598474182, -3419165.631422436),new Cesium.Cartesian3(-4241924.323338147, 3866722.31789444, -3472992.9572996963),new Cesium.Cartesian3(-4180662.795544127, 3891510.3606594354, -3526076.944087809),new Cesium.Cartesian3(-4118835.489166029, 3915118.5187601186, -3578433.122278033),new Cesium.Cartesian3(-4056434.867695827, 3937559.260511525, -3630076.165917214),new Cesium.Cartesian3(-3993452.839311667, 3958843.7819062024, -3681019.935914781),new Cesium.Cartesian3(-3929880.7563425787, 3978982.05126372, -3731277.51892337),new Cesium.Cartesian3(-3865709.412160801, 3997982.847645562, -3780861.2621581163),new Cesium.Cartesian3(-3800929.035551857, 4015853.7934296764, -3829782.8044694886),new Cesium.Cartesian3(-3735529.2825852036, 4032601.3813708723, -3878053.1039400175),new Cesium.Cartesian3(-3669499.2259818856, 4048230.9964114875, -3925682.4622352812),new Cesium.Cartesian3(-3602827.341950508, 4062746.932450533, -3972680.545904057),new Cesium.Cartesian3(-3535501.494437102, 4076152.4042260274, -4019056.4047894906),new Cesium.Cartesian3(-3467508.9167083446, 4088449.554414455, -4064818.487682745),new Cesium.Cartesian3(-3398836.1901616994, 4099639.456003748, -4109974.655322943),new Cesium.Cartesian3(-3329469.220227437, 4109722.109947566, -4154532.1908198036),new Cesium.Cartesian3(-3259393.209198024, 4118696.4380611666, -4198497.807549724),new Cesium.Cartesian3(-3188592.625788413, 4126560.2710709795, -4241877.654550819),new Cesium.Cartesian3(-3117051.1711953897, 4133310.3316791803, -4284677.319416685),new Cesium.Cartesian3(-3044751.741385862, 4138942.2124520503, -4326901.828663288),new Cesium.Cartesian3(-2971676.3853005283, 4143450.3482837826, -4368555.645516131),new Cesium.Cartesian3(-2897806.2586112283, 4146827.9831262752, -4409642.665037075),new Cesium.Cartesian3(-2823121.572615579, 4149067.130607594, -4450166.206479739),new Cesium.Cartesian3(-2747601.5377897453, 4150158.528085962, -4490129.002729254),new Cesium.Cartesian3(-2671224.3014496695, 4150091.5836028196, -4529533.186646469),new Cesium.Cartesian3(-2593966.8788880445, 4148854.315100696, -4568380.274095286),new Cesium.Cartesian3(-2515805.0772600584, 4146433.2811634094, -4606671.143386649),new Cesium.Cartesian3(-2436713.4113799557, 4142813.50240846, -4644406.010819854),new Cesium.Cartesian3(-2356665.0104619022, 4137978.372515302, -4681584.401941862),new Cesium.Cartesian3(-2275631.5146873333, 4131909.5577019043, -4718205.118075382),new Cesium.Cartesian3(-2193582.9603028707, 4124586.8832609765, -4754266.197584597),new Cesium.Cartesian3(-2110487.6517421883, 4115988.2055299766, -4789764.871251324),new Cesium.Cartesian3(-2026312.019015206, 4106089.2673883326, -4824697.5110207405),new Cesium.Cartesian3(-1941020.4583088811, 4094863.5350392833, -4859059.571239827),new Cesium.Cartesian3(-1854575.1533859093, 4082282.013432432, -4892845.52134975),new Cesium.Cartesian3(-1766935.8749354891, 4068313.0371977948, -4926048.768796999),new Cesium.Cartesian3(-1678059.7545082308, 4052922.03337691, -4958661.570691859),new Cesium.Cartesian3(-1587901.029029362, 4036071.251519669, -4990674.932452632),new Cesium.Cartesian3(-1496410.7511063796, 4017719.455841992, -5022078.491320666),new Cesium.Cartesian3(-1403536.4593862426, 3997821.5730585717, -5052860.382193236),new Cesium.Cartesian3(-1309221.8020287286, 3976328.288167432, -5083007.082679072),new Cesium.Cartesian3(-1213406.1048792172, 3953185.5787918605, -5112503.233602792),new Cesium.Cartesian3(-1116023.8740617223, 3928334.17658481, -5141331.430330589),new Cesium.Cartesian3(-1017004.2203580346, 3901708.941541914, -5169471.97920757),new Cesium.Cartesian3(-916270.1897352766, 3873238.131673865, -5196902.612013105),new Cesium.Cartesian3(-813737.9805254135, 3842842.546121951, -5223598.149558717),new Cesium.Cartesian3(-709316.0227538217, 3810434.5141272284, -5249530.103234509),new Cesium.Cartesian3(-602903.8885612227, 3775916.69482968, -5274666.200268267),new Cesium.Cartesian3(-494390.9939932488, 3739180.643024754, -5298969.814425455),new Cesium.Cartesian3(-383655.04083670303, 3700105.0828166306, -5322399.278466899),new Cesium.Cartesian3(-270560.131485058, 3658553.8132321946, -5344907.047335798),new Cesium.Cartesian3(-154954.4682888072, 3614373.145313572, -5366438.670945428),new Cesium.Cartesian3(-36667.51890096255, 3567388.7360182703, -5386931.521351201),new Cesium.Cartesian3(84493.5131784752, 3517401.635893319, -5406313.199134788),new Cesium.Cartesian3(208748.13446181454, 3464183.2978895493, -5424499.515068624),new Cesium.Cartesian3(336348.2343961913, 3407469.1926161796, -5441391.900895879),new Cesium.Cartesian3(467585.42921531945, 3346950.522474978, -5456874.039721221),new Cesium.Cartesian3(602800.7245587353, 3282263.2927452996, -5470807.409259642),new Cesium.Cartesian3(742397.4654020183, 3212973.628720004, -5483025.277876833),new Cesium.Cartesian3(886859.0614385884, 3138557.6294262893, -5493324.444294892),new Cesium.Cartesian3(1036773.8473369014, 3058373.0434643403, -5501453.59307925),new Cesium.Cartesian3(1192870.9575909097, 2971618.29660492, -5507096.4053695)];

var polygonCreate = viewer.entities.add({        
    polygon : {
        hierarchy:new Cesium.CallbackProperty(function () {
          return {
              positions: hardcoded
         };
      }, false),
        material: Cesium.Color.fromCssColorString("green"),

    }
});

Demo

Thanks in advance.

Update
Apparently my issue is not caused by the CallbackProperty, see my sandcastle example
Or my more involved example
So the rest of this post can be ignored.

I think I’m facing a different, but related issue regarding the use of CallbackProperties in combination with Polylines. I have assigned an outline material to a polyline, and I’m trying to set the color through a CallbackProperty. This lead to flicker when the color is updated.
Maybe the use of the CallbackProperty is the bottleneck in situations like this? could someone from the Cesium dev team shine a light on this?
I’ll try to set up a sandcastle example for my use-case.

Is there a way to update the polygon hierarchy manually? Maybe with a listener?
I tried to do as suggested, with an ontick event and updating the polygon hierarchy but the performance is still horrible.

Any suggestions?

Hi,

Yes, you can update it any way you like, for example myEntity.polygon.hierarchy = myPosArray; any time you like, including any event handler. There are some change detection in both the API natively (although don’t know if there’s any in an array of coordinates, so manually updating that in real-time might be quite slow) as well as the callbackProperty(), so I don’t think that is your problem.

But it all comes down to what you’re trying to do. Can you create a Sandcastle example with this horrible performance? Both the previous ones were snappy and fine. I think if you can re-create a slow version we can all have a stab at it.

Cheers,

Alex

Are you really telling me this sandcastle works fine in your browser? Compare it performance with this one without callback property.

If you tell me that, maybe I have a problem with the browser or my GPU is not enough. In my case the first one with the callbackproperty works so bad, with a very low performance :frowning:

CallbackProperty should be best option but I don’t know why browser is hanging on sandcastle. I’ve tried with setInterval which is not hanging browser. You check this link

Hi again, Jacky, you always helping :stuck_out_tongue:

That was my exact aproach because I noticed it worked better with a setInterval. I was not using requestRender so maybe I need to implement it. When should I update with a new frame? Because I guess changing requestRenderMode to true will force me to update every render, is that correct?
I just realised your approach has another issue: check the time passing. Its slower and kind of laggy.

I will implement that and test it but my problem now is that we need to calculate the new hierarchy so increasing the simulation speed makes it laggy again.

So to summarize:

  • I need to calculate a new hierarchy for each tick of the clock.
  • With callbackProperty it works pretty bad and all the browser is lagging.
  • Using an ontick event listener improves the performance.
  • When the app is running in x1 speed, it works decently but as soon as I increase the speed it starts to get lagged. It can be because of the new calculation taking time, I am going to test what happens if I just return something random hardcoded which should not take time.

Hiya,

No, you’re right the performance takes a big hit, not sure why I didn’t see it earlier? (Although I sometimes have more than one Cesium viewer running, and I know there’s a slowdown with multiples running).

The only thing I would do is look in the source code for the callbackProperty to find out how the change detection works. Maybe it’s simply rules that arrays over X don’t check, or some silly limitation? You could try to do your sandcastle twice but with half the coords, or four times but with a quarter positions at least until some Cesium dev team member can share some light on it. Maybe the change detection doesn’t work well for Cartesian3, bt great for booleans and simpler data types?

Cheers,

Alex

I’ve met the problem too. I made a drawing program using CallbackProperty to receive the positions which changed once user click on viewer. I find that if all the positions are close to each other, the fps is good, but if some positions are very far away, then fps will be very low. And after drawing is done I will turn it to ConstantProperty then the fps will be good again.

So I think it’s related to position data? (Not very sure)

I suppose the problem is related to the earth curvature, but I find it strange that this has not happened before to anyone.

If the problem is that, could it be a possible approach to divide the polygon into multiple polygons?

I honestly cant see a solution.