private void OnSaveAs(object obj)
{
var dlg = new GRSaveAsFormatView();
dlg.DataContext = new SaveAsFormatViewModel();
var vm = dlg.DataContext as SaveAsFormatViewModel;
if (dlg.ShowDialog() == true)
{
IFeatureClass fc = null;
// Get the graphics list for the selected tab
List<Graphic> typeGraphicsList = new List<Graphic>();
if (this is LinesViewModel)
{
typeGraphicsList = GraphicsList.Where(g => g.GraphicType == GraphicTypes.Line).ToList();
}
else if (this is CircleViewModel)
{
typeGraphicsList = GraphicsList.Where(g => g.GraphicType == GraphicTypes.Circle).ToList();
}
else if (this is EllipseViewModel)
{
typeGraphicsList = GraphicsList.Where(g => g.GraphicType == GraphicTypes.Ellipse).ToList();
}
else if (this is RangeViewModel)
{
typeGraphicsList = GraphicsList.Where(g => g.GraphicType == GraphicTypes.RangeRing).ToList();
}
string path = null;
if (vm.FeatureShapeIsChecked)
{
path = fcUtils.PromptUserWithGxDialog(ArcMap.Application.hWnd);
if (path != null)
{
if (System.IO.Path.GetExtension(path).Equals(".shp"))
{
fc = fcUtils.CreateFCOutput(path, SaveAsType.Shapefile, typeGraphicsList, ArcMap.Document.FocusMap.SpatialReference);
}
else
{
fc = fcUtils.CreateFCOutput(path, SaveAsType.FileGDB, typeGraphicsList, ArcMap.Document.FocusMap.SpatialReference);
}
}
}
else
{
path = PromptSaveFileDialog();
if (path != null)
{
string kmlName = System.IO.Path.GetFileName(path);
string folderName = System.IO.Path.GetDirectoryName(path);
string tempShapeFile = folderName + "\\tmpShapefile.shp";
IFeatureClass tempFc = fcUtils.CreateFCOutput(tempShapeFile, SaveAsType.Shapefile, typeGraphicsList, ArcMap.Document.FocusMap.SpatialReference);
if (tempFc != null)
{
kmlUtils.ConvertLayerToKML(path, tempShapeFile, ArcMap.Document.FocusMap);
// delete the temporary shapefile
fcUtils.DeleteShapeFile(tempShapeFile);
}
}
}
if (fc != null)
{
IFeatureLayer outputFeatureLayer = new FeatureLayerClass();
outputFeatureLayer.FeatureClass = fc;
IGeoFeatureLayer geoLayer = outputFeatureLayer as IGeoFeatureLayer;
geoLayer.Name = fc.AliasName;
ESRI.ArcGIS.Carto.IMap map = ArcMap.Document.FocusMap;
map.AddLayer((ILayer)outputFeatureLayer);
}
}
}