Skip to content

Commit

Permalink
RadioGUI: Fix #144 (OpenStreetMap Map tiles not displaying anymore)
Browse files Browse the repository at this point in the history
Reason was two missing HTTP headers:
 - HTTP-Useragent was wrongly set (in System, but that was ignored)
 - Referer was not set (not mandatory, but polite according to OSM policy)
Now the headers are set correctly.
  • Loading branch information
hbeni committed Aug 17, 2021
1 parent bfe55bc commit 829b4ed
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions client/radioGUI/src/main/java/hbeni/fgcom_mumble/MapWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ public class MapWindow extends JFrame implements JMapViewerEventListener {
public MainWindow mainWindow;


static {
System.setProperty("http.agent", "FGCom-mumble RadioGUI /" + System.getProperty("http.agent"));
}

/**
* Open MapClick window
*
Expand All @@ -91,7 +87,6 @@ public MapWindow(State s, MainWindow mw) {
// receive events and update
map().addJMVListener(this);


setLayout(new BorderLayout());
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setExtendedState(JFrame.MAXIMIZED_BOTH);
Expand All @@ -100,8 +95,12 @@ public MapWindow(State s, MainWindow mw) {
JPanel panelBottom = new JPanel();
JPanel helpPanel = new JPanel();

JPanel zoomTextPanel = new JPanel();
mperpLabelName = new JLabel("Meters/Pixels: ");
mperpLabelValue = new JLabel(String.format("%s", map().getMeterPerPixel()));
mperpLabelValue = new JLabel();
updateZoomParameters();
zoomTextPanel.add(mperpLabelName);
zoomTextPanel.add(mperpLabelValue);

if (lastZoom == -1) {
lastZoom = map().getZoom();
Expand All @@ -126,8 +125,13 @@ public void itemStateChanged(ItemEvent e) {
});
tileSourceSelector.setSelectedIndex(lastTileSourceSelectorIDX);

// prepare the tile loaders
OsmTileLoader osm_loader = new OsmTileLoader(map());
osm_loader.headers.put("User-Agent", "FGCom-mumble RadioGUI / "+ System.getProperty("http.agent"));
osm_loader.headers.put("Referer", "https://github.com/hbeni/fgcom-mumble/blob/master/client/radioGUI/Readme.RadioGUI.md");

JComboBox<TileLoader> tileLoaderSelector;
tileLoaderSelector = new JComboBox<>(new TileLoader[] {new OsmTileLoader(map())});
tileLoaderSelector = new JComboBox<>(new TileLoader[] {osm_loader});
tileLoaderSelector.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
Expand All @@ -136,6 +140,7 @@ public void itemStateChanged(ItemEvent e) {
});
map().setTileLoader((TileLoader) tileLoaderSelector.getSelectedItem());
panelTop.add(tileSourceSelector);
panelTop.add(zoomTextPanel);
//panelTop.add(tileLoaderSelector);

map().setTileGridVisible(true);
Expand All @@ -152,6 +157,8 @@ public void itemStateChanged(ItemEvent e) {
JLabel helpLabel = new JLabel("Left mouse click selects position. \nUse right mouse button to move,\n "
+ " and mouse wheel to zoom.");
helpPanel.add(helpLabel);
JLabel attributionLabel = new JLabel("(C) "+map().getAttribution().toString());
helpPanel.add(attributionLabel);


JFrame myself = this;
Expand All @@ -177,7 +184,6 @@ public void mouseClicked(MouseEvent e) {
// Add a marker at current position
map().addMapMarker(new MapMarkerDot("Position", new Coordinate(state.getLatitutde(), state.getLongitude())));


setExtendedState(JFrame.NORMAL);
setPreferredSize(new Dimension(1000, 800));
pack();
Expand All @@ -203,7 +209,7 @@ private static Coordinate c(double lat, double lon) {

private void updateZoomParameters() {
if (mperpLabelValue != null)
mperpLabelValue.setText(String.format("%s", map().getMeterPerPixel()));
mperpLabelValue.setText(String.format("%s", Math.round(map().getMeterPerPixel() *100.0)/100.0));
if (zoomValue != null)
zoomValue.setText(String.format("%s", map().getZoom()));
}
Expand Down

0 comments on commit 829b4ed

Please sign in to comment.