{"id":1453,"date":"2015-10-20T23:41:48","date_gmt":"2015-10-20T23:41:48","guid":{"rendered":"http:\/\/www.phpmind.com\/blog\/?p=1453"},"modified":"2015-10-20T23:46:34","modified_gmt":"2015-10-20T23:46:34","slug":"1453","status":"publish","type":"post","link":"https:\/\/www.phpmind.com\/blog\/2015\/10\/1453\/","title":{"rendered":"Cesiumjs &#8211; How to remove individual KML DataSources?"},"content":{"rendered":"<p><a href=\"http:\/\/www.phpmind.com\/blog\/wp-content\/uploads\/2015\/10\/Cesiumjs-phpmind-remove-datasource.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1454\" src=\"http:\/\/www.phpmind.com\/blog\/wp-content\/uploads\/2015\/10\/Cesiumjs-phpmind-remove-datasource.png\" alt=\"Cesiumjs-phpmind-remove-datasource\" width=\"473\" height=\"409\" srcset=\"https:\/\/www.phpmind.com\/blog\/wp-content\/uploads\/2015\/10\/Cesiumjs-phpmind-remove-datasource.png 473w, https:\/\/www.phpmind.com\/blog\/wp-content\/uploads\/2015\/10\/Cesiumjs-phpmind-remove-datasource-300x259.png 300w\" sizes=\"auto, (max-width: 473px) 100vw, 473px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/www.phpmind.com\/blog\/wp-content\/uploads\/2015\/10\/Cesiumjs-phpmind-remove-datasource_add.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1455\" src=\"http:\/\/www.phpmind.com\/blog\/wp-content\/uploads\/2015\/10\/Cesiumjs-phpmind-remove-datasource_add.png\" alt=\"Cesiumjs-phpmind-remove-datasource_add\" width=\"493\" height=\"474\" srcset=\"https:\/\/www.phpmind.com\/blog\/wp-content\/uploads\/2015\/10\/Cesiumjs-phpmind-remove-datasource_add.png 493w, https:\/\/www.phpmind.com\/blog\/wp-content\/uploads\/2015\/10\/Cesiumjs-phpmind-remove-datasource_add-300x288.png 300w\" sizes=\"auto, (max-width: 493px) 100vw, 493px\" \/><\/a><\/p>\n<pre lang=\"js\">var viewer = new Cesium.Viewer('cesiumContainer');\r\n\r\nvar dataSource1 = new Cesium.KmlDataSource();\r\ndataSource1.load('..\/..\/SampleData\/kml\/facilities\/facilities.kml');\r\n\r\nvar dataSource2 = new Cesium.KmlDataSource();\r\ndataSource2.load('..\/..\/SampleData\/kml\/gdpPerCapita2008.kmz');\r\n\r\nSandcastle.addToolbarButton('Add DataSource 1', function() {\r\n    viewer.dataSources.add(dataSource1);\r\n});\r\n\r\nSandcastle.addToolbarButton('Remove DataSource 1', function() {\r\n    viewer.dataSources.remove(dataSource1);\r\n});\r\n\r\nSandcastle.addToolbarButton('Add DataSource 2', function() {\r\n    viewer.dataSources.add(dataSource2);\r\n});\r\n\r\nSandcastle.addToolbarButton('Remove DataSource 2', function() {\r\n    viewer.dataSources.remove(dataSource2);\r\n});\r\n\r\n<\/pre>\n<p>If you are not familiat with Promises, I recommend reading this article: http:\/\/www.html5rocks.com\/en\/tutorials\/es6\/promises\/ Cesium specifically uses the `when` promise library that is mentioned in the article.<\/p>\n<pre>\r\n \r\nvar viewer = new Cesium.Viewer('cesiumContainer');\r\n\r\nvar promise1 = Cesium.KmlDataSource.load('..\/..\/SampleData\/kml\/facilities\/facilities.kml');\r\nvar promise2 = Cesium.KmlDataSource.load('..\/..\/SampleData\/kml\/gdpPerCapita2008.kmz');\r\n\r\nCesium.when(promise1, function(dataSource1){\r\n    Sandcastle.addToolbarButton('Add DataSource 1', function() {\r\n        viewer.dataSources.add(dataSource1);\r\n    });\r\n\r\n    Sandcastle.addToolbarButton('Remove DataSource 1', function() {\r\n        viewer.dataSources.remove(dataSource1);\r\n    });\r\n});\r\n\r\nCesium.when(promise2, function(dataSource2){\r\n    Sandcastle.addToolbarButton('Add DataSource 2', function() {\r\n        viewer.dataSources.add(dataSource2);\r\n    });\r\n\r\n    Sandcastle.addToolbarButton('Remove DataSource 2', function() {\r\n        viewer.dataSources.remove(dataSource2);\r\n    });\r\n});\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>var viewer = new Cesium.Viewer(&#8216;cesiumContainer&#8217;); var dataSource1 = new Cesium.KmlDataSource(); dataSource1.load(&#8216;..\/..\/SampleData\/kml\/facilities\/facilities.kml&#8217;); var dataSource2 = new Cesium.KmlDataSource(); dataSource2.load(&#8216;..\/..\/SampleData\/kml\/gdpPerCapita2008.kmz&#8217;); Sandcastle.addToolbarButton(&#8216;Add DataSource 1&#8217;, function() { viewer.dataSources.add(dataSource1); }); Sandcastle.addToolbarButton(&#8216;Remove DataSource 1&#8217;, function() { viewer.dataSources.remove(dataSource1); }); Sandcastle.addToolbarButton(&#8216;Add DataSource 2&#8217;, function() { viewer.dataSources.add(dataSource2); }); Sandcastle.addToolbarButton(&#8216;Remove DataSource 2&#8217;, function() { viewer.dataSources.remove(dataSource2); }); If you are not familiat with Promises, I recommend reading [&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-1453","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\/1453","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=1453"}],"version-history":[{"count":4,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/posts\/1453\/revisions"}],"predecessor-version":[{"id":1459,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/posts\/1453\/revisions\/1459"}],"wp:attachment":[{"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/media?parent=1453"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/categories?post=1453"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/tags?post=1453"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}