Exemplo n.º 1
0
    @Override
    public void layerRemoved(LayerCollectionEvent e) {
      HashSet<ILayer> newSelection = new HashSet<ILayer>();
      newSelection.addAll(Arrays.asList(selectedLayers));
      ILayer[] affected = e.getAffected();
      for (final ILayer layer : affected) {
        // Check active
        if (activeLayer == layer) {
          setActiveLayer(null);
        }

        // Check selection
        newSelection.remove(layer);
        layer.removeLayerListenerRecursively(openerListener);
        if (isOpen()) {
          try {
            layer.close();
          } catch (LayerException e1) {
            LOGGER.warn(I18N.tr("Cannot close layer {0}", layer.getName()), e1);
          }
        }
      }

      setSelectedLayers(newSelection.toArray(new ILayer[newSelection.size()]));
      // checkIfHasToResetSRID();
    }
Exemplo n.º 2
0
  private OWSContextType createJaxbMapContext() {
    // Create jaxbcontext data
    ObjectFactory ows_context_factory = new ObjectFactory();
    net.opengis.ows._2.ObjectFactory ows_factory = new net.opengis.ows._2.ObjectFactory();

    OWSContextType mapContextSerialisation = ows_context_factory.createOWSContextType();

    // GeneralType
    mapContextSerialisation.setGeneral(ows_context_factory.createGeneralType());

    // GeneralType:Bounding Box
    if (boundingBox != null) {
      BoundingBoxType bbox = ows_factory.createBoundingBoxType();
      bbox.getLowerCorner().add(boundingBox.getMinX());
      bbox.getLowerCorner().add(boundingBox.getMinY());
      bbox.getUpperCorner().add(boundingBox.getMaxX());
      bbox.getUpperCorner().add(boundingBox.getMaxY());
      mapContextSerialisation.getGeneral().setBoundingBox(ows_factory.createBoundingBox(bbox));
    }
    // GeneralType:Title
    Map<Locale, String> titles = description.getTitles();
    if (!titles.isEmpty()) {
      // Take the first one
      for (Entry<Locale, String> entry : titles.entrySet()) {
        LanguageStringType title = ows_factory.createLanguageStringType();
        title.setLang(LocalizedText.toLanguageTag(entry.getKey()));
        title.setValue(entry.getValue());
        mapContextSerialisation.getGeneral().setTitle(title);
        break; // Ows-context does not support multi-lingual
      }
    }
    // GeneralType:Abstract
    Map<Locale, String> abstracts = description.getAbstractTexts();
    if (!abstracts.isEmpty()) {
      // Take the first one
      for (Entry<Locale, String> entry : abstracts.entrySet()) {
        LanguageStringType mapAbstract = ows_factory.createLanguageStringType();
        mapAbstract.setLang(LocalizedText.toLanguageTag(entry.getKey()));
        mapAbstract.setValue(entry.getValue());
        mapContextSerialisation.getGeneral().setAbstract(mapAbstract);
        break; // Ows-context does not support multi-lingual
      }
    }
    // ResourceList
    ResourceListType rs = ows_context_factory.createResourceListType();
    mapContextSerialisation.setResourceList(rs);

    // LayerList
    if (layerModel != null) {
      List<LayerType> rootLayerList = rs.getLayer();
      ILayer[] rootLayers = layerModel.getChildren();
      for (ILayer layer : rootLayers) {
        if (layer.isSerializable()) {
          rootLayerList.add(createJAXBFromLayer(layer, this));
        }
      }
    }
    return mapContextSerialisation;
  }
Exemplo n.º 3
0
 @Override
 public boolean isLayerModelSpatial() {
   ILayer[] layers = getLayers();
   for (ILayer l : layers) {
     if (!l.acceptsChilds()) {
       return true;
     }
   }
   return false;
 }
Exemplo n.º 4
0
 /**
  * Recursive function to parse a layer tree
  *
  * @param lt
  * @param parentLayer
  */
 private void parseJaxbLayer(LayerType lt, ILayer parentLayer) throws LayerException {
   // Test if lt is a group
   if (!lt.getLayer().isEmpty() || (lt.getDataURL() == null)) {
     // it will create a LayerCollection
     parseJaxbLayerCollection(lt, parentLayer);
   } else {
     // it corresponding to a leaf layer
     // We need to read the data declaration and create the layer
     URLType dataUrl = lt.getDataURL();
     if (dataUrl != null) {
       OnlineResourceType resType = dataUrl.getOnlineResource();
       try {
         URI layerURI = new URI(resType.getHref());
         // The resource is given as relative to MapContext location
         if (!layerURI.isAbsolute() && getLocation() != null) {
           try {
             // Resolve the relative resource ex: new Uri("myFile.shp")
             layerURI = getLocation().resolve(layerURI);
           } catch (IllegalArgumentException ex) {
             LOGGER.warn(
                 "Error while trying to find an absolute path for an external resource", ex);
           }
         }
         // Get table name
         ILayer leafLayer = createLayer(layerURI);
         leafLayer.setDescription(new Description(lt));
         leafLayer.setVisible(!lt.isHidden());
         // Parse styles
         if (lt.isSetStyleList()) {
           for (StyleType st : lt.getStyleList().getStyle()) {
             if (st.isSetSLD()) {
               if (st.getSLD().isSetAbstractStyle()) {
                 leafLayer.addStyle(
                     new Style(
                         (JAXBElement<net.opengis.se._2_0.core.StyleType>)
                             st.getSLD().getAbstractStyle(),
                         leafLayer));
               }
             }
           }
         }
         parentLayer.addLayer(leafLayer);
       } catch (URISyntaxException ex) {
         throw new LayerException(
             I18N.tr("Unable to parse the href URI {0}.", resType.getHref()), ex);
       } catch (InvalidStyle ex) {
         throw new LayerException(
             I18N.tr("Unable to load the description of the layer {0}", lt.getTitle().toString()),
             ex);
       }
     }
   }
 }
