@SuppressWarnings("rawtypes")
  private void setPosition() {
    Coordinates coor;
    try {
      coor = GeoCoder.getGeoCoordinates(company.getAddress());

      double latitude = Double.parseDouble(coor.getLatitude());
      double longitude = Double.parseDouble(coor.getLongitude());
      position = new GeoPosition(latitude, longitude);
      jXMapKit.setAddressLocation(position);

      Set<Waypoint> waypoints = new HashSet<Waypoint>();
      waypoints.add(new Waypoint(latitude, longitude));

      WaypointPainter<?> painter = new WaypointPainter();
      painter.setWaypoints(waypoints);
      //	        painter.setRenderer(new WaypointRenderer() {
      //	            public boolean paintWaypoint(Graphics2D g, JXMapViewer map, Waypoint wp) {
      //	                g.setColor(Color.RED);
      //	                g.drawLine(-5,-5,+5,+5);
      //	                g.drawLine(-5,+5,+5,-5);
      //	                return true;
      //	            }
      //	        });

      jXMapKit.getMainMap().setOverlayPainter(painter);
      jXMapKit.getMainMap().setZoom(2);
      jXMapKit.setAddressLocationShown(true);
      jXMapKit.setCenterPosition(position);
      jXMapKit.setDataProviderCreditShown(true);
    } catch (NonExistentAddressException e) {
      JOptionPane.showMessageDialog(
          this,
          e.getMessage(),
          ApplicationInternationalization.getString("Error"),
          JOptionPane.ERROR_MESSAGE);
    } catch (WSResponseException e) {
      JOptionPane.showMessageDialog(
          this,
          e.getMessage(),
          ApplicationInternationalization.getString("Error"),
          JOptionPane.ERROR_MESSAGE);
    } catch (IOException e) {
      JOptionPane.showMessageDialog(
          this,
          e.getMessage(),
          ApplicationInternationalization.getString("Error"),
          JOptionPane.ERROR_MESSAGE);
    } catch (JDOMException e) {
      JOptionPane.showMessageDialog(
          this,
          e.getMessage(),
          ApplicationInternationalization.getString("Error"),
          JOptionPane.ERROR_MESSAGE);
    }
  }
示例#2
0
  private void jButton1ActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jButton1ActionPerformed
    try {
      if (query.getText().split(",").length < 3) {
        JOptionPane.showMessageDialog(this, "You must use the format: street, city, state");
        return;
      }
      GeoPosition gp = GeoUtil.getPositionForAddress(query.getText().split(","));
      Set<Waypoint> wps = new HashSet<Waypoint>();
      wps.add(new Waypoint(gp));

      waypointPainter.setWaypoints(wps);
      kit.setCenterPosition(gp);
    } catch (IOException ex) {
      ex.printStackTrace();
    }

    // TODO add your handling code here:
  } // GEN-LAST:event_jButton1ActionPerformed
示例#3
0
  /** Creates new form WorldMapForm */
  public WorldMapForm() {
    waypointPainter = new WaypointPainter();
    waypointPainter.setRenderer(new DefaultWaypointRenderer());

    RectanglePainter rp = new RectanglePainter(120, 25, 10, new Color(100, 100, 100, 150));
    rp.setInsets(new Insets(5, 0, 0, 0));
    rp.setVerticalAlignment(RectanglePainter.VerticalAlignment.TOP);
    final TextPainter tp = new TextPainter();
    tp.setInsets(new Insets(10, 0, 0, 0));
    tp.setText("stuff");
    tp.setFillPaint(Color.WHITE);
    tp.setVerticalAlignment(TextPainter.VerticalAlignment.TOP);

    initComponents();
    /*
    kit.setTileFactory(new CylindricalProjectionTileFactory(new SLMapServerInfo(
            "file:/Users/joshy/projects/java.net/ImageTileCutter/big_tiles_26000")));
    */
    kit.getMainMap().setOverlayPainter(new CompoundPainter(waypointPainter, rp, tp));
    kit.getMainMap()
        .addMouseMotionListener(
            new MouseMotionAdapter() {
              public void mouseMoved(MouseEvent e) {

                // get the screen point
                Point pt = e.getPoint();
                JXMapViewer map = kit.getMainMap();
                // u.p("pos = " + e.getPoint());
                // convert to world bitmap coords
                Rectangle rect = map.getViewportBounds();
                // u.p("rect = " + rect);
                pt.setLocation(rect.getX() - pt.getX(), rect.getY() - pt.getY());
                // u.p("pt = " + pt);
                // convert to geoposition
                GeoPosition gp = map.getTileFactory().pixelToGeo(pt, map.getZoom());
                u.p("gp " + gp);
                DecimalFormat fmt = new DecimalFormat("#00.000");
                tp.setText(fmt.format(gp.getLatitude()) + " , " + fmt.format(gp.getLongitude()));
                map.repaint();
              }
            });
  }