Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed GetLegendGraphic from RemoteWMSLayer #714

Merged
merged 3 commits into from
Aug 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}

}
}