- Timestamp:
- 2017-04-13T00:13:59+02:00 (8 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/layer/markerlayer
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/Marker.java
r11850 r11892 10 10 import java.awt.image.BufferedImage; 11 11 import java.io.File; 12 import java.net.MalformedURLException;13 import java.net.URL;14 12 import java.text.DateFormat; 15 13 import java.text.SimpleDateFormat; 16 14 import java.util.ArrayList; 17 import java.util.Arrays;18 15 import java.util.Collection; 19 import java.util.Collections;20 16 import java.util.Date; 21 17 import java.util.HashMap; … … 23 19 import java.util.List; 24 20 import java.util.Map; 25 import java.util.Optional;26 21 import java.util.TimeZone; 27 22 … … 34 29 import org.openstreetmap.josm.data.coor.EastNorth; 35 30 import org.openstreetmap.josm.data.coor.LatLon; 36 import org.openstreetmap.josm.data.gpx.Extensions;37 31 import org.openstreetmap.josm.data.gpx.GpxConstants; 38 import org.openstreetmap.josm.data.gpx.GpxLink;39 32 import org.openstreetmap.josm.data.gpx.WayPoint; 40 33 import org.openstreetmap.josm.data.preferences.CachedProperty; … … 42 35 import org.openstreetmap.josm.gui.MapView; 43 36 import org.openstreetmap.josm.tools.ImageProvider; 44 import org.openstreetmap.josm.tools.Utils;45 37 import org.openstreetmap.josm.tools.template_engine.ParseError; 46 38 import org.openstreetmap.josm.tools.template_engine.TemplateEngineDataProvider; … … 184 176 // Add one Marker specifying the default behaviour. 185 177 static { 186 Marker.markerProducers.add((wpt, relativePath, parentLayer, time, offset) -> { 187 String uri = null; 188 // cheapest way to check whether "link" object exists and is a non-empty collection of GpxLink objects... 189 Collection<GpxLink> links = wpt.<GpxLink>getCollection(GpxConstants.META_LINKS); 190 if (links != null) { 191 for (GpxLink oneLink : links) { 192 uri = oneLink.uri; 193 break; 194 } 195 } 196 197 URL url = uriToUrl(uri, relativePath); 198 String urlStr = url == null ? "" : url.toString(); 199 String symbolName = Optional.ofNullable(wpt.getString("symbol")).orElseGet(() -> wpt.getString(GpxConstants.PT_SYM)); 200 // text marker is returned in every case, see #10208 201 final Marker marker = new Marker(wpt.getCoor(), wpt, symbolName, parentLayer, time, offset); 202 if (url == null) { 203 return Collections.singleton(marker); 204 } else if (urlStr.endsWith(".wav")) { 205 final AudioMarker audioMarker = new AudioMarker(wpt.getCoor(), wpt, url, parentLayer, time, offset); 206 Extensions exts = (Extensions) wpt.get(GpxConstants.META_EXTENSIONS); 207 if (exts != null && exts.containsKey("offset")) { 208 try { 209 audioMarker.syncOffset = Double.parseDouble(exts.get("sync-offset")); 210 } catch (NumberFormatException nfe) { 211 Main.warn(nfe); 212 } 213 } 214 return Arrays.asList(marker, audioMarker); 215 } else if (urlStr.endsWith(".png") || urlStr.endsWith(".jpg") || urlStr.endsWith(".jpeg") || urlStr.endsWith(".gif")) { 216 return Arrays.asList(marker, new ImageMarker(wpt.getCoor(), url, parentLayer, time, offset)); 217 } else { 218 return Arrays.asList(marker, new WebMarker(wpt.getCoor(), url, parentLayer, time, offset)); 219 } 220 }); 178 Marker.markerProducers.add(new DefaultMarkerProducers()); 221 179 } 222 180 … … 237 195 public static void prependMarkerProducer(MarkerProducers mp) { 238 196 markerProducers.add(0, mp); 239 }240 241 private static URL uriToUrl(String uri, File relativePath) {242 URL url = null;243 if (uri != null) {244 try {245 url = new URL(uri);246 } catch (MalformedURLException e) {247 // Try a relative file:// url, if the link is not in an URL-compatible form248 if (relativePath != null) {249 url = Utils.fileToURL(new File(relativePath.getParentFile(), uri));250 }251 }252 }253 return url;254 197 } 255 198
Note:
See TracChangeset
for help on using the changeset viewer.