private void addLayer( FeatureStore store, FeatureType ft, StyleStore sstore, Map<String, Layer> map ) { String name = ft.getName().getLocalPart(); LOG.debug( "Adding layer {}.", name ); LayerMetadata md = LayerMetadataBuilder.buildMetadataForAutoMode( store, ft, name ); Map<String, Style> styles = new LinkedHashMap<String, Style>(); if ( sstore != null && sstore.getAll( name ) != null ) { for ( Style s : sstore.getAll( name ) ) { LOG.debug( "Adding style with name {}.", s.getName() ); styles.put( s.getName(), s ); if ( !styles.containsKey( "default" ) ) { styles.put( "default", s ); } } } if ( !styles.containsKey( "default" ) ) { LOG.debug( "No styles found, using gray default style." ); styles.put( "default", new Style() ); } md.setStyles( styles ); Layer l = new FeatureLayer( md, store, ft.getName(), null, null, null ); map.put( name, l ); }
public static Pair<Map<String, Style>, Map<String, Style>> parseStyles( Workspace workspace, String layerName, List<StyleRefType> styles ) { // hail java 7 to finally be able to do some really complicated type inference Map<String, Style> styleMap = new LinkedHashMap<String, Style>(); Map<String, Style> legendStyleMap = new LinkedHashMap<String, Style>(); Style defaultStyle = null, defaultLegendStyle = null; for ( StyleRefType srt : styles ) { String id = srt.getStyleStoreId(); StyleStore store = workspace.getResource( StyleStoreProvider.class, id ); if ( srt.getStyle() == null || srt.getStyle().isEmpty() ) { if ( store.getAll( layerName ) != null ) { for ( Style s : store.getAll( layerName ) ) { if ( defaultStyle == null ) { defaultStyle = s; defaultLegendStyle = s; } styleMap.put( s.getName(), s ); legendStyleMap.put( s.getName(), s ); } } continue; } Pair<Style, Style> p = useSelectedStyles( workspace, store, srt, id, styleMap, legendStyleMap, defaultStyle, defaultLegendStyle ); defaultStyle = p.first; defaultLegendStyle = p.second; } checkDefaultStyle( defaultStyle, styleMap, defaultLegendStyle, legendStyleMap ); return new Pair<Map<String, Style>, Map<String, Style>>( styleMap, legendStyleMap ); }
LayerStore createFromAutoLayers( AutoLayers cfg ) { String cid = cfg.getCoverageStoreId(); String sid = cfg.getStyleStoreId(); Coverage cov = workspace.getResource( CoverageProvider.class, cid ); StyleStore sstore = null; if ( sid != null ) { sstore = workspace.getResource( StyleStoreProvider.class, sid ); } SpatialMetadata smd = new SpatialMetadata( cov.getEnvelope(), Collections.singletonList( cov.getCoordinateSystem() ) ); Description desc = new Description( cid, Collections.singletonList( new LanguageString( cid, null ) ), null, null ); LayerMetadata md = new LayerMetadata( cid, desc, smd ); md.getFeatureTypes().add( buildFeatureType() ); if ( sstore != null ) { for ( Style s : sstore.getAll( cid ) ) { md.getStyles().put( s.getName(), s ); } } Layer l = new CoverageLayer( md, cov instanceof AbstractRaster ? (AbstractRaster) cov : null, cov instanceof MultiResolutionRaster ? (MultiResolutionRaster) cov : null ); return new SingleLayerStore( l, metadata ); }