From 829b4ed82bf2ade5d2085346b417a0bbbd284106 Mon Sep 17 00:00:00 2001 From: hbeni Date: Tue, 17 Aug 2021 22:32:34 +0200 Subject: [PATCH] RadioGUI: Fix #144 (OpenStreetMap Map tiles not displaying anymore) 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. --- .../java/hbeni/fgcom_mumble/MapWindow.java | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/client/radioGUI/src/main/java/hbeni/fgcom_mumble/MapWindow.java b/client/radioGUI/src/main/java/hbeni/fgcom_mumble/MapWindow.java index 5ec8498c..e2255d19 100644 --- a/client/radioGUI/src/main/java/hbeni/fgcom_mumble/MapWindow.java +++ b/client/radioGUI/src/main/java/hbeni/fgcom_mumble/MapWindow.java @@ -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 * @@ -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); @@ -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(); @@ -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 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) { @@ -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); @@ -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; @@ -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(); @@ -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())); }