Package chunmap.app.tools.create

Source Code of chunmap.app.tools.create.AreaTool

/**
* 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.app.tools.create;

import chunmap.model.coord.CoordSeqEditor;
import chunmap.model.geom.GeometryException;
import chunmap.model.geom.Polygon;
import chunmap.model.geom.Ring;

public class AreaTool extends LineTool{
  protected @Override void finished(CoordSeqEditor lse)
    {
        if (onCreateFinish != null)
        {
            lse.close();
            Ring ls = null;
            try
            {
                ls = new Ring(lse.toCoordinateSeq());
            }
            catch(GeometryException ex) {
              ex.printStackTrace();
              return;
            }
            onCreateFinish.fire(new Polygon(ls));
        }
    }
  @Override
  protected int[] toXa(int lastX) {
    int[] ps = new int[lse.size() + 2];

    for (int i = 0, n = lse.size(); i < n; i++) {
      double p = map.getView().x2Screen(lse.getPoint(i).getX());
      ps[i] = (int) p;
    }
    ps[lse.size()] = lastX;
    double p= map.getView().x2Screen(lse.firstPoint().getX());
    ps[lse.size() + 1] =(int)p;

    return ps;
  }
  @Override
  protected int[] toYa(int lastY) {
    int[] ps = new int[lse.size() + 2];

    for (int i = 0, n = lse.size(); i < n; i++) {
      double p = map.getView().y2Screen(lse.getPoint(i).getY());
      ps[i] = (int) p;
    }
    ps[lse.size()] = lastY;
    double p= map.getView().y2Screen(lse.firstPoint().getY());
    ps[lse.size() + 1] =(int)p;

    return ps;
  }
}
TOP

Related Classes of chunmap.app.tools.create.AreaTool

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.