Search in sources :

Example 36 with MapLayers

use of org.apache.sis.portrayal.MapLayers in project geotoolkit by Geomatys.

the class OwcXmlIO method readEntry.

private static MapItem readEntry(final EntryType entry) throws JAXBException, FactoryException, DataStoreException {
    final List<Object> entryContent = entry.getAuthorOrCategoryOrContent();
    String layerName = "";
    String layerTitle = "";
    String layerAbstract = "";
    boolean visible = true;
    boolean selectable = true;
    double layerOpacity = 1.0;
    MapItem mapItem = null;
    MutableStyle baseStyle = null;
    MutableStyle selectionStyle = null;
    final List<MapItem> children = new ArrayList<>();
    for (Object o : entryContent) {
        QName name = null;
        if (o instanceof JAXBElement) {
            final JAXBElement jax = (JAXBElement) o;
            name = jax.getName();
            o = jax.getValue();
            if (GEOTK_FACTORY._Visible_QNAME.equals(name)) {
                visible = (Boolean) o;
            } else if (GEOTK_FACTORY._Selectable_QNAME.equals(name)) {
                selectable = (Boolean) o;
            } else if (GEOTK_FACTORY._Opacity_QNAME.equals(name)) {
                layerOpacity = (Double) o;
            }
        }
        if (o instanceof OfferingType) {
            final OfferingType offering = (OfferingType) o;
            for (OwcExtension ext : getExtensions()) {
                if (ext.getCode().equals(offering.getCode())) {
                    mapItem = ext.createLayer(offering);
                    break;
                }
            }
            // search for styles
            baseStyle = readStyle(offering, true);
            selectionStyle = readStyle(offering, false);
        } else if (o instanceof ContentType) {
            // decode children
            final ContentType content = (ContentType) o;
            final List<Object> contentContent = content.getContent();
            for (Object co : contentContent) {
                if (co instanceof JAXBElement) {
                    co = ((JAXBElement) o).getValue();
                }
                if (co instanceof EntryType) {
                    children.add(readEntry((EntryType) co));
                }
            }
        } else if (o instanceof IdType) {
            final IdType idType = (IdType) o;
            final String value = idType.getValue();
            layerName = value;
        } else if (o instanceof TextType) {
            final TextType tt = (TextType) o;
            if (ATOM_FACTORY._EntryTypeTitle_QNAME.equals(name)) {
                if (!tt.getContent().isEmpty()) {
                    layerTitle = (String) tt.getContent().get(0);
                }
            } else if (ATOM_FACTORY._EntryTypeSummary_QNAME.equals(name)) {
                if (!tt.getContent().isEmpty()) {
                    layerAbstract = (String) tt.getContent().get(0);
                }
            }
        }
    }
    if (mapItem == null) {
        mapItem = MapBuilder.createItem();
    } else if (mapItem instanceof MapLayer) {
        if (baseStyle != null) {
            ((MapLayer) mapItem).setStyle(baseStyle);
        }
        ((MapLayer) mapItem).setOpacity(layerOpacity);
    }
    mapItem.setIdentifier(layerName);
    mapItem.setTitle(layerTitle);
    mapItem.setAbstract(layerAbstract);
    mapItem.setVisible(visible);
    if (mapItem instanceof MapLayers) {
        ((MapLayers) mapItem).getComponents().addAll(children);
    } else if (!children.isEmpty()) {
        throw new IllegalArgumentException("MapLayer can not have children layers.");
    }
    return mapItem;
}
Also used : ContentType(org.geotoolkit.owc.xml.v10.ContentType) QName(javax.xml.namespace.QName) MapLayer(org.apache.sis.portrayal.MapLayer) ArrayList(java.util.ArrayList) JAXBElement(javax.xml.bind.JAXBElement) IdType(org.w3._2005.atom.IdType) TextType(org.w3._2005.atom.TextType) OfferingType(org.geotoolkit.owc.xml.v10.OfferingType) EntryType(org.w3._2005.atom.EntryType) MutableStyle(org.geotoolkit.style.MutableStyle) List(java.util.List) ArrayList(java.util.ArrayList) MapItem(org.apache.sis.portrayal.MapItem) MapLayers(org.apache.sis.portrayal.MapLayers)

Example 37 with MapLayers

use of org.apache.sis.portrayal.MapLayers in project geotoolkit by Geomatys.

the class WMCUtilities method getMapContext.

/**
 * This method will get WMC informations to create a new valid
 * {@link MapContext}.
 *
 * @param source : An {@link InputSream}, the WMC as an xml.
 * @return A map context containing informations given by a wmc document.
 * @throws JAXBException if the xml cannot be read.
 */
