Skip to main content

Proxy for JXMapViewer and TileFactory to use OSM tiles

1 reply [Last post]
Joined: 2010-08-12


I downloaded the ExercisingSwing project from, 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
"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.setAddressLocation(new GeoPosition(51.5,0));

JXMapKit kit = new JXMapKit();
return map;

Reply viewing options

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

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");

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.