Skip to content

Instantly share code, notes, and snippets.

@odoe

odoe/esrijs4kml.js

Created Dec 15, 2015
Embed
What would you like to do?
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