SVG is an XML-based file format that has been specifically designed for viewing on the Web.
SVG can contain both vector and raster information. This is a good choice for displaying maps on a web page because it is rescalable and more easily edited than raster files.
SVG has been gaining in popularity since the World Wide Web Consortium (W3C) selected it as their standard vector Web format.
Some Web browsers may require a plug-in to view SVG files; older browsers may not be able to view SVG files at all.
//This example demonstrates how to export a layout to SVG.
//Added references
using ArcGIS.Desktop.Core; //Project
using ArcGIS.Desktop.Layouts; //Layout classes
using ArcGIS.Desktop.Framework.Threading.Tasks; //QueuedTask
using ArcGIS.Desktop.Mapping; //Export formats
publicclass ExportLayoutToSVGExample
{
publicstatic Task ExportLayoutToSVGAsync(string LayoutName, string Path)
{
//Reference a layoutitem in a project by name
LayoutProjectItem layoutItem = Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals(LayoutName));
if (layoutItem == null)
return Task.FromResult<Layout>(null);
//Create SVG format with appropriate settings
SVGFormat SVG = new SVGFormat();
SVG.Resolution = 300;
SVG.OutputFileName = Path;
return QueuedTask.Run(() =>
{
//Export Layout
Layout lyt = layoutItem.GetLayout(); //Loads and returns the layout associated with a LayoutItem
if (SVG.ValidateOutputFilePath())
{
lyt.Export(SVG);
}
});
}
}
//This example demonstrates how to export an individual map frame on a layout to SVG.
//Added references
using ArcGIS.Desktop.Core; //Project
using ArcGIS.Desktop.Layouts; //Layout classes
using ArcGIS.Desktop.Framework.Threading.Tasks; //QueuedTask
using ArcGIS.Desktop.Mapping; //Export formats
publicclass ExportMapFrameToSVGExample
{
publicstatic Task ExportMapFrameToSVGAsync(string LayoutName, string MFName, string Path)
{
//Reference a layoutitem in a project by name
LayoutProjectItem layoutItem = Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals(LayoutName));
if (layoutItem == null)
return Task.FromResult<Layout>(null);
//Create SVG format with appropriate settings
SVGFormat SVG = new SVGFormat();
SVG.Resolution = 300;
SVG.OutputFileName = Path;
return QueuedTask.Run(() =>
{
//Export MapFrame
Layout lyt = layoutItem.GetLayout(); //Loads and returns the layout associated with a LayoutItem
MapFrame mf = lyt.FindElement(MFName) as MapFrame;
SVG.OutputFileName = Path;
if (SVG.ValidateOutputFilePath())
{
mf.Export(SVG);
}
});
}
}
//This example demonstrates how to export the active mapview to SVG.
//Added references
using ArcGIS.Desktop.Framework.Threading.Tasks; //QueuedTask
using ArcGIS.Desktop.Mapping; //MapView and Export formats
publicclass ExportActiveMapToSVGExample
{
publicstatic Task ExportActiveMapToSVGAsync(string Path)
{
return QueuedTask.Run(() =>
{
//Reference the active map view
MapView mapv = MapView.Active;
//Create SVG format with appropriate settings
SVGFormat SVG = new SVGFormat();
SVG.Resolution = 300;
SVG.Height = 500;
SVG.Width = 800;
SVG.OutputFileName = Path;
//Export active map view
if (SVG.ValidateOutputFilePath())
{
mapv.Export(SVG);
}
});
}
}