Hi Ryan,
Not sure if it's too late on this one but here's what I did for file based datasets (kml/kmz and shapefiles):
1. Use the DocumentDialog type. It's in beta and doesn't allow you to filter by file extensions (lol) -
FileInfo {
id: fileInfo
}
DocumentDialog {
id: fileDialog
onAccepted: {
// add the attachment to the feature table
fileInfo.url = filePath
var lyr = createFromFile(fileInfo);
mapView.map.operationalLayers.append(lyr);
}
}
function createFromFile(file_info) {
//read file extension - is it .shp or .kml/kmz?
var ext = file_info.suffix
var file_path = file_info.url
if (ext === 'kml' || ext === 'kmz') {
// create the dataset from a local file
const kmlDataset = ArcGISRuntimeEnvironment.createObject("KmlDataset", {
//url: AppFramework.userHomeFolder.fileUrl(caKmlPath + "/SubDivs.kmz")
url: file_path
});
// create the layer
const kmlLayer = ArcGISRuntimeEnvironment.createObject("KmlLayer", {
dataset: kmlDataset
});
// return the KML Layer
return kmlLayer;
}
if (ext === 'shp') {
const shpFeatTbl = ArcGISRuntimeEnvironment.createObject("ShapefileFeatureTable", {
path: file_path
});
const shpLyr = ArcGISRuntimeEnvironment.createObject("FeatureLayer", {
featureTable: shpFeatTbl
});
return shpLyr;
}
}
2. Enable drag and drop on the map. This was awesome!
DropArea {
id: dropOnMap
anchors.fill: parent
FileInfo {
id: dropFileInfo
}
onEntered: {
if (drag.urls.length === 1) {
// verify that this file exists
dropFileInfo.url = drag.urls[0];
if (dropFileInfo.exists) {
if (validateFileExtension()) { //just checks for kml/kmz + .shp
drag.accept();
}
else {
console.log("Not KML/KMZ or Shp");
}
}
}
}
onDropped: {
if (validateFileExtension()) {
var droplyr = createFromFile(dropFileInfo);
mapView.map.operationalLayers.append(droplyr);
}
}
Best of luck w/your work!
Rob