Skip to main content

Proxy for JXMapViewer and TileFactory to use OSM tiles

1 reply [Last post]
user_javafx
Offline
Joined: 2010-08-12
Points: 0

Hello,

I downloaded the ExercisingSwing project from http://javafx.com/samples/ExercisingSwing/index.html, and I tested but it is not working because my network it is behind of Proxy.

I changed the code but still it is not working. My question is:
How should I configure proxy in classes: JXMapViewer or TileFactoryInfo or TileFactory to be possible to use OSM tiles.

my code is:

public class SetupMap {

public static JComponent create() {
JXMapViewer map = new JXMapViewer();
final int max = 17;

//lines added for proxy
System.setProperty("http.proxyHost", host);
System.setProperty("http.proxyPort", port);
String proxyStr = username + ":" + passwd;
String encoded = new String(Base64.encode(proxyStr.getBytes()));
//--------------------------------------------------------------------------------------

TileFactoryInfo info = new TileFactoryInfo(1,max-2,max,
256, true, true, // tile size is 256 and x/y orientation is normal
"http://tile.openstreetmap.org",
"x","y","z") {
public String getTileUrl(int x, int y, int zoom) {
zoom = max-zoom;
String url = this.baseURL +"/"+zoom+"/"+x+"/"+y+".png";
return url;
}

};

TileFactory tf = new DefaultTileFactory(info);

map.setTileFactory(tf);
map.setZoom(12);
map.setAddressLocation(new GeoPosition(51.5,0));

JXMapKit kit = new JXMapKit();
kit.setDefaultProvider(JXMapKit.DefaultProviders.OpenStreetMaps);
return map;
}
}

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jimbo8
Offline
Joined: 2003-10-22
Points: 0

I checked what I did, and this seems to work for me:

Properties systemSettings = System.getProperties();
systemSettings.put("http.proxyHost", "w.x.y.z");
systemSettings.put("http.proxyPort", "8080");
System.setProperties(systemSettings);

On our system there does not seem to be a need to set username and password - I guess the server picks this up from your current session.

I seem to vaguely remember also having some trouble with this.

Jim