You are right, the KML Layer requires a KML hosted on a URL. So, assuming you have ArcGIS Server, you can get around this...I was able to implement the uploading of KML/KMZ files by publishing a geoprocessing task on my ArcGIS Server. This is basically a Modelbuilder model that takes a KML file and converts it to a feature layer. When published as a GP Service, this feature layer is then available on the server and can be added as a dynamic service layer. Here's what my model looks like:[ATTACH=CONFIG]34470[/ATTACH]You can use esri/request to upload\retrieve the file from the server.var uploadKml = new esriRequest({
url: config.KML_Conv + "/GPServer/uploads/upload",
form: dom.byId('uploadForm'),
content: { "f": "json" }
});
uploadKml.then(
function(response) {
var random = (new Date()).getTime();
var itemID = response.item.itemID;
var kmlTask = new Geoprocessor(config.KML_Conv + "/GPServer/KML_Conv3");
var dataFile = new DataFile();
dataFile.itemID = itemID;
var params = {"KML": dataFile };
kmlTask.outSpatialReference = map.spatialReference;
//pass file name and random ID to callbacks for reference. Note: cannot set ID to filename due to use of spaces or special chars
var args = { fileName: response.item.itemName, random: random };
kmlTask.submitJob(params, lang.hitch(args, completeCallback), lang.hitch(args, statusCallback), lang.hitch(args,errCallback));
},
function (error) {
console.log("An error has occured: " + error);
});
}
Here's the callback:function completeCallback(jobInfo){
var kmlURL = config.KML_Conv + "/MapServer/jobs/";
var kmlLayer = new ArcGISDynamicMapServiceLayer(kmlURL + jobInfo.jobId);
map.addLayer(kmlLayer);
$(".alert button#" + jobInfo.jobId).one("click", function() {
map.removeLayer(kmlLayer);
});
//zoom to new layer
on(kmlLayer, "Load", function() {
map.setExtent(kmlLayer.fullExtent, true);
});
}
Here's some more information on GP services: http://resources.arcgis.com/en/help/main/10.1/index.html#//00570000005w000000You could presumably publish another Model as a Geoprocessing Task that handles CSV files in the same fashion...