Skip to content

Instantly share code, notes, and snippets.

@odoe
Created December 15, 2015 18:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save odoe/4b88ff6a3b928eb0a51d to your computer and use it in GitHub Desktop.
Save odoe/4b88ff6a3b928eb0a51d to your computer and use it in GitHub Desktop.
require([
"esri/config",
"esri/Map",
"esri/views/SceneView",
"esri/layers/FeatureLayer",
"esri/layers/GroupLayer",
"esri/request",
"dojo/domReady!"
], function(esriConfig, Map, SceneView, FeatureLayer, GroupLayer, esriRequest) {
// you'll need a proxy
esriConfig.request.proxyUrl = "/proxy/proxy.php";
var kmlUrl = "https://dl.dropboxusercontent.com/u/2654618/kml/Wyoming.kml";
var serviceUrl = "//utility.arcgis.com/sharing/kml";
var map = new Map({
basemap: "streets"
});
var view = new SceneView({
container: "viewDiv",
map: map,
zoom: 6,
center: [-108.663, 42.68]
});
view.then(function() {
return esriRequest({
url: serviceUrl,
content: {
url: kmlUrl
}
})
}).then(function(response) {
// works, but errors on empty features
/*
var layers = response.featureCollection.layers;
var kml = new GroupLayer({
layers: layers.map(function(x) {
return new FeatureLayer(x);
})
});
map.add(kml);
*/
// remove featureSets with empty features
var layers = response.featureCollection.layers.filter(function(x) {
return x.featureSet.features.length;
});
var kml = new GroupLayer({
layers: layers.map(function(x) {
return new FeatureLayer(x);
})
});
map.add(kml);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment