Esempio n. 1
0
 /** Unit test of {@link WMSLayer#WMSLayer}. */
 @Test
 public void testWMSLayer() {
   WMSLayer wms = new WMSLayer(new ImageryInfo("test wms", "http://localhost"));
   Main.getLayerManager().addLayer(wms);
   try {
     assertEquals(ImageryType.WMS, wms.getInfo().getImageryType());
   } finally {
     // Ensure we clean the place before leaving, even if test fails.
     Main.getLayerManager().removeLayer(wms);
   }
 }
Esempio n. 2
0
 /**
  * Adds the specified GPX and marker layers to Map.main
  *
  * @param data The layers to add
  * @see #loadLayers
  */
 public static void addLayers(final GpxImporterData data) {
   // FIXME: remove UI stuff from the IO subsystem
   GuiHelper.runInEDT(
       () -> {
         if (data.markerLayer != null) {
           Main.getLayerManager().addLayer(data.markerLayer);
         }
         if (data.gpxLayer != null) {
           Main.getLayerManager().addLayer(data.gpxLayer);
         }
         data.postLayerTask.run();
       });
 }
 /** Gets the elevation profile layer which decorates the current layer with some markers. */
 public static ElevationProfileLayer getCurrentLayer() {
   if (currentLayer == null) {
     currentLayer = new ElevationProfileLayer(tr("Elevation Profile"));
     Main.getLayerManager().addLayer(currentLayer);
   }
   return currentLayer;
 }
  /**
   * find which gpx layer holds the trace to upload. layers are tried in this order:
   *
   * <p>1. selected (*not* active - think "zoom to layer"), from first to last 2. not selectd - if
   * there is only one 3. active
   *
   * @return data of the selected gpx layer, or null if there is none
   */
  GpxData autoSelectTrace() {
    if (Main.map != null && Main.map.mapView != null) {
      MainLayerManager lm = Main.getLayerManager();
      //            List<Layer> allLayers = new ArrayList<Layer>(mv.getAllLayersAsList());  //
      // modifiable
      List<Layer> selectedLayers = LayerListDialog.getInstance().getModel().getSelectedLayers();
      List<GpxLayer> gpxLayersRemaining = lm.getLayersOfType(GpxLayer.class);
      gpxLayersRemaining.removeAll(selectedLayers);
      GpxLayer traceLayer = null;
      // find the first gpx layer inside selected layers
      for (Layer l : LayerListDialog.getInstance().getModel().getSelectedLayers()) {
        if (l instanceof GpxLayer) {
          traceLayer = (GpxLayer) l;
          break;
        }
      }
      if (traceLayer == null) {
        // if there is none, try the none selected gpx layers. if there is only one, use it.
        if (gpxLayersRemaining.size() == 1) {
          traceLayer = gpxLayersRemaining.get(0);
        }
        // active layer
        else if (lm.getActiveLayer() instanceof GpxLayer) {
          traceLayer = (GpxLayer) lm.getActiveLayer();
        }
      }

      if (traceLayer != null) {
        return traceLayer.data;
      }
    }

    return null;
  }
 @Override
 public void enterMode() {
   super.enterMode();
   if (!hasImageryLayersToAdjust()) {
     warnNoImageryLayers();
     return;
   }
   List<ImageryLayer> layers = Main.getLayerManager().getLayersOfType(ImageryLayer.class);
   if (layers.size() == 1) {
     adjustingLayer = layers.get(0);
   } else {
     adjustingLayer = (ImageryLayer) askAdjustLayer(getVisibleLayers());
   }
   if (adjustingLayer == null) return;
   if (!adjustingLayer.isVisible()) {
     adjustingLayer.setVisible(true);
   }
   Main.map.mapView.addMouseListener(this);
   Main.map.mapView.addMouseMotionListener(this);
   listener =
       new TimedKeyReleaseListener() {
         @Override
         protected void doKeyReleaseEvent(KeyEvent evt) {
           if (releaseEvent.getKeyCode() == getShortcut().getKeyStroke().getKeyCode()) {
             if (oldMapMode != null && !(oldMapMode instanceof ImageryAdjustMapMode))
               Main.map.selectMapMode(oldMapMode);
           }
         }
       };
 }
 /**
  * Constructs a new <code>RecentRelationsAction</code>.
  *
  * @param editButton edit button
  */
 public RecentRelationsAction(SideButton editButton) {
   this.editButton = editButton;
   arrow = editButton.createArrow(this);
   arrow.setToolTipText(tr("List of recent relations"));
   Main.main.undoRedo.addCommandQueueListener(this);
   Main.getLayerManager().addLayerChangeListener(this);
   Main.getLayerManager().addActiveLayerChangeListener(this);
   enableArrow();
   shortcut =
       Shortcut.registerShortcut(
           "relationeditor:editrecentrelation",
           tr("Relation Editor: {0}", tr("Open recent relation")),
           KeyEvent.VK_ESCAPE,
           Shortcut.SHIFT);
   Main.registerActionShortcut(new LaunchEditorAction(), shortcut);
 }
 private List<? extends Layer> getVisibleLayers() {
   List<? extends Layer> all =
       new ArrayList<Layer>(Main.getLayerManager().getLayersOfType(ImageryLayer.class));
   Iterator<? extends Layer> it = all.iterator();
   while (it.hasNext()) {
     if (!it.next().isVisible()) it.remove();
   }
   return all;
 }
 /**
  * Returns the list of recent relations on active layer.
  *
  * @return the list of recent relations on active layer
  */
 public static List<Relation> getRecentRelationsOnActiveLayer() {
   if (!Main.isDisplayingMapView()) return Collections.emptyList();
   Layer activeLayer = Main.getLayerManager().getActiveLayer();
   if (!(activeLayer instanceof OsmDataLayer)) {
     return Collections.emptyList();
   } else {
     return ((OsmDataLayer) activeLayer).getRecentRelations();
   }
 }
