Package chunmap.example.layer

Source Code of chunmap.example.layer.ShapefileTest

/**
* Copyright (c) 2009-2011, chunquedong(YangJiandong)
*
* This file is part of ChunMap project
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE(Version >=3)
*
* History:
*     2010-05-05  Jed Young  Creation
*/
package chunmap.example.layer;

import java.util.List;

import javax.swing.JTextArea;

import chunmap.app.MapCtrl;
import chunmap.data.feature.Feature;
import chunmap.data.provider.LayerFactory;
import chunmap.example.BaseMap;
import chunmap.util.Function;
import chunmap.view.layer.VectorLayer;
import chunmap.view.render.GeneralSymbol;
import chunmap.view.render.LabelSymbol;
import chunmap.view.render.Style2D;
import chunmap.view.render.Symbol;

/**
* read shapefile and show data
*
* @author chunquedong
*
*/
public class ShapefileTest extends BaseMap {
  public static void main(String[] args) {

    ShapefileTest me = new ShapefileTest();
    me.init();
  }

  @Override
  protected void addLayer(MapCtrl map) {
    String path1=
        "D:\\Temp\\gs\\region.shp";
    String path2=
        "D:\\Temp\\gs\\city1.shp";
    String path3=
        "D:\\Temp\\gs\\river.shp";

    VectorLayer layer =  LayerFactory.openShapeFile(path1,1);
    layer.setDefaultStyle(new Symbol[]{new GeneralSymbol(),new LabelSymbol()});
    VectorLayer layer2 =  LayerFactory.openShapeFile(path2);
    layer2.setDefaultStyle(new Symbol[]{new GeneralSymbol(Style2D.style2())});
    VectorLayer layer3 =  LayerFactory.openShapeFile(path3);
    layer3.setDefaultStyle(new Symbol[]{new GeneralSymbol(Style2D.style1())});

    map.getLayerCollection().add(layer);
    map.getLayerCollection().add(layer2);
    map.getLayerCollection().add(layer3);
  }
 
  @Override
  protected void addButton(){
    super.addButton();
   
    final JTextArea text=new JTextArea(5,70);
    text.setLineWrap(true);
    text.setAutoscrolls(true);
   
    frame.add(text);
   
    tool.onSelectChange.add(new Function(){
      @SuppressWarnings("unchecked")
      @Override
      public Object call(Object... args) {
        List<Feature> fs=(List<Feature>)args[0];
        if(fs.size()==0){
          text.setText("");
        }else{
          text.setText(fs.get(0).toString());
        }
        return null;
      }});
  }
}
TOP

Related Classes of chunmap.example.layer.ShapefileTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.