Ejemplo n.º 1
0
  /**
   * Replace a layer identified by its name, by another.
   *
   * @param layerName the name of the layer to be replaced
   * @param layer the new layer
   */
  public void replaceLayer(String layerName, FLayer layer) throws LoadLayerException {
    FLayer lyr;
    FLayer parent;
    for (int i = 0; i < layers.size(); i++) {
      lyr = ((FLayer) layers.get(i));

      if (lyr.getName().compareToIgnoreCase(layerName) == 0) {
        parent = lyr.getParentLayer();
        removeLayer(i);
        if (parent != null) {
          // Notificamos a la capa que va a ser añadida
          if (layer instanceof FLyrDefault) {
            ((FLyrDefault) layer).wakeUp();
          }
        }

        if (layer instanceof FLayers) {
          FLayers layers = (FLayers) layer;
          fmap.addAsCollectionListener(layers);
        }
        callLayerAdding(LayerCollectionEvent.createLayerAddingEvent(layer));

        layers.add(i, layer);
        layer.setParentLayer(this);

        callLayerAdded(LayerCollectionEvent.createLayerAddedEvent(layer));
        break;
      }
    }
  }
Ejemplo n.º 2
0
  /**
   * Adds a layer in an specified position in this node.
   *
   * @param layer a layer
   */
  public void addLayer(int pos, FLayer layer) {
    try {
      // Notificamos a la capa que va a ser añadida
      if (layer instanceof FLyrDefault) {
        ((FLyrDefault) layer).wakeUp();
      }

      if (layer instanceof FLayers) {
        FLayers layers = (FLayers) layer;
        fmap.addAsCollectionListener(layers);
      }
      callLayerAdding(LayerCollectionEvent.createLayerAddingEvent(layer));

      doAddLayer(pos, layer);

      callLayerAdded(LayerCollectionEvent.createLayerAddedEvent(layer));
    } catch (CancelationException e) {
      logger.warn(e.getMessage());
    } catch (LoadLayerException e) {
      layer.setAvailable(false);
      layer.addError(e);
    }
  }