Пример #1
0
 /** Zoom and position the map in order to see everything. */
 public void showAllMap() {
   transformer.resetAutoScale();
   try {
     transformer.adjustAutoScaleFromWgs84(
         CoordUtils.toWGS84Rad(map.getMinLongitude()),
         CoordUtils.toWGS84Rad(map.getMinLatitude()));
     transformer.adjustAutoScaleFromWgs84(
         CoordUtils.toWGS84Rad(map.getMaxLongitude()),
         CoordUtils.toWGS84Rad(map.getMaxLatitude()));
   } catch (IOException e) {
     e.printStackTrace();
   }
   transformer.fixAspectRatio();
   transformerChanged();
 }
Пример #2
0
  public void saveMapAs(
      final File selectedFile, FileExporter exporter, MapTransformer<COORD> transformer)
      throws IOException {
    exporter.setup(selectedFile, transformer.getWidth(), transformer.getHeight());
    final Graphics2D g2 = exporter.getG2();

    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setColor(MapPanel.BG_COLOR);
    g2.fillRect(0, 0, transformer.getWidth(), transformer.getHeight());

    Rectangle bbox = transformer.getGarminBoundingBox();
    int minLon = bbox.x;
    int maxLon = bbox.x + bbox.width;
    int minLat = bbox.y;
    int maxLat = bbox.y + bbox.height;
    int resolution = getResolution(minLon, maxLon, transformer.getWidth());
    TransformedMapListener drawer =
        createMapDrawer(new MapConfig(), g2, exporter.getFontSize(), transformer);
    MapListener listener =
        new CoordinateConverterListener<COORD>(
            transformer,
            new ClippingMapListener(0, transformer.getWidth(), 0, transformer.getHeight(), drawer));

    map.readMapForDrawing(minLon, maxLon, minLat, maxLat, resolution, ObjectKind.ALL, listener);
    exporter.finishSave();
  }
Пример #3
0
  public String getInfo(int x, int y, int maxNbInfo) {
    Point2D.Double wgs84 = new Point2D.Double();
    transformer.map2wgs84(x, y, wgs84);

    Point2D.Double wgs84Precision = new Point2D.Double();
    transformer.map2wgs84(x + 5, y, wgs84Precision);

    int longitude = CoordUtils.fromWGS84Rad(wgs84.x);
    int latitude = CoordUtils.fromWGS84Rad(wgs84.y);

    int precision =
        Math.max(
            Math.abs(longitude - CoordUtils.fromWGS84Rad(wgs84Precision.x)),
            Math.abs(latitude - CoordUtils.fromWGS84Rad(wgs84Precision.y)));

    try {
      FindObjectByPositionListener listener =
          new FindObjectByPositionListener(longitude, latitude, precision);

      int resolution = getResolution(transformer);
      map.readMapForDrawing(
          longitude, longitude, latitude, latitude, resolution, ObjectKind.ALL, listener);

      List<FoundObject> founds = listener.getFounds();
      if (founds.isEmpty()) return null;
      StringBuilder buffer = new StringBuilder("<html>\n<ul>\n");
      for (int i = founds.size() - 1; i >= Math.max(0, founds.size() - maxNbInfo); i--) {
        FoundObject found = founds.get(i);
        buffer.append("  <li>");
        found.toDebugHtml(buffer);
        buffer.append("</li>\n");
      }
      buffer.append("</ul>\n</html>\n");
      return buffer.toString();
    } catch (IOException e) {
      e.printStackTrace();
      return null;
    }
  }
Пример #4
0
 public void clearMaps() throws IOException {
   map.clear();
   thread.scheduleComputeMap();
 }
Пример #5
0
 public void addMapLocation(File location) throws IOException {
   if (location.isDirectory()) map.addDirectory(location);
   else map.addFile(location);
   thread.scheduleComputeMap();
 }