Skip to content

Commit

Permalink
Merge pull request #714 from lat-lon/remoteGetLegendGraphic-3192
Browse files Browse the repository at this point in the history
Fixed GetLegendGraphic from RemoteWMSLayer
  • Loading branch information
copierrj authored Aug 17, 2016
2 parents 03ada08 + 71b9c15 commit 6082647
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,11 @@ Pair<Integer, Integer> getLegendSize( Style style ) {
if ( url != null ) {
try {
BufferedImage legend = ImageIO.read( url );
return new Pair<Integer, Integer>( legend.getWidth(), legend.getHeight() );
if ( legend != null ) {
return new Pair<Integer, Integer>( legend.getWidth(), legend.getHeight() );
} else {
LOG.warn( "Legend file {} could not be read, using dynamic legend.", url );
}
} catch ( IOException e ) {
LOG.warn( "Legend file {} could not be read, using dynamic legend: {}", url, e.getLocalizedMessage() );
LOG.trace( "Stack trace:", e );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,43 @@ class RemoteWmsLayerBuilder {
}

Map<String, Layer> buildLayerMap() {
Map<String, LayerMetadata> configured = collectConfiguredLayers();
if ( configured.isEmpty() )
return parseAllRemoteLayers();
return collectConfiguredRemoteLayers( configured );
}

private Map<String, Layer> parseAllRemoteLayers() {
Map<String, Layer> map = new LinkedHashMap<String, Layer>();

RequestOptionsType opts = cfg.getRequestOptions();
List<LayerMetadata> layers = client.getLayerTree().flattenDepthFirst();
for ( LayerMetadata md : layers ) {
if ( md.getName() != null ) {
map.put( md.getName(), new RemoteWMSLayer( md.getName(), md, client, opts ) );
}
}
return map;
}

private Map<String, Layer> collectConfiguredRemoteLayers( Map<String, LayerMetadata> configured ) {
Map<String, Layer> map = new LinkedHashMap<String, Layer>();
RequestOptionsType opts = cfg.getRequestOptions();
List<LayerMetadata> layers = client.getLayerTree().flattenDepthFirst();
for ( LayerMetadata md : layers ) {
String name = md.getName();
LayerMetadata confMd = configured.get( name );
if ( confMd != null ) {
confMd.merge( md );
confMd.setStyles( md.getStyles() );
confMd.setLegendStyles( md.getLegendStyles() );
map.put( confMd.getName(), new RemoteWMSLayer( name, confMd, client, opts ) );
}
}
return map;
}

private Map<String, LayerMetadata> collectConfiguredLayers() {
Map<String, LayerMetadata> configured = new HashMap<String, LayerMetadata>();
if ( cfg.getLayer() != null ) {
for ( LayerType l : cfg.getLayer() ) {
Expand All @@ -105,25 +139,7 @@ Map<String, Layer> buildLayerMap() {
configured.put( l.getOriginalName(), md );
}
}

List<LayerMetadata> layers = client.getLayerTree().flattenDepthFirst();
if ( configured.isEmpty() ) {
for ( LayerMetadata md : layers ) {
if ( md.getName() != null ) {
map.put( md.getName(), new RemoteWMSLayer( md.getName(), md, client, opts ) );
}
}
} else {
for ( LayerMetadata md : layers ) {
String name = md.getName();
LayerMetadata confMd = configured.get( name );
if ( confMd != null ) {
confMd.merge( md );
map.put( confMd.getName(), new RemoteWMSLayer( name, confMd, client, opts ) );
}
}
}
return map;
return configured;
}

}
}

0 comments on commit 6082647

Please sign in to comment.