Esempio n. 9
0
 @Override
 public void startTest(ProgressMonitor monitor) {
   super.startTest(monitor);
   ways = new HashSet<>();
   endnodes = new QuadBuckets<>();
   endnodesHighway = new QuadBuckets<>();
   middlenodes = new QuadBuckets<>();
   othernodes = new HashSet<>();
   mindist = Main.pref.getDouble(PREFIX + ".node_way_distance", 10.0);
   minmiddledist = Main.pref.getDouble(PREFIX + ".way_way_distance", 0.0);
   DataSet dataSet = Main.getLayerManager().getEditDataSet();
   dsArea = dataSet == null ? null : dataSet.getDataSourceArea();
 }
 @Override
 public Iterable<Way> getWays() {
   return new FilteredOsmPrimitiveIterable<>(Main.getLayerManager().getEditDataSet().getWays());
 }
 @Override
 public Iterable<Relation> getRelations() {
   return new FilteredRelationIterable(Main.getLayerManager().getEditDataSet().getRelations());
 }
 /**
  * Replies true if there is at least one imagery layer
  *
  * @return true if there is at least one imagery layer
  */
 protected boolean hasImageryLayersToAdjust() {
   if (Main.map == null) return false;
   if (Main.map.mapView == null) return false;
   boolean b = !Main.getLayerManager().getLayersOfType(ImageryLayer.class).isEmpty();
   return b;
 }
 protected boolean isActiveLayer(Layer layer) {
   if (Main.map == null) return false;
   if (Main.map.mapView == null) return false;
   return Main.getLayerManager().getActiveLayer() == layer;
 }
Esempio n. 14
0
 static SearchTask newSearchTask(SearchSetting setting, SearchReceiver resultReceiver) {
   final DataSet ds = Main.getLayerManager().getEditDataSet();
   return newSearchTask(setting, ds, resultReceiver);
 }
 /**
  * Determines if the given relation is listable in last relations.
  *
  * @param relation relation
  * @return {@code true} if relation is non null, not deleted, and in current dataset
  */
 public static boolean isRelationListable(Relation relation) {
   return relation != null
       && !relation.isDeleted()
       && Main.getLayerManager().getEditDataSet().containsRelation(relation);
 }