Skip to content

Commit

Permalink
Initial commit of plugin based on walking papers plugin.
Browse files Browse the repository at this point in the history
  • Loading branch information
iandees committed Jul 16, 2013
0 parents commit b2ef175
Show file tree
Hide file tree
Showing 38 changed files with 775 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry combineaccessrules="false" kind="src" path="/JOSM"/>
<classpathentry kind="output" path="build"/>
</classpath>
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build
.settings

17 changes: 17 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>JOSM-walkingpapers</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
6 changes: 6 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
A plugin for displaying tiled, scanned maps from walking-papers.org.

Written by Frederik Ramm <[email protected]>, based on SlippyMap
plugin work by Lubomir Varga <[email protected]> or <[email protected]>.

Public Domain.
30 changes: 30 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
** This is a template build file for a JOSM plugin.
**
** Maintaining versions
** ====================
** See README.template
**
** Usage
** =====
** Call "ant help" to get possible build targets.
**
-->
<project name="walkingpapers" default="dist" basedir=".">

<!-- enter the SVN commit message -->
<property name="commit.message" value="Changed the constructor signature of the plugin main class"/>
<!-- enter the *lowest* JOSM version this plugin is currently compatible with -->
<property name="plugin.main.version" value="4549"/>

<property name="plugin.author" value="Frederik Ram"/>
<property name="plugin.class" value="org.openstreetmap.josm.plugins.walkingpapers.WalkingPapersPlugin"/>
<property name="plugin.description" value="Supports downloading tiled, scanned maps from walking-papers.org. This plugin is still under early development and may be buggy."/>
<property name="plugin.icon" value="images/preferences/walkingpapers.png"/>
<property name="plugin.link" value="http://wiki.openstreetmap.org/index.php/JOSM/Plugins/WalkingPapers"/>

<!-- ** include targets that all plugins have in common ** -->
<import file="../build-common.xml"/>

</project>
Binary file added data/bg.lang
Binary file not shown.
Binary file added data/ca.lang
Binary file not shown.
Binary file added data/cs.lang
Binary file not shown.
Binary file added data/da.lang
Binary file not shown.
Binary file added data/de.lang
Binary file not shown.
Binary file added data/el.lang
Binary file not shown.
Binary file added data/en.lang
Binary file not shown.
1 change: 1 addition & 0 deletions data/en_AU.lang
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
����������������
1 change: 1 addition & 0 deletions data/en_GB.lang
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
����������������
Binary file added data/es.lang
Binary file not shown.
Binary file added data/et.lang
Binary file not shown.
Binary file added data/eu.lang
Binary file not shown.
Binary file added data/fr.lang
Binary file not shown.
Binary file added data/gl.lang
Binary file not shown.
Binary file added data/id.lang
Binary file not shown.
Binary file added data/it.lang
Binary file not shown.
Binary file added data/ja.lang
Binary file not shown.
Binary file added data/nl.lang
Binary file not shown.
Binary file added data/pl.lang
Binary file not shown.
Binary file added data/pt.lang
Binary file not shown.
Binary file added data/pt_BR.lang
Binary file not shown.
Binary file added data/ru.lang
Binary file not shown.
Binary file added data/sk.lang
Binary file not shown.
Binary file added data/uk.lang
Binary file not shown.
Binary file added data/zh_CN.lang
Binary file not shown.
Binary file added data/zh_TW.lang
Binary file not shown.
Binary file added images/preferences/walkingpapers.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/walkingpapers.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package org.openstreetmap.josm.plugins.fieldpapers;

import static org.openstreetmap.josm.tools.I18n.tr;

import java.awt.event.ActionEvent;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.swing.JOptionPane;

import org.openstreetmap.josm.Main;
import org.openstreetmap.josm.actions.JosmAction;
import org.openstreetmap.josm.data.Bounds;
import org.openstreetmap.josm.data.coor.LatLon;