public static MapLayers getMapContext(InputStream source) throws JAXBException {
    final MarshallerPool pool = getMarshallerPool();
    final Unmarshaller um = pool.acquireUnmarshaller();
    Object o = um.unmarshal(source);
    if (o instanceof JAXBElement) {
        o = ((JAXBElement) o).getValue();
    }
    // Get needed markups
    ViewContextType root = (ViewContextType) o;
    final MapLayers context = getMapContext(root);
    pool.recycle(um);
    return context;
}
Also used : MarshallerPool(org.apache.sis.xml.MarshallerPool) JAXBElement(javax.xml.bind.JAXBElement) Unmarshaller(javax.xml.bind.Unmarshaller) MapLayers(org.apache.sis.portrayal.MapLayers)

Example 38 with MapLayers

use of org.apache.sis.portrayal.MapLayers in project geotoolkit by Geomatys.

the class WMCUtilitiesTest method testGetMapContext.

/**
 * Test of getMapContext method, of class WMCUtilities.
 */
@Test
public void testGetMapContext() throws Exception {
    MapLayers context = WMCUtilities.getMapContext(this.getClass().getResourceAsStream("testWMC_wms.xml"));
    assertNotNull(context);
}
Also used : MapLayers(org.apache.sis.portrayal.MapLayers) Test(org.junit.Test)

Example 39 with MapLayers

use of org.apache.sis.portrayal.MapLayers in project geotoolkit by Geomatys.

the class WMTSClientDemo method main.

public static void main(String[] args) throws Exception {
    Demos.init();
    final MapLayers context = createContext();
// FXMapFrame.show(context);
}
Also used : MapLayers(org.apache.sis.portrayal.MapLayers)

Example 40 with MapLayers

use of org.apache.sis.portrayal.MapLayers in project geotoolkit by Geomatys.

the class WMTSClientDemo method createContext.

public static MapLayers createContext() throws Exception {
    final MapLayers context = MapBuilder.createContext(CommonCRS.WGS84.normalizedGeographic());
    final WebMapTileClient server = new WebMapTileClient(new URL("http://localhost:8080/constellation/WS/wmts/test"), WMTSVersion.v100);
    for (final Resource ref : DataStores.flatten(server, false)) {
        final GenericName n = ref.getIdentifier().get();
        System.out.println(n);
        final MapLayer layer = MapBuilder.createCoverageLayer(ref, new DefaultStyleFactory().style(StyleConstants.DEFAULT_RASTER_SYMBOLIZER));
        TiledResource model = (TiledResource) ref;
        System.out.println(model);
        layer.setTitle(n.tip().toString());
        context.getComponents().add(layer);
    }
    return context;
}
Also used : GenericName(org.opengis.util.GenericName) TiledResource(org.geotoolkit.storage.multires.TiledResource) MapLayer(org.apache.sis.portrayal.MapLayer) Resource(org.apache.sis.storage.Resource) TiledResource(org.geotoolkit.storage.multires.TiledResource) WebMapTileClient(org.geotoolkit.wmts.WebMapTileClient) URL(java.net.URL) DefaultStyleFactory(org.geotoolkit.style.DefaultStyleFactory) MapLayers(org.apache.sis.portrayal.MapLayers)

Aggregations

MapLayers (org.apache.sis.portrayal.MapLayers)104 Dimension (java.awt.Dimension)61 BufferedImage (java.awt.image.BufferedImage)57 Test (org.junit.Test)57 MapLayer (org.apache.sis.portrayal.MapLayer)51 GeneralEnvelope (org.apache.sis.geometry.GeneralEnvelope)47 Rectangle (java.awt.Rectangle)26 CanvasDef (org.geotoolkit.display2d.service.CanvasDef)26 SceneDef (org.geotoolkit.display2d.service.SceneDef)26 GridGeometry (org.apache.sis.coverage.grid.GridGeometry)22 Coordinate (org.locationtech.jts.geom.Coordinate)17 GridCoverage (org.apache.sis.coverage.grid.GridCoverage)16 MutableStyle (org.geotoolkit.style.MutableStyle)16 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)16 Graphics2D (java.awt.Graphics2D)15 SampleDimension (org.apache.sis.coverage.SampleDimension)15 Feature (org.opengis.feature.Feature)14 FeatureType (org.opengis.feature.FeatureType)14 FeatureTypeBuilder (org.apache.sis.feature.builder.FeatureTypeBuilder)13 FeatureSet (org.apache.sis.storage.FeatureSet)13