Changeset 24486 in osm for applications
- Timestamp:
- 2010-12-01T04:38:47+01:00 (14 years ago)
- Location:
- applications/editors/josm/plugins/slippymap
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/slippymap/src/org/openstreetmap/josm/plugins/slippymap/SlippyMapLayer.java
r23190 r24486 4 4 5 5 import java.awt.Color; 6 import java.awt.Font; 6 7 import java.awt.Graphics; 7 8 import java.awt.Graphics2D; … … 104 105 JCheckBoxMenuItem autoZoomPopup; 105 106 Tile showMetadataTile; 107 private Image attrImage; 108 private Font attrFont = Font.decode("Arial-10"); 106 109 107 110 void redraw() … … 115 118 int origZoom = currentZoomLevel; 116 119 tileSource = SlippyMapPreferences.getMapSource(); 120 boolean requireAttr = tileSource.requiresAttribution(); 121 if(requireAttr) { 122 attrImage = tileSource.getAttributionImage(); 123 if(attrImage == null) { 124 System.out.println("Attribution image was null."); 125 } else { 126 System.out.println("Got an attribution image " + attrImage.getHeight(this) + "x" + attrImage.getWidth(this)); 127 } 128 } 129 117 130 // The minimum should also take care of integer parsing 118 131 // errors which would leave us with a zoom of -1 otherwise … … 817 830 return; 818 831 } 832 819 833 if (lastTopLeft != null && lastBotRight != null && topLeft.equalsEpsilon(lastTopLeft) 820 834 && botRight.equalsEpsilon(lastBotRight) && bufferImage != null … … 908 922 this.paintTileText(ts, t, g, mv, currentZoomLevel, t); 909 923 } 924 925 if (tileSource.requiresAttribution()) { 926 // Draw attribution 927 g.setColor(Color.white); 928 Font font = g.getFont(); 929 g.setFont(attrFont); 930 g.drawString(tileSource.getAttributionText(currentZoomLevel, topLeft, botRight), 5 + attrImage.getWidth(this) + 2, mv.getHeight() - 5); 931 g.setFont(font); 932 933 // Draw attribution logo 934 if(attrImage != null) { 935 g.drawImage(attrImage, 5, mv.getHeight() - attrImage.getHeight(this) - 5, this); 936 } 937 } 938 910 939 oldg.drawImage(bufferImage, 0, 0, null); 911 940 -
applications/editors/josm/plugins/slippymap/src/org/openstreetmap/josm/plugins/slippymap/SlippyMapPreferences.java
r24358 r24486 3 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 4 5 import java.awt.Image; 6 import java.io.IOException; 7 import java.io.InputStream; 8 import java.net.URL; 5 9 import java.util.ArrayList; 10 import java.util.Collections; 6 11 import java.util.List; 7 12 import java.util.Map; … … 11 16 import org.openstreetmap.gui.jmapviewer.interfaces.TileSource; 12 17 import org.openstreetmap.josm.Main; 18 import org.openstreetmap.josm.data.Bounds; 19 import org.openstreetmap.josm.data.coor.LatLon; 20 import org.openstreetmap.josm.tools.ImageProvider; 21 import org.xml.sax.Attributes; 22 import org.xml.sax.InputSource; 23 import org.xml.sax.SAXException; 24 import org.xml.sax.XMLReader; 25 import org.xml.sax.helpers.DefaultHandler; 26 import org.xml.sax.helpers.XMLReaderFactory; 13 27 14 28 /** … … 277 291 278 292 public static class BingAerial extends OsmTileSource.AbstractOsmTileSource { 293 private static String API_KEY = "Arzdiw4nlOJzRwOz__qailc8NiR31Tt51dN2D7cm57NrnceZnCpgOkmJhNpGoppU"; 294 private static List<Attribution> attributions; 295 279 296 public BingAerial() { 280 297 super("Bing Aerial Maps", "http://ecn.t2.tiles.virtualearth.net/tiles/"); 298 299 attributions = loadAttributionText(); 300 System.err.println("Added " + attributions.size() + " attributions."); 301 } 302 303 class Attribution { 304 String attribution; 305 int minZoom; 306 int maxZoom; 307 Bounds bounds; 308 } 309 310 class AttrHandler extends DefaultHandler { 311 312 private String string; 313 private Attribution curr; 314 private List<Attribution> attributions = new ArrayList<Attribution>(); 315 private double southLat; 316 private double northLat; 317 private double eastLon; 318 private double westLon; 319 private boolean inCoverage = false; 320 321 public void startElement(String uri, String stripped, String tagName, 322 Attributes attrs) throws SAXException { 323 if("ImageryProvider".equals(tagName)) { 324 curr = new Attribution(); 325 } else if("CoverageArea".equals(tagName)) { 326 inCoverage = true; 327 } 328 } 329 330 public void characters(char[] ch, int start, int length) 331 throws SAXException { 332 string = new String(ch, start, length); 333 } 334 335 public void endElement(String uri, String stripped, String tagName) 336 throws SAXException { 337 if("ImageryProvider".equals(tagName)) { 338 attributions.add(curr); 339 } else if("Attribution".equals(tagName)) { 340 curr.attribution = string; 341 } else if(inCoverage && "ZoomMin".equals(tagName)) { 342 curr.minZoom = Integer.parseInt(string); 343 } else if(inCoverage && "ZoomMax".equals(tagName)) { 344 curr.maxZoom = Integer.parseInt(string); 345 } else if(inCoverage && "SouthLatitude".equals(tagName)) { 346 southLat = Double.parseDouble(string); 347 } else if(inCoverage && "NorthLatitude".equals(tagName)) { 348 northLat = Double.parseDouble(string); 349 } else if(inCoverage && "EastLongitude".equals(tagName)) { 350 eastLon = Double.parseDouble(string); 351 } else if(inCoverage && "WestLongitude".equals(tagName)) { 352 westLon = Double.parseDouble(string); 353 } else if("BoundingBox".equals(tagName)) { 354 curr.bounds = new Bounds(northLat, westLon, southLat, eastLon); 355 } else if("CoverageArea".equals(tagName)) { 356 inCoverage = false; 357 } 358 string = ""; 359 } 360 } 361 362 private List<Attribution> loadAttributionText() { 363 try { 364 URL u = new URL("http://dev.virtualearth.net/REST/v1/Imagery/Metadata/Aerial/0,0?zl=1&mapVersion=v1&key="+API_KEY+"&include=ImageryProviders&output=xml"); 365 InputStream stream = u.openStream(); 366 XMLReader parser = XMLReaderFactory.createXMLReader(); 367 AttrHandler handler = new AttrHandler(); 368 parser.setContentHandler(handler); 369 parser.parse(new InputSource(stream)); 370 return handler.attributions; 371 } catch (IOException e) { 372 System.err.println("Could not open Bing aerials attribution metadata."); 373 } catch (SAXException e) { 374 System.err.println("Could not parse Bing aerials attribution metadata."); 375 e.printStackTrace(); 376 } 377 return Collections.emptyList(); 281 378 } 282 379 … … 299 396 public TileUpdate getTileUpdate() { 300 397 return TileUpdate.IfNoneMatch; 398 } 399 400 public boolean requiresAttribution() { 401 return true; 402 } 403 404 public Image getAttributionImage() { 405 return ImageProvider.get("bing_maps").getImage(); 406 } 407 408 public String getAttributionText(int zoom, LatLon topLeft, LatLon botRight) { 409 Bounds windowBounds = new Bounds(topLeft, botRight); 410 StringBuilder a = new StringBuilder(); 411 for (Attribution attr : attributions) { 412 Bounds attrBounds = attr.bounds; 413 if(zoom <= attr.maxZoom && zoom >= attr.minZoom) { 414 if(windowBounds.getMin().lon() < attrBounds.getMax().lon() 415 && windowBounds.getMax().lon() > attrBounds.getMin().lon() 416 && windowBounds.getMax().lat() < attrBounds.getMin().lat() 417 && windowBounds.getMin().lat() > attrBounds.getMax().lat()) { 418 a.append(attr.attribution); 419 a.append(" "); 420 } else { 421 } 422 } 423 } 424 return a.toString(); 301 425 } 302 426 } … … 422 546 sources.add(new OsmTileSource.TilesAtHome()); 423 547 // *PLEASE* do not enable BingAerial until we have legal approval. 424 //sources.add(new BingAerial());548 sources.add(new BingAerial()); 425 549 sources.add(new Coastline()); 426 550 sources.add(new FreeMapySkPokus());
Note:
See TracChangeset
for help on using the changeset viewer.