{"id":1464,"date":"2015-10-21T20:50:06","date_gmt":"2015-10-21T20:50:06","guid":{"rendered":"http:\/\/www.phpmind.com\/blog\/?p=1464"},"modified":"2015-10-21T20:50:44","modified_gmt":"2015-10-21T20:50:44","slug":"cesiumjs-how-can-i-control-visibility-of-datasource-showhide","status":"publish","type":"post","link":"https:\/\/www.phpmind.com\/blog\/2015\/10\/cesiumjs-how-can-i-control-visibility-of-datasource-showhide\/","title":{"rendered":"Cesiumjs &#8211; How can i control visibility of datasource show\/hide ?"},"content":{"rendered":"<p><a href=\"http:\/\/www.phpmind.com\/blog\/wp-content\/uploads\/2015\/10\/phpmind-cesiumjs-show-hide-kml.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.phpmind.com\/blog\/wp-content\/uploads\/2015\/10\/phpmind-cesiumjs-show-hide-kml.png\" alt=\"phpmind-cesiumjs-show-hide-kml\" width=\"572\" height=\"455\" class=\"aligncenter size-full wp-image-1465\" srcset=\"https:\/\/www.phpmind.com\/blog\/wp-content\/uploads\/2015\/10\/phpmind-cesiumjs-show-hide-kml.png 572w, https:\/\/www.phpmind.com\/blog\/wp-content\/uploads\/2015\/10\/phpmind-cesiumjs-show-hide-kml-300x239.png 300w\" sizes=\"auto, (max-width: 572px) 100vw, 572px\" \/><\/a><\/p>\n<pre>\r\n\r\n\r\nvar viewer = new Cesium.Viewer('cesiumContainer');\r\n\r\n\/\/ Create a typical CzmlDataSource.\r\nvar dataSource1 = new Cesium.CzmlDataSource();\r\ndataSource1.load('..\/..\/SampleData\/simple.czml');\r\n\r\n\/\/ Add a checkbox at the top.\r\ndocument.getElementById('toolbar').innerHTML =\r\n    '<label><input type=\"checkbox\" id=\"showCheckbox\" \/> Show CZML<\/label>';\r\n\r\nvar checkbox = document.getElementById('showCheckbox');\r\ncheckbox.addEventListener('change', function() {\r\n    \/\/ Checkbox state changed.\r\n    if (checkbox.checked) {\r\n        \/\/ Show if not shown.\r\n        if (!viewer.dataSources.contains(dataSource1)) {\r\n            viewer.dataSources.add(dataSource1);\r\n        }\r\n    } else {\r\n        \/\/ Hide if currently shown.\r\n        if (viewer.dataSources.contains(dataSource1)) {\r\n            viewer.dataSources.remove(dataSource1);\r\n        }\r\n    }\r\n}, false);\r\n\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>var viewer = new Cesium.Viewer(&#8216;cesiumContainer&#8217;); \/\/ Create a typical CzmlDataSource. var dataSource1 = new Cesium.CzmlDataSource(); dataSource1.load(&#8216;..\/..\/SampleData\/simple.czml&#8217;); \/\/ Add a checkbox at the top. document.getElementById(&#8216;toolbar&#8217;).innerHTML = &#8216; Show CZML&#8217;; var checkbox = document.getElementById(&#8216;showCheckbox&#8217;); checkbox.addEventListener(&#8216;change&#8217;, function() { \/\/ Checkbox state changed. if (checkbox.checked) { \/\/ Show if not shown. if (!viewer.dataSources.contains(dataSource1)) { viewer.dataSources.add(dataSource1); } } else { [&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,27],"tags":[],"class_list":["post-1464","post","type-post","status-publish","format-standard","hentry","category-cesiumjs","category-javascript"],"_links":{"self":[{"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/posts\/1464","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=1464"}],"version-history":[{"count":1,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/posts\/1464\/revisions"}],"predecessor-version":[{"id":1466,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/posts\/1464\/revisions\/1466"}],"wp:attachment":[{"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/media?parent=1464"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/categories?post=1464"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/tags?post=1464"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}