Exemplo n.º 5
0
  @Override
  public void setSelectedLayers(ILayer[] selectedLayers) {
    checkIsOpen();
    ArrayList<ILayer> filtered = new ArrayList<ILayer>();
    for (ILayer layer : selectedLayers) {
      if (layerModel.getLayerByName(layer.getName()) != null) {
        filtered.add(layer);
      }
    }
    super.setSelectedLayers(filtered.toArray(new ILayer[filtered.size()]));

    // DEPRECATED LISTENERS
    for (MapContextListener listener : listeners) {
      listener.layerSelectionChanged(this);
    }
  }
Exemplo n.º 6
0
 /**
  * Recursive function to parse a layer tree
  *
  * @param lt
  * @param parentLayer
  */
 private void parseJaxbLayerCollection(LayerType lt, ILayer parentLayer) throws LayerException {
   LayerCollection layerCollection = new LayerCollection(lt);
   for (LayerType ltc : lt.getLayer()) {
     try {
       parseJaxbLayer(ltc, layerCollection);
     } catch (LayerException ex) {
       // The layer is not created if a layer exception is thrown
       // Create a warning, because the MapContext is loaded
       LOGGER.warn(I18N.tr("The layer has not been imported"), ex);
     }
   }
   parentLayer.addLayer(layerCollection);
 }
Exemplo n.º 7
0
  private static LayerType createJAXBFromLayer(ILayer layer, MapContext mapContext) {
    ObjectFactory ows_context_factory = new ObjectFactory();
    LayerType layerType = ows_context_factory.createLayerType();
    Description description = layer.getDescription();
    description.initJAXBType(layerType);
    layerType.setHidden(!layer.isVisible());
    ILayer[] childrens = layer.getChildren();
    for (ILayer child : childrens) {
      if (child.isSerializable()) {
        layerType.getLayer().add(createJAXBFromLayer(child, mapContext));
      }
    }
    // If not a Layer Collection
    if (!(layer instanceof LayerCollection) && layer.getStyles() != null) {
      StyleListType slt = ows_context_factory.createStyleListType();
      layerType.setStyleList(slt);
      for (Style style : layer.getStyles()) {
        StyleType st = ows_context_factory.createStyleType();
        slt.getStyle().add(st);
        SLDType sltType = ows_context_factory.createSLDType();
        st.setSLD(sltType);
        sltType.setAbstractStyle(style.getJAXBElement());
      }
    }

    // Serialisation of dataSource as a DataUrl string
    // Create jaxb instances
    URLType dataURL = ows_context_factory.createURLType();
    if (!(layer instanceof LayerCollection)) {
      OnlineResourceType resource = ows_context_factory.createOnlineResourceType();
      dataURL.setOnlineResource(resource);

      String resourceSerialisation = "";
      URI srcUri = layer.getDataUri();
      if (srcUri != null) {
        // If file, use MapContext relative path
        if (srcUri.getScheme().equalsIgnoreCase("file") && mapContext.getLocation() != null) {
          srcUri = URIUtility.relativize(mapContext.getLocation(), srcUri);
        }
        resourceSerialisation = srcUri.toString();
      }
      resource.setHref(resourceSerialisation);
      if (resource.isSetHref()) {
        layerType.setDataURL(dataURL);
      }
    }
    return layerType;
  }
Exemplo n.º 8
0
 @Override
 public void layerAdded(LayerCollectionEvent e) {
   if (isOpen()) {
     for (final ILayer layer : e.getAffected()) {
       try {
         layer.open();
         layer.addLayerListenerRecursively(openerListener);
         // checking & possibly setting SRID
         // checkSRID(layer);
       } catch (LayerException ex) {
         LOGGER.error(I18N.tr("Cannot open layer : {0} ", layer.getName()), ex);
         try {
           layer.getParent().remove(layer);
         } catch (LayerException e1) {
           LOGGER.error(I18N.tr("Cannot remove the layer {0}", layer.getName()), ex);
         }
       }
     }
   }
 }