Changeset 30758 in osm


Ignore:
Timestamp:
2014-10-21T02:54:10+02:00 (10 years ago)
Author:
donvip
Message:

[jmapviewer] update Bing logo + read it from Bing attribution if removed from source (like in Debian, see bug 765421. Modified patch from Marcus Lundblad, Martin Krüger and Sebastiaan Couwenberg)

Location:
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/BingAerialTileSource.java

    r30426 r30758  
    44import java.awt.Image;
    55import java.io.IOException;
     6import java.io.InputStream;
    67import java.net.MalformedURLException;
    78import java.net.URL;
     
    4647    private static final Pattern quadkeyPattern = Pattern.compile("\\{quadkey\\}");
    4748    private static final Pattern culturePattern = Pattern.compile("\\{culture\\}");
    48 
     49    private String brandLogoUri = null;
     50
     51    /**
     52     * Constructs a new {@code BingAerialTileSource}.
     53     */
    4954    public BingAerialTileSource() {
    5055        super("Bing Aerial Maps", "http://example.com/");
     
    97102                subdomains[i] = subdomainTxt.item(i).getNodeValue();
    98103            }
     104
     105            brandLogoUri = xpath.compile("/Response/BrandLogoUri/text()").evaluate(document);
    99106
    100107            XPathExpression attributionXpath = xpath.compile("Attribution/text()");
     
    175182    public Image getAttributionImage() {
    176183        try {
    177             return ImageIO.read(JMapViewer.class.getResourceAsStream("images/bing_maps.png"));
     184            final InputStream imageResource = JMapViewer.class.getResourceAsStream("images/bing_maps.png");
     185            if (imageResource != null) {
     186                return ImageIO.read(imageResource);
     187            } else {
     188                // Some Linux distributions (like Debian) will remove Bing logo from sources, so get it at runtime
     189                for (int i = 0; i < 5 && getAttribution() == null; i++) {
     190                    // Makes sure attribution is loaded
     191                }
     192                if (brandLogoUri != null && !brandLogoUri.isEmpty()) {
     193                    System.out.println("Reading Bing logo from "+brandLogoUri);
     194                    return ImageIO.read(new URL(brandLogoUri));
     195                }
     196            }
    178197        } catch (IOException e) {
    179             return null;
    180         }
     198            System.err.println("Error while retrieving Bing logo: "+e.getMessage());
     199        }
     200        return null;
    181201    }
    182202
Note: See TracChangeset for help on using the changeset viewer.