Changeset 29170 in osm for applications/viewer/jmapviewer/src/org/openstreetmap/gui
- Timestamp:
- 2013-01-05T11:21:15+01:00 (12 years ago)
- Location:
- applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/Demo.java
r27992 r29170 63 63 setExtendedState(JFrame.MAXIMIZED_BOTH); 64 64 JPanel panel = new JPanel(); 65 JPanel panelTop = new JPanel(); 66 JPanel panelBottom = new JPanel(); 65 67 JPanel helpPanel = new JPanel(); 66 68 … … 73 75 add(panel, BorderLayout.NORTH); 74 76 add(helpPanel, BorderLayout.SOUTH); 77 panel.setLayout(new BorderLayout()); 78 panel.add(panelTop, BorderLayout.NORTH); 79 panel.add(panelBottom, BorderLayout.SOUTH); 75 80 JLabel helpLabel = new JLabel("Use right mouse button to move,\n " 76 81 + "left double click or mouse wheel to zoom."); … … 103 108 }); 104 109 map.setTileLoader((TileLoader) tileLoaderSelector.getSelectedItem()); 105 panel .add(tileSourceSelector);106 panel .add(tileLoaderSelector);110 panelTop.add(tileSourceSelector); 111 panelTop.add(tileLoaderSelector); 107 112 final JCheckBox showMapMarker = new JCheckBox("Map markers visible"); 108 113 showMapMarker.setSelected(map.getMapMarkersVisible()); … … 113 118 } 114 119 }); 115 panel .add(showMapMarker);120 panelBottom.add(showMapMarker); 116 121 final JCheckBox showTileGrid = new JCheckBox("Tile grid visible"); 117 122 showTileGrid.setSelected(map.isTileGridVisible()); … … 122 127 } 123 128 }); 124 panel .add(showTileGrid);129 panelBottom.add(showTileGrid); 125 130 final JCheckBox showZoomControls = new JCheckBox("Show zoom controls"); 126 131 showZoomControls.setSelected(map.getZoomContolsVisible()); … … 131 136 } 132 137 }); 133 panel.add(showZoomControls); 134 panel.add(button); 138 panelBottom.add(showZoomControls); 139 final JCheckBox scrollWrapEnabled = new JCheckBox("Scrollwrap enabled"); 140 scrollWrapEnabled.addActionListener(new ActionListener() { 141 public void actionPerformed(ActionEvent e) { 142 map.setScrollWrapEnabled(scrollWrapEnabled.isSelected()); 143 } 144 }); 145 panelBottom.add(scrollWrapEnabled); 146 panelBottom.add(button); 135 147 136 panel .add(zoomLabel);137 panel .add(zoomValue);138 panel .add(mperpLabelName);139 panel .add(mperpLabelValue);148 panelTop.add(zoomLabel); 149 panelTop.add(zoomValue); 150 panelTop.add(mperpLabelName); 151 panelTop.add(mperpLabelValue); 140 152 141 153 add(map, BorderLayout.CENTER); -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/JMapViewer.java
r29169 r29170 63 63 64 64 protected boolean tileGridVisible; 65 protected boolean scrollWrapEnabled; 65 66 66 67 protected TileController tileController; … … 510 511 int x_max = getWidth(); 511 512 int y_max = getHeight(); 513 514 // calculate the length of the grid (number of squares per edge) 515 int gridLength = 1 << zoom; 512 516 513 517 // paint the tiles in a spiral, starting from center of the map … … 523 527 if (x_min <= posx && posx <= x_max && y_min <= posy && posy <= y_max) { 524 528 // tile is visible 525 Tile tile = tileController.getTile(tilex, tiley, zoom); 529 Tile tile; 530 if (scrollWrapEnabled) { 531 // in case tilex is out of bounds, grab the tile to use for wrapping 532 int tilexWrap = (((tilex % gridLength) + gridLength) % gridLength); 533 tile = tileController.getTile(tilexWrap, tiley, zoom); 534 } else { 535 tile = tileController.getTile(tilex, tiley, zoom); 536 } 526 537 if (tile != null) { 527 538 tile.paint(g, posx, posy); … … 543 554 // outer border of the map 544 555 int mapSize = tilesize << zoom; 545 g.drawRect(w2 - center.x, h2 - center.y, mapSize, mapSize); 556 if (scrollWrapEnabled) { 557 g.drawLine(0, h2 - center.y, getWidth(), h2 - center.y); 558 g.drawLine(0, h2 - center.y + mapSize, getWidth(), h2 - center.y + mapSize); 559 } else { 560 g.drawRect(w2 - center.x, h2 - center.y, mapSize, mapSize); 561 } 546 562 547 563 // g.drawString("Tiles in cache: " + tileCache.getTileCount(), 50, 20); 548 564 565 // keep x-coordinates from growing without bound if scroll-wrap is enabled 566 if (scrollWrapEnabled) { 567 center.x = center.x % mapSize; 568 } 569 549 570 if (mapPolygonsVisible && mapPolygonList != null) { 550 571 for (MapPolygon polygon : mapPolygonList) { … … 573 594 protected void paintMarker(Graphics g, MapMarker marker) { 574 595 Point p = getMapPosition(marker.getLat(), marker.getLon()); 575 if (p != null) { 596 if (scrollWrapEnabled) { 597 int tilesize = tileSource.getTileSize(); 598 int mapSize = tilesize << zoom; 599 if (p == null) { 600 p = getMapPosition(marker.getLat(), marker.getLon(), false); 601 } 576 602 marker.paint(g, p); 603 int xSave = p.x; 604 int xWrap = xSave; 605 // overscan of 15 allows up to 30-pixel markers to gracefully scroll off the edge of the panel 606 while ((xWrap -= mapSize) >= -15) { 607 p.x = xWrap; 608 marker.paint(g, p); 609 } 610 xWrap = xSave; 611 while ((xWrap += mapSize) <= getWidth() + 15) { 612 p.x = xWrap; 613 marker.paint(g, p); 614 } 615 } else { 616 if (p != null) { 617 marker.paint(g, p); 618 } 577 619 } 578 620 } … … 589 631 if (pTopLeft != null && pBottomRight != null) { 590 632 rectangle.paint(g, pTopLeft, pBottomRight); 633 if (scrollWrapEnabled) { 634 int tilesize = tileSource.getTileSize(); 635 int mapSize = tilesize << zoom; 636 int xTopLeftSave = pTopLeft.x; 637 int xTopLeftWrap = xTopLeftSave; 638 int xBottomRightSave = pBottomRight.x; 639 int xBottomRightWrap = xBottomRightSave; 640 while ((xBottomRightWrap -= mapSize) >= 0) { 641 xTopLeftWrap -= mapSize; 642 pTopLeft.x = xTopLeftWrap; 643 pBottomRight.x = xBottomRightWrap; 644 rectangle.paint(g, pTopLeft, pBottomRight); 645 } 646 xTopLeftWrap = xTopLeftSave; 647 xBottomRightWrap = xBottomRightSave; 648 while ((xTopLeftWrap += mapSize) <= getWidth()) { 649 xBottomRightWrap += mapSize; 650 pTopLeft.x = xTopLeftWrap; 651 pBottomRight.x = xBottomRightWrap; 652 rectangle.paint(g, pTopLeft, pBottomRight); 653 } 654 655 } 591 656 } 592 657 } … … 608 673 } 609 674 polygon.paint(g, points); 675 if (scrollWrapEnabled) { 676 int tilesize = tileSource.getTileSize(); 677 int mapSize = tilesize << zoom; 678 List<Point> pointsWrapped = new LinkedList<Point>(points); 679 boolean keepWrapping = true; 680 while (keepWrapping) { 681 for (Point p : pointsWrapped) { 682 p.x -= mapSize; 683 if (p.x < 0) { 684 keepWrapping = false; 685 } 686 } 687 polygon.paint(g, pointsWrapped); 688 } 689 pointsWrapped = new LinkedList<Point>(points); 690 keepWrapping = true; 691 while (keepWrapping) { 692 for (Point p : pointsWrapped) { 693 p.x += mapSize; 694 if (p.x > getWidth()) { 695 keepWrapping = false; 696 } 697 } 698 polygon.paint(g, pointsWrapped); 699 } 700 } 610 701 } 611 702 } … … 867 958 repaint(); 868 959 } 960 961 public boolean isScrollWrapEnabled() { 962 return scrollWrapEnabled; 963 } 964 965 public void setScrollWrapEnabled(boolean scrollWrapEnabled) { 966 this.scrollWrapEnabled = scrollWrapEnabled; 967 repaint(); 968 } 869 969 870 970 /**
Note:
See TracChangeset
for help on using the changeset viewer.