{"id":1591,"date":"2016-04-05T01:41:49","date_gmt":"2016-04-05T01:41:49","guid":{"rendered":"http:\/\/www.phpmind.com\/blog\/?p=1591"},"modified":"2016-04-05T01:44:34","modified_gmt":"2016-04-05T01:44:34","slug":"cesium-updating-a-czml-description-upon-opening-the-infobox","status":"publish","type":"post","link":"https:\/\/www.phpmind.com\/blog\/2016\/04\/cesium-updating-a-czml-description-upon-opening-the-infobox\/","title":{"rendered":"cesium &#8211; Updating a CZML &#8216;description&#8217; upon opening the InfoBox ?"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.phpmind.com\/blog\/wp-content\/uploads\/2016\/04\/updating-CZML-description.png\" alt=\"updating-CZML-description\" width=\"494\" height=\"421\" class=\"aligncenter size-full wp-image-1594\" srcset=\"https:\/\/www.phpmind.com\/blog\/wp-content\/uploads\/2016\/04\/updating-CZML-description.png 494w, https:\/\/www.phpmind.com\/blog\/wp-content\/uploads\/2016\/04\/updating-CZML-description-300x256.png 300w\" sizes=\"auto, (max-width: 494px) 100vw, 494px\" \/><\/p>\n<pre>\r\nvar viewer = new Cesium.Viewer('cesiumContainer');\r\nvar scene = viewer.scene;\r\n\r\n\/\/------ create CZML ------\r\n\r\nvar czml = \r\n [{\"id\" : \"document\",\r\n \"version\" : \"1.0\"\r\n },{\"id\" : \"Boston\",\r\n \"label\":{\"text\":\"Boston\"},\r\n \"position\":{\"cartographicDegrees\":[-71.0589,42.3601,0]},\r\n \"description\":\"Boston is a city...\",\r\n },{\"id\" : \"New York City\",\r\n \"label\":{\"text\":\"New York\"},\r\n \"description\":\"New York is a city...\",\r\n \"position\":{\"cartographicDegrees\":[-74.0059,40.7127,0]},\r\n }];\r\n\r\nvar promise = Cesium.CzmlDataSource.load(czml);\r\npromise.then(function(dataSource) {\r\n viewer.dataSources.add(dataSource);\r\n\r\n   \/\/------ Get the array of entities\r\n var entities = dataSource.entities.values;\r\n   \/\/------ Loop entities\r\n   for (var i = 0; i < entities.length; i++) {\r\n     var entity = entities[i];\r\n     var name = entity.label;\r\n     entity.label.translucencyByDistance = new Cesium.NearFarScalar(100000,1.0,500000,0.0);\r\n   }\r\n}).otherwise(function(error){\r\n   \/\/------ Display error\r\n window.alert(error);\r\n});\r\n\r\n    \/\/------ Use SSEH to update to current description\r\n\r\nvar handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);\r\nhandler.setInputAction(function(click) {\r\n  var pickedObject = scene.pick(click.position);\r\n  if (Cesium.defined(pickedObject)) {\r\n\r\n    pickedObject.id.description =  'The current temperature is...';\r\n   }\r\n}, Cesium.ScreenSpaceEventType.LEFT_CLICK);    \r\n<\/pre>\n<pre>\r\n\r\nSetting the description property should update it.  Here is an example:\r\n\r\n\r\nvar handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);\r\nhandler.setInputAction(function(click) {\r\n    var pickedObject = scene.pick(click.position);\r\n    if (Cesium.defined(pickedObject)) {\r\n        pickedObject.id.description = 'New description';\r\n    }\r\n}, Cesium.ScreenSpaceEventType.LEFT_CLICK);\r\n\r\n\r\npickedObject.id is the entity.\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>var viewer = new Cesium.Viewer(&#8216;cesiumContainer&#8217;); var scene = viewer.scene; \/\/&#8212;&#8212; create CZML &#8212;&#8212; var czml = [{&#8220;id&#8221; : &#8220;document&#8221;, &#8220;version&#8221; : &#8220;1.0&#8221; },{&#8220;id&#8221; : &#8220;Boston&#8221;, &#8220;label&#8221;:{&#8220;text&#8221;:&#8221;Boston&#8221;}, &#8220;position&#8221;:{&#8220;cartographicDegrees&#8221;:[-71.0589,42.3601,0]}, &#8220;description&#8221;:&#8221;Boston is a city&#8230;&#8221;, },{&#8220;id&#8221; : &#8220;New York City&#8221;, &#8220;label&#8221;:{&#8220;text&#8221;:&#8221;New York&#8221;}, &#8220;description&#8221;:&#8221;New York is a city&#8230;&#8221;, &#8220;position&#8221;:{&#8220;cartographicDegrees&#8221;:[-74.0059,40.7127,0]}, }]; var promise = Cesium.CzmlDataSource.load(czml); promise.then(function(dataSource) { viewer.dataSources.add(dataSource); \/\/&#8212;&#8212; Get the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[53],"tags":[],"class_list":["post-1591","post","type-post","status-publish","format-standard","hentry","category-cesiumjs"],"_links":{"self":[{"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/posts\/1591","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/comments?post=1591"}],"version-history":[{"count":3,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/posts\/1591\/revisions"}],"predecessor-version":[{"id":1595,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/posts\/1591\/revisions\/1595"}],"wp:attachment":[{"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/media?parent=1591"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/categories?post=1591"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/tags?post=1591"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}