예제 #1
0
 /** @param ev */
 @Override
 public void onMouseReleased(MapMouseEvent ev) {
   // avoid the zooming window at the time scroll button pan action.
   if (dragged
       && !ev.getPoint().equals(startDragPos)
       && ev.getButton() != java.awt.event.MouseEvent.BUTTON2) {
     dragged = false;
     Envelope2D env = new Envelope2D();
     env.setFrameFromDiagonal(startDragPos, ev.getWorldPos());
     this.onRectangleFinished(env);
   }
 }
 /**
  * If a new click is done while creating a cadastre object, it has to snap to a point. Because the
  * only layer used as snaptarget is the NewSurveyPointLayer the only points are the survey points.
  *
  * @param ev
  */
 @Override
 public void onMouseClicked(MapMouseEvent ev) {
   if (ev.getButton() == java.awt.event.MouseEvent.BUTTON1
       && this.getSnappedTarget() != SNAPPED_TARGET_TYPE.Vertex) {
     Messaging.getInstance().show(GisMessage.CADASTRE_CHANGE_NEW_CO_MUST_SNAP);
     return;
   }
   super.onMouseClicked(ev);
 }
예제 #3
0
 /**
  * Records the map position of the mouse event in case this button press is the beginning of a
  * mouse drag
  *
  * @param ev the mouse event
  */
 @Override
 public void onMousePressed(MapMouseEvent ev) {
   startDragPos.setLocation(ev.getWorldPos());
 }
예제 #4
0
  /**
   * This method is called by our feature selection tool when the user has clicked on the map.
   *
   * @param pos map (world) coordinates of the mouse cursor
   */
  void selectFeatures(MapMouseEvent ev) {

    System.out.println("Mouse click at: " + ev.getMapPosition());

    /*
     * Construct a 5x5 pixel rectangle centred on the mouse click position
     */
    Point screenPos = ev.getPoint();
    Rectangle screenRect = new Rectangle(screenPos.x - 2, screenPos.y - 2, 5, 5);

    /*
     * Transform the screen rectangle into bounding box in the coordinate
     * reference system of our map context. Note: we are using a naive method
     * here but GeoTools also offers other, more accurate methods.
     */
    AffineTransform screenToWorld = mapFrame.getMapPane().getScreenToWorldTransform();
    Rectangle2D worldRect = screenToWorld.createTransformedShape(screenRect).getBounds2D();
    ReferencedEnvelope bbox =
        new ReferencedEnvelope(
            worldRect,
            //             mapFrame.getMapContext().getCoordinateReferenceSystem());
            //             这里有点问题,需调整
            mapFrame.getMapContent().getCoordinateReferenceSystem());

    /*
     * Create a Filter to select features that intersect with
     * the bounding box
     */
    Filter filter = ff.intersects(ff.property(geometryAttributeName), ff.literal(bbox));

    // ff.bbox(ff.property(geometryAttributeName), bbox);

    /*
     * Use the filter to identify the selected features
     */
    try {
      FeatureCollection<SimpleFeatureType, SimpleFeature> selectedFeatures =
          featureSource.getFeatures(filter);

      FeatureIterator<SimpleFeature> iter = selectedFeatures.features();
      Set<FeatureId> IDs = new HashSet<FeatureId>();
      try {
        while (iter.hasNext()) {
          SimpleFeature feature = iter.next();
          IDs.add(feature.getIdentifier());

          System.out.println("   " + feature.getIdentifier());
        }

      } finally {
        iter.close();
      }

      if (IDs.isEmpty()) {
        System.out.println("   no feature selected");
      }

      displaySelectedFeatures(IDs);

    } catch (Exception ex) {
      ex.printStackTrace();
      return;
    }
  }