use of com.esri.arcgis.carto.IActiveView in project sldeditor by robward-scisys.
the class ImportMXD method convert.
/**
* Read mxd and write out the json file.
*
* @param fileData the file data
*/
public void convert(FileData fileData) {
if (fileData == null) {
return;
}
// Get all the known conversion classes
RegisterClasses.initialise(data);
System.out.println("Reading MXD : " + fileData.getInputFile().getAbsolutePath());
SystemWin sWin = new SystemWin();
Pointer obj = sWin.getDesktopWindow();
int hWnd = obj.getInt(0);
try {
System.out.println("Opening mxd...");
IMapDocument mapDocument = new MapDocument();
String password = null;
mapDocument.open(fileData.getInputFile().getAbsolutePath(), password);
IPageLayout iPageLayout = mapDocument.getPageLayout();
IActiveView activeView = (IActiveView) iPageLayout;
IMap iMap = activeView.getFocusMap();
activeView.activate(hWnd);
JsonArray jsonLayerlist = new JsonArray();
int count = 1;
int total = 0;
// Find total number of layers
IEnumLayer layerEnum = iMap.getLayers(null, true);
ILayer layer = layerEnum.next();
while (layer != null) {
layer = layerEnum.next();
total++;
}
// Now work through all the layers
layerEnum = iMap.getLayers(null, true);
layer = layerEnum.next();
ParseLayer parseLayer = new ParseLayer(data);
while (layer != null) {
parseLayer.convertLayer(count, total, jsonLayerlist, layer, (Map) iMap);
layer = layerEnum.next();
count++;
}
JsonObject jsonMXDObject = new JsonObject();
jsonMXDObject.addProperty("mxd", mapDocument.getDocumentFilename());
jsonMXDObject.add("layers", jsonLayerlist);
outputJSON(jsonMXDObject, fileData.getOutputFile());
System.out.println("Written JSON file : " + fileData.getOutputFile().getAbsolutePath());
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
Aggregations