清除地图中的所有图层和FileFilter的使用

清除图层中所有图层的代码如下:

IActiveView activeView = mainMapBean.getActiveView();   //获取当前地图的视图

activeView.clear();                                                                        //清除地图中的图层

activeView.refresh();                                                                    //刷新当前视图

新建一个对话框的过滤的类

import javax.swing.filechooser.FileFilter;

import javax.swing.filechooser.FileNameExtensionFilter;

public class MapFileFilter{

public FileFilter createFileFilter(String description, String...extensions) {

  description = createFileNameFilterDescriptionFromExtensions(

    description, extensions);

  return new FileNameExtensionFilter(description, extensions);

}

private String createFileNameFilterDescriptionFromExtensions(

   String description, String[] extensions) {

  String fullDescription = (description == null) ?

    "(" : description + " (";

    // build the description from the extension list

  fullDescription += "." + extensions[0];

  for (int i = 1; i < extensions.length; i++) {

   fullDescription += ", .";

   fullDescription += extensions[i];

  }

  fullDescription += ")";

  return fullDescription;

}

}

通过调用createFileFilter方法来实现添加过滤

MapFileFilter fileFilter = new MapFileFilter();

fileChooser.resetChoosableFileFilters();

FileFilter mxdFilter = fileFilter.createFileFilter("ESRI地图文档","mxd");

fileChooser.addChoosableFileFilter(mxdFilter);

fileChooser.showOpenDialog(this);

posted @ 2010-02-28 13:43  iLocationStudio  阅读(341)  评论(0编辑  收藏  举报