Improve InfoBox

361 views
Skip to first unread message

xsa...@gmail.com

unread,
May 28, 2016, 10:11:50 AM5/28/16
to cesium-dev
Hello, I'm trying to improve the InfoBox of my cesium development (http://social4d.com/) and I'm finding to do something like that https://cesiumjs.org/d3cesium/ where you can see how into the infobox is showed the interpolate number of height of the polyline in each moment. I'm trying to adapt this code to my web, but the problem is that I have no idea about how I can change the infobox because cesium doesn't have any function to modify it, not?

In this moment I'm reading the documentation about the InfoBox but doesn't appear nothing about modify the content. Do you have any idea?

Thanks!

xsa...@gmail.com

unread,
May 28, 2016, 10:13:50 AM5/28/16
to cesium-dev, xsa...@gmail.com
And another question, exist any function in Cesium to show using the console the values of one entity in the Cesium time?

xsa...@gmail.com

unread,
May 29, 2016, 11:37:22 AM5/29/16
to cesium-dev, xsa...@gmail.com
Ok, I found the method to modify the InfoBox of one entity:

entity.description = "Hello";

But I want insert in the description one value of the entity that is changing with the time (the height of extrusion of a polygon). I found the function getValue(time) but, I have no idea about where is declared the variable time in function. Any help?

In my opinion, the documentation of Cesium is very very well, but one example from each function would help all the doubts...

xsa...@gmail.com

unread,
May 30, 2016, 1:29:33 PM5/30/16
to cesium-dev, xsa...@gmail.com
I found this topic about the same problem ( https://groups.google.com/forum/#!topic/cesium-dev/RstiXJxCBQE ) and I found the example of Hiroshima ( http://hiroshima.archiving.jp/index_en.html ) I'm trying to improve my Info Box with a script like this:

entity.description = '<script type="text/javascript">document.write("Hello ");</script>';

But it doesn't work. Someone know how put a script into the description? Thanks!

Hannah Pinkos

unread,
May 31, 2016, 10:07:55 AM5/31/16
to cesium-dev, xsa...@gmail.com
Hello,

In order to run a script in the infobox, you have to enable scrips to run in the iframe.  This is disabled by default for security reasons, in case you don't know the source of the data populating the infobox.
You can enable scrips with this code:


var iframe = document.getElementsByClassName('cesium-infoBox-iframe')[0];
iframe
.setAttribute('sandbox', 'allow-same-origin allow-scripts allow-popups allow-forms'); 


Also, to get the current value of an entity property, you can use .getValue(viewer.clock.currentTime);

Best,

Hannah

오유상

unread,
Nov 5, 2019, 2:43:49 AM11/5/19
to cesium-dev
var iframe = document.getElementsByClassName('cesium-infoBox-iframe')[0];
iframe
.setAttribute('sandbox', 'allow-same-origin allow-scripts allow-popups allow-forms'); 
This method is valid now??

It's not working for me.

Certainly function is declared.

but onclick in infobox can't find function.

-Error message-
Uncaught ReferenceError: youtube_popup is not defined
    at HTMLInputElement.onclick (about:blank:1)

Omar Shehata

unread,
Nov 5, 2019, 8:22:39 AM11/5/19
to cesium-dev
Can you put together a Sandcastle (https://sandcastle.cesium.com/index.html?) example showing this issue?

오유상

unread,
Nov 5, 2019, 9:48:46 PM11/5/19
to cesium-dev

오유상

unread,
Nov 6, 2019, 10:19:15 AM11/6/19
to cesium-dev
 I partially find solution.(it's a trick?)
iframe is another page.
So there are no function declared.
If you want call function from main page to iframe.
Attach 'parent' or 'top' front of function name.

eg)
---Main page----
function message(){
   console.log('message');
}
---iframe---
<button onclick="top.message">
or
<button onclick="parent.message">

da...@ferg.co

unread,
Nov 12, 2019, 2:54:27 PM11/12/19
to cesium-dev
One thing you could do also is (we did this this), just completely get rid of the default info box and then listen for the selectedEntityChanged events within Cesium and show a custom info box using info from the selected entity

오유상

unread,
Nov 13, 2019, 8:16:18 AM11/13/19
to cesium-dev
Hi David.
That's a nice tip.
Your advise contribute improving my work's quality
Thank you!!

lawyo...@gmail.com

unread,
Mar 11, 2020, 5:59:50 AM3/11/20
to cesium-dev
Do you think you can provide an code example of what you mean? Thank you.

lawyo...@gmail.com

unread,
Mar 11, 2020, 6:03:42 AM3/11/20
to cesium-dev

Omar Shehata

unread,
Mar 11, 2020, 7:08:31 AM3/11/20
to cesium-dev
The viewer has a selectedEntityChanged event so you can listen for that, undo the default behavior (set viewer.selectedEntity = undefined) and then do your own custom behavior:

da...@ferg.co

unread,
Mar 11, 2020, 9:06:21 AM3/11/20
to cesium-dev
Expanding on this a little further....

What he was looking for (I think) was the ability to show a button in the InfoBox and it run his custom JavaScript when clicked. The issue with that is though that, the InfoBox code is run in an iframe and isn't in the same scope as his other code.

I'm not 100% sure if this is what Omar was suggesting or not but this is what we did with our tool. Using that selectedEntityChanged event, disable the default InfoBox component and watch that event. When an item is selected, show your own custom modal or other component/HTML that is within the same scope and not in the iframe previously mentioned. That way you have complete control over that piece and can style it to do exactly what you want it to do.

lawyo...@gmail.com

unread,
Mar 12, 2020, 5:44:25 AM3/12/20
to cesium-dev
Do you mean like this:

dots.forEach(function(dot) {
    viewer.entities.add({
        position : Cesium.Cartesian3.fromDegrees(dot.lon, dot.lat),
        point : {
            pixelSize : 7,
            color : Cesium.Color.STEELBLUE,
            outlineColor : Cesium.Color.BLACK,
            outlineWidth : 1.0
        }
    });
});

viewer.selectedEntityChanged.addEventListener(function(entity) {
test_function();
});
Reply all
Reply to author
Forward
0 new messages