@SuppressWarnings("serial")
public class FieldPapersAddLayerAction extends JosmAction {

public FieldPapersAddLayerAction() {
super(tr("Scanned Map..."), "walkingpapers",
tr("Display a map that was previously scanned and uploaded to walking-papers.org"), null, false);
}

public void actionPerformed(ActionEvent e) {
String wpid = JOptionPane.showInputDialog(Main.parent,
tr("Enter a walking-papers.org URL or ID (the bit after the ?id= in the URL)"),
Main.pref.get("walkingpapers.last-used-id"));

if (wpid == null || wpid.equals("")) return;

// Grab id= from the URL if we need to, otherwise get an ID
String mungedWpId = this.getWalkingPapersId(wpid);

if (mungedWpId == null || mungedWpId.equals("")) return;

// screen-scrape details about this id from walking-papers.org
String wpUrl = Main.pref.get("walkingpapers.base-url", "http://walking-papers.org/") + "scan.php?id=" + mungedWpId;

Pattern spanPattern = Pattern.compile("<span class=\"(\\S+)\">(\\S+)</span>");
Matcher m;

double north = 0;
double south = 0;
double east = 0;
double west = 0;
int minz = -1;
int maxz = -1;
String tile = null;

try {
BufferedReader r = new BufferedReader(new InputStreamReader(new URL(wpUrl).openStream(), "utf-8"));
for (String line = r.readLine(); line != null; line = r.readLine()) {
m = spanPattern.matcher(line);
if (m.find()) {
if ("tile".equals(m.group(1))) tile = m.group(2);
else if ("north".equals(m.group(1))) north = Double.parseDouble(m.group(2));
else if ("south".equals(m.group(1))) south = Double.parseDouble(m.group(2));
else if ("east".equals(m.group(1))) east = Double.parseDouble(m.group(2));
else if ("west".equals(m.group(1))) west = Double.parseDouble(m.group(2));
else if ("minzoom".equals(m.group(1))) minz = Integer.parseInt(m.group(2));
else if ("maxzoom".equals(m.group(1))) maxz = Integer.parseInt(m.group(2));
}
}
r.close();
if ((tile == null) || (north == 0 && south == 0) || (east == 0 && west == 0)) throw new Exception();
} catch (Exception ex) {
JOptionPane.showMessageDialog(Main.parent,tr("Could not read information from walking-papers.org the id \"{0}\"", mungedWpId));
return;
}


//http://walking-papers.org/scan.php?id=rmvdr3lq
// The server is apparently broken and returning the WpId in the URL twice
// which makes it return errors when we fetch it. So, strip out one of
// the dups. This is a hack and needs to get removed when the server
// is fixed.
tile = tile.replaceFirst(mungedWpId+"/"+mungedWpId, mungedWpId);
Main.pref.put("walkingpapers.last-used-id", mungedWpId);

Bounds b = new Bounds(new LatLon(south, west), new LatLon(north, east));

FieldPapersLayer wpl = new FieldPapersLayer(mungedWpId, tile, b, minz, maxz);
Main.main.addLayer(wpl);

}

private static String getWalkingPapersId(String wpid) {
if (!wpid.contains("id=")) {
return wpid;
} else {
// To match e.g. http://walking-papers.org/scan.php?id=53h78bbx
final Pattern pattern = Pattern.compile("\\?id=(\\S+)");
final Matcher matcher = pattern.matcher(wpid);
final boolean found = matcher.find();

if (found) {
return matcher.group(1);
}
}
return null;
}
}
78 changes: 78 additions & 0 deletions src/org/openstreetmap/josm/plugins/fieldpapers/FieldPapersKey.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/**
*
*/
package org.openstreetmap.josm.plugins.fieldpapers;

/**
* <p>
* Key for map tile. Key have just X and Y value. It have overriden {@link #hashCode()},
* {@link #equals(Object)} and also {@link #toString()}.
* </p>
*
* @author LuVar <[email protected]>
* @author Dave Hansen <[email protected]>
*
*/
public class FieldPapersKey {
private final int x;
private final int y;
private final int level;

/**
* <p>
* Constructs key for hashmaps for some tile describedy by X and Y position. X and Y are tiles
* positions on discrete map.
* </p>
*
* @param x x position in tiles table
* @param y y position in tiles table
*/
public final boolean valid;
public FieldPapersKey(int level, int x, int y) {
this.x = x;
this.y = y;
this.level = level;
if (level <= 0 || x < 0 || y < 0) {
this.valid = false;
System.err.println("invalid WalkingPapersKey("+level+", "+x+", "+y+")");
} else {
this.valid = true;
}
}

/**
* <p>
* Returns true ONLY if x and y are equals.
* </p>
*
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (obj instanceof FieldPapersKey) {
FieldPapersKey smk = (FieldPapersKey) obj;
if((smk.x == this.x) && (smk.y == this.y) && (smk.level == this.level)) {
return true;
}
}
return false;
}

/**
* @return return new Integer(this.x + this.y * 10000).hashCode();
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
return new Integer(this.x + this.y * 10000 + this.level * 100000).hashCode();
}

/**
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "WalkingPapersKey(x=" + this.x + ",y=" + this.y + ",level=" + level + ")";
}

}
Loading

0 comments on commit b2ef175

Please sign in to comment.