Changeset 31418 in osm for applications
- Timestamp:
- 2015-07-30T13:17:49+02:00 (9 years ago)
- Location:
- applications/editors/josm/plugins/mapillary
- Files:
-
- 1 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryData.java
r31415 r31418 68 68 */ 69 69 public synchronized void add(List<MapillaryAbstractImage> images) { 70 add(images, true); 71 } 72 73 /** 74 * Adds an MapillaryImage to the object, and then repaints mapView. 75 * 76 * @param image 77 * The image to be added. 78 */ 79 public synchronized void add(MapillaryAbstractImage image) { 80 add(image, true); 81 } 82 83 /** 84 * Adds a new listener. 85 * 86 * @param lis 87 * Listener to be added. 88 */ 89 public void addListener(MapillaryDataListener lis) { 90 listeners.add(lis); 91 } 92 93 /** 94 * Removes a listener. 95 * 96 * @param lis 97 * Listener to be removed. 98 */ 99 public void removeListener(MapillaryDataListener lis) { 100 listeners.remove(lis); 101 } 102 103 /** 104 * Adds a set of MapillaryImages to the object, but doesn't repaint mapView. 105 * This is needed for concurrency. 106 * 107 * @param images 108 * The set of images to be added. 109 * @param update 110 * Whether the map must be updated or no. 111 */ 112 public synchronized void add(List<MapillaryAbstractImage> images, 113 boolean update) { 70 114 for (MapillaryAbstractImage image : images) { 71 add(image); 72 } 73 } 74 75 /** 76 * Adds an MapillaryImage to the object, and then repaints mapView. 115 add(image, update); 116 } 117 } 118 119 /** 120 * Highlights the image under the cursor. 121 * 122 * @param image 123 * The image under the cursor. 124 */ 125 public void setHighlightedImage(MapillaryAbstractImage image) { 126 highlightedImage = image; 127 } 128 129 /** 130 * Returns the image under the mouse cursor. 131 * 132 * @return The image under the mouse cursor. 133 */ 134 public MapillaryAbstractImage getHighlighted() { 135 return highlightedImage; 136 } 137 138 /** 139 * Adds a MapillaryImage to the object, but doesn't repaint mapView. This is 140 * needed for concurrency. 77 141 * 78 142 * @param image 79 143 * The image to be added. 80 */ 81 public synchronized void add(MapillaryAbstractImage image) { 144 * @param update 145 * Whether the map must be updated or not. 146 */ 147 public synchronized void add(MapillaryAbstractImage image, boolean update) { 82 148 if (!images.contains(image)) { 83 149 this.images.add(image); 84 150 } 85 dataUpdated(); 86 fireImagesAdded(); 87 } 88 89 /** 90 * Adds a new listener. 91 * 92 * @param lis 93 * Listener to be added. 94 */ 95 public void addListener(MapillaryDataListener lis) { 96 listeners.add(lis); 97 } 98 99 /** 100 * Removes a listener. 101 * 102 * @param lis 103 * Listener to be removed. 104 */ 105 public void removeListener(MapillaryDataListener lis) { 106 listeners.remove(lis); 107 } 108 109 /** 110 * Adds a set of MapillaryImages to the object, but doesn't repaint mapView. 111 * This is needed for concurrency. 112 * 113 * @param images 114 * The set of images to be added. 115 */ 116 public synchronized void addWithoutUpdate(List<MapillaryAbstractImage> images) { 117 for (MapillaryAbstractImage image : images) { 118 addWithoutUpdate(image); 119 } 120 } 121 122 /** 123 * Highlights the image under the cursor. 124 * 125 * @param image 126 * The image under the cursor. 127 */ 128 public void setHighlightedImage(MapillaryAbstractImage image) { 129 highlightedImage = image; 130 } 131 132 /** 133 * Returns the image under the mouse cursor. 134 * 135 * @return The image under the mouse cursor. 136 */ 137 public MapillaryAbstractImage getHighlighted() { 138 return highlightedImage; 139 } 140 141 /** 142 * Adds a MapillaryImage to the object, but doesn't repaint mapView. This is 143 * needed for concurrency. 144 * 145 * @param image 146 * The image to be added. 147 */ 148 public synchronized void addWithoutUpdate(MapillaryAbstractImage image) { 149 if (!images.contains(image)) { 150 this.images.add(image); 151 } 151 if (update) 152 dataUpdated(); 152 153 fireImagesAdded(); 153 154 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryPlugin.java
r31417 r31418 52 52 private final MapillaryDownloadAction downloadAction; 53 53 private final MapillaryExportAction exportAction; 54 /** Import action */ 54 55 public static MapillaryImportAction importAction; 55 56 private final MapillaryZoomAction zoomAction; -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryImportAction.java
r31417 r31418 50 50 */ 51 51 public MapillaryImportAction() { 52 super(tr("Import pictures"), new ImageProvider(MapillaryPlugin.directory + "images/icon24.png"), 53 tr("Import local pictures"), Shortcut.registerShortcut( 54 "Import Mapillary", tr("Import pictures into Mapillary layer"), 52 super(tr("Import pictures"), new ImageProvider(MapillaryPlugin.directory 53 + "images/icon24.png"), tr("Import local pictures"), Shortcut 54 .registerShortcut("Import Mapillary", 55 tr("Import pictures into Mapillary layer"), 55 56 KeyEvent.CHAR_UNDEFINED, Shortcut.NONE), false, "mapillaryImport", 56 57 false); … … 174 175 */ 175 176 public MapillaryImportedImage readNoTags(File file) { 177 return readNoTags( 178 file, 179 Main.map.mapView.getProjection().eastNorth2latlon( 180 Main.map.mapView.getCenter())); 181 } 182 183 /** 184 * Reads a image file that doesn't contain the needed GPS information. And 185 * creates a new icon in the middle of the map. 186 * 187 * @param file 188 * @param pos 189 * A {@link LatLon} object indicating the position in the map where 190 * the image must be set. 191 * @return The imported image. 192 */ 193 public MapillaryImportedImage readNoTags(File file, LatLon pos) { 176 194 double HORIZONTAL_DISTANCE = 0.0001; 177 195 double horDev; … … 180 198 else 181 199 horDev = -HORIZONTAL_DISTANCE * ((noTagsPics + 1) / 2); 182 LatLon pos = Main.map.mapView.getProjection().eastNorth2latlon(183 Main.map.mapView.getCenter());184 200 noTagsPics++; 185 201 return new MapillaryImportedImage(pos.lat(), pos.lon() + horDev, 0, file); … … 246 262 result += degMinSec[2].doubleValue() / 3600; // seconds 247 263 248 while (result >= 180) {249 result -= 180;250 }251 while (result <= -180) {252 result += 180;253 }254 255 264 if (GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF_VALUE_SOUTH.equals(ref) 256 265 || GpsTagConstants.GPS_TAG_GPS_LONGITUDE_REF_VALUE_WEST.equals(ref)) { … … 258 267 } 259 268 269 result = 360*((result+180)/360 - Math.floor((result+180)/360)) - 180; 260 270 return result; 261 271 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillaryDownloader.java
r31409 r31418 33 33 public final static String BASE_URL = "https://a.mapillary.com/v2/"; 34 34 /** Client ID for the app */ 35 public final static String CLIENT_ID = " NzNRM2otQkR2SHJzaXJmNmdQWVQ0dzo1YTA2NmNlODhlNWMwOTBm";35 public final static String CLIENT_ID = "T1Fzd20xZjdtR0s1VDk5OFNIOXpYdzoxNDYyOGRkYzUyYTFiMzgz"; 36 36 /** Executor that will run the petitions. */ 37 37 private static ThreadPoolExecutor EXECUTOR = new ThreadPoolExecutor(3, 5, -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillarySequenceDownloadThread.java
r31417 r31418 118 118 } 119 119 120 layer.getMapillaryData().add WithoutUpdate(121 new ArrayList<MapillaryAbstractImage>(finalImages) );120 layer.getMapillaryData().add( 121 new ArrayList<MapillaryAbstractImage>(finalImages), false); 122 122 } 123 123 } catch (IOException e) { … … 125 125 + " might be a Mapillary problem."); 126 126 } 127 layer.getMapillaryData().dataUpdated(); 127 128 } 128 129 -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryPreferenceSetting.java
r31406 r31418 84 84 oauth.setText("Login"); 85 85 else 86 oauth.setText(" Already loged in, click to relogin.");86 oauth.setText("Logged as: " + Main.pref.get("mapillary.username") + ". Click to relogin."); 87 87 panel.add(oauth); 88 88 gui.getDisplayPreference().addSubTab(this, "Mapillary", panel); … … 130 130 portListener.start(); 131 131 132 String url = "http://www.mapillary. io/connect?redirect_uri=http:%2F%2Flocalhost:8763%2F&client_id=MkJKbDA0bnZuZlcxeTJHTmFqN3g1dzplZTlkZjQyYjYyZTczOTdi&response_type=token&scope=user:email";132 String url = "http://www.mapillary.com/connect?redirect_uri=http:%2F%2Flocalhost:8763%2F&client_id=T1Fzd20xZjdtR0s1VDk5OFNIOXpYdzoxNDYyOGRkYzUyYTFiMzgz&response_type=token&scope=user:read%20public:upload%20public:write"; 133 133 Desktop desktop = Desktop.getDesktop(); 134 134 if (desktop.isSupported(Desktop.Action.BROWSE)) { -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/OAuthPortListener.java
r31412 r31418 8 8 import java.net.ServerSocket; 9 9 import java.net.Socket; 10 import java.net.URL; 10 11 import java.util.Scanner; 11 12 … … 25 26 ServerSocket serverSocket = new ServerSocket(8763); 26 27 Socket clientSocket = serverSocket.accept(); 27 PrintWriter out = new PrintWriter(new OutputStreamWriter(clientSocket.getOutputStream(), "UTF-8"), true); 28 Scanner in = new Scanner(new InputStreamReader(clientSocket.getInputStream(), "UTF-8")); 28 PrintWriter out = new PrintWriter(new OutputStreamWriter( 29 clientSocket.getOutputStream(), "UTF-8"), true); 30 Scanner in = new Scanner(new InputStreamReader( 31 clientSocket.getInputStream(), "UTF-8")); 29 32 String s; 30 33 String accessToken = null; … … 41 44 } 42 45 break; 43 } 46 } else if (s.contains("keep-alive")) 47 break; 44 48 } 45 49 46 50 writeContent(out); 47 51 48 Main.info("Successful login with Mapillary, the access token is: "49 + accessToken);50 Main.pref.put("mapillary.access-token", accessToken);51 52 52 out.close(); 53 53 in.close(); 54 54 serverSocket.close(); 55 56 Main.info("Successful login with Mapillary, the access token is: " 57 + accessToken); 58 // Saves the access token in preferences. 59 Main.pref.put("mapillary.access-token", accessToken); 60 // Sets the logged username in preferences. 61 Main.pref 62 .put( 63 "mapillary.username", 64 OAuthUtils 65 .getWithHeader( 66 new URL( 67 "https://a.mapillary.com/v2/me?client_id=T1Fzd20xZjdtR0s1VDk5OFNIOXpYdzoxNDYyOGRkYzUyYTFiMzgz")) 68 .getString("username")); 69 70 Main.info("The username is: " + Main.pref.get("mapillary.username")); 71 55 72 } catch (BindException e) { 56 73 return; -
applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/AbstractTest.java
r31417 r31418 2 2 3 3 import org.junit.BeforeClass; 4 import org.openstreetmap.josm.Main;5 import org.openstreetmap.josm.gui.MainApplication;6 4 import org.openstreetmap.josm.plugins.mapillary.util.TestUtil; 7 5 6 /** 7 * Abstract class for tests that require JOSM's preferences running. 8 * 9 * @author nokutu 10 * 11 */ 8 12 public abstract class AbstractTest { 9 13 10 14 private static boolean started = false; 11 15 16 /** 17 * Initiates the basic parts of JOSM. 18 */ 12 19 @BeforeClass 13 public static void setUpBeforeClass() throws Exception{20 public static void setUpBeforeClass() { 14 21 if (!started) { 15 new Thread() { 16 @Override 17 public synchronized void run() { 18 MainApplication 19 .main(new String[] { "--download=http://www.openstreetmap.org/#map=18/40.42013/-3.68923" }); 20 } 21 }.start(); 22 TestUtil.initPlugin(); 22 23 started = true; 23 while (Main.map == null || Main.map.mapView == null) {24 synchronized (Thread.currentThread()) {25 Thread.currentThread().wait(1000);26 }27 }28 24 } 29 25 } -
applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/AllTests.java
r31417 r31418 4 4 import org.junit.runners.Suite; 5 5 import org.junit.runners.Suite.SuiteClasses; 6 import org.openstreetmap.josm.plugins.mapillary.util.TestUtil;7 6 7 /** 8 * Runs all tests. 9 * 10 * @author nokutu 11 * 12 */ 8 13 @RunWith(Suite.class) 9 @SuiteClasses({ ImportTest.class, 10 MapillarySequenceDownloadThreadTest.class}) 14 @SuiteClasses({ ImportTest.class, MapillarySequenceDownloadThreadTest.class }) 11 15 public class AllTests { 12 16 } -
applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/ImportTest.java
r31417 r31418 2 2 3 3 import static org.junit.Assert.*; 4 import org.junit.Test; 4 5 5 6 import java.io.File; … … 10 11 import org.apache.commons.imaging.common.RationalNumber; 11 12 import org.apache.commons.imaging.formats.tiff.constants.GpsTagConstants; 12 import org.junit.BeforeClass;13 import org.junit.Test;14 import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate;15 13 import org.openstreetmap.josm.Main; 16 14 import org.openstreetmap.josm.data.coor.LatLon; 17 import org.openstreetmap.josm.gui.MainApplication;18 15 import org.openstreetmap.josm.plugins.mapillary.actions.MapillaryImportAction; 19 16 20 public class ImportTest extends AbstractTest{ 17 /** 18 * Test the importation of images. 19 * 20 * @author nokutu 21 * 22 */ 23 public class ImportTest extends AbstractTest { 21 24 25 /** 26 * Test the importation of images in PNG format. 27 */ 22 28 @Test 23 public void importNoTagsTest() throws InterruptedException{29 public void importNoTagsTest() { 24 30 File image = new File(MapillaryPlugin.directory + "images/icon16.png"); 25 MapillaryImportedImage img = MapillaryPlugin.importAction.readNoTags(image); 31 MapillaryImportedImage img = MapillaryPlugin.importAction.readNoTags(image, 32 new LatLon(0, 0)); 26 33 assertEquals(0, img.getCa(), 0.01); 27 assert(Main.map.mapView.getRealBounds().getCenter().equalsEpsilon(img.getLatLon())); 34 assert (Main.map.mapView.getRealBounds().getCenter().equalsEpsilon(img 35 .getLatLon())); 28 36 } 29 37 30 @Test(expected=IIOException.class) 38 /** 39 * Test if provided an invalid file, the proper exception is thrown. 40 * 41 * @throws IOException 42 */ 43 @Test(expected = IIOException.class) 31 44 public void testInvalidFiles() throws IOException { 32 MapillaryImportedImage img = new MapillaryImportedImage(0,0,0, null);33 34 45 MapillaryImportedImage img = new MapillaryImportedImage(0, 0, 0, null); 46 assertEquals(null, img.getImage()); 47 assertEquals(null, img.getFile()); 35 48 36 37 38 49 img = new MapillaryImportedImage(0, 0, 0, new File("")); 50 assertEquals(new File(""), img.getFile()); 51 img.getImage(); 39 52 } 40 53 54 /** 55 * Test degMinSecToDouble method. 56 */ 41 57 @Test 42 58 public void degMinSecToDoubleTest() { -
applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/util/TestUtil.java
r31417 r31418 11 11 import org.openstreetmap.josm.tools.I18n; 12 12 13 /** 14 * 15 * Utilities for tests. 16 * 17 * @author floscher 18 */ 13 19 public class TestUtil { 14 20 private static boolean isInitialized; 15 21 16 private TestUtil() { 17 // Prevent instantiation 22 private TestUtil() { 23 // Prevent instantiation 24 } 25 26 /** 27 * Initializes the {@link Main} class of JOSM and the mapillary plugin with 28 * the preferences from test/data/preferences. 29 * 30 * That is needed e.g. to use {@link MapillaryLayer#getInstance()} 31 */ 32 public static final void initPlugin() { 33 if (!isInitialized) { 34 System.setProperty("josm.home", "test/data/preferences"); 35 Main.initApplicationPreferences(); 36 Main.pref.enableSaveOnPut(false); 37 I18n.init(); 38 Main.determinePlatformHook(); 39 Main.platform.preStartupHook(); 40 Main.pref.init(false); 41 I18n.set(Main.pref.get("language", "en")); 42 Main.setProjection(Projections.getProjectionByCode("EPSG:3857")); // Mercator 43 try { 44 new MapillaryPlugin(new PluginInformation(new File( 45 "./build/libs/josm-mapillary-plugin.jar"))); 46 } catch (PluginException e) { 47 e.printStackTrace(); 48 } 49 isInitialized = true; 18 50 } 19 20 /** 21 * Initializes the {@link Main} class of JOSM and the mapillary plugin 22 * with the preferences from test/data/preferences. 23 * 24 * That is needed e.g. to use {@link MapillaryLayer#getInstance()} 25 */ 26 public static final void initPlugin() { 27 if (!isInitialized) { 28 System.setProperty("josm.home", "test/data/preferences"); 29 Main.initApplicationPreferences(); 30 Main.pref.enableSaveOnPut(false); 31 I18n.init(); 32 Main.determinePlatformHook(); 33 Main.platform.preStartupHook(); 34 Main.pref.init(false); 35 I18n.set(Main.pref.get("language", "en")); 36 Main.setProjection(Projections.getProjectionByCode("EPSG:3857")); // Mercator 37 try { 38 new MapillaryPlugin(new PluginInformation(new File("/home/nokutu/.josm/plugins/Mapillary.jar"))); 39 } catch (PluginException e) { 40 // TODO Auto-generated catch block 41 e.printStackTrace(); 42 } 43 isInitialized = true; 44 } 45 } 51 } 46 52 47 53 }
Note:
See TracChangeset
for help on using the changeset viewer.