Changeset 27015 in osm for applications/editors/josm/plugins/imagery-xml-bounds/src/org
- Timestamp:
- 2011-11-05T19:25:22+01:00 (13 years ago)
- Location:
- applications/editors/josm/plugins/imagery-xml-bounds
- Files:
-
- 4 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/imagery-xml-bounds
- Property svn:ignore
-
old new 1 1 build 2 2 .settings 3 bin
-
- Property svn:ignore
-
applications/editors/josm/plugins/imagery-xml-bounds/src/org/openstreetmap/josm/plugins/imageryxmlbounds/ImageryXmlBoundsPlugin.java
r26900 r27015 21 21 import org.openstreetmap.josm.data.osm.DataSet; 22 22 import org.openstreetmap.josm.gui.MapFrame; 23 import org.openstreetmap.josm.gui.preferences.PreferenceSetting; 23 24 import org.openstreetmap.josm.plugins.Plugin; 24 25 import org.openstreetmap.josm.plugins.PluginInformation; … … 33 34 * Main class of Imagery XML bounds plugin. 34 35 * @author Don-vip 35 * @version 1. 236 * @version 1.3 36 37 * History: 38 * 1.3 05-Nov-2011 Update for JOSM 4577 (allow to edit selected default imagery entries from Preferences dialog) 37 39 * 1.2 17-Oct-2011 Update for #6960 and JOSM 4523 (allow to download imagery XML bounds with Ctrl-L) 38 40 * 1.1 08-Oct-2011 Update for #6934 and JOSM 4506, code refactorisation, removing debug code … … 62 64 63 65 /** 66 * Class modifying the Imagery preferences panel 67 */ 68 private final XmlBoundsPreferenceSetting preferenceSetting = new XmlBoundsPreferenceSetting(); 69 70 /** 64 71 * Initializes the plugin. 65 72 * @param info … … 79 86 } 80 87 } 88 89 /* (non-Javadoc) 90 * @see org.openstreetmap.josm.plugins.Plugin#getPreferenceSetting() 91 */ 92 @Override 93 public PreferenceSetting getPreferenceSetting() { 94 return this.preferenceSetting; 95 } 81 96 82 97 /* (non-Javadoc) -
applications/editors/josm/plugins/imagery-xml-bounds/src/org/openstreetmap/josm/plugins/imageryxmlbounds/XmlBoundsConstants.java
r26896 r27015 33 33 * Plugin version. 34 34 */ 35 public static final String PLUGIN_VERSION = "1. 2";35 public static final String PLUGIN_VERSION = "1.3"; 36 36 37 37 /** -
applications/editors/josm/plugins/imagery-xml-bounds/src/org/openstreetmap/josm/plugins/imageryxmlbounds/XmlBoundsLayer.java
r26776 r27015 80 80 private static final Map<JosmAction, Boolean> actionsStates = new HashMap<JosmAction, Boolean>(); 81 81 82 public XmlBoundsLayer(DataSet data) { 83 this(data, OsmDataLayer.createNewName(), null); 84 } 85 82 86 public XmlBoundsLayer(DataSet data, String name, File associatedFile) { 83 87 super(data, name, associatedFile); -
applications/editors/josm/plugins/imagery-xml-bounds/src/org/openstreetmap/josm/plugins/imageryxmlbounds/io/XmlBoundsImporter.java
r26896 r27015 20 20 import java.io.File; 21 21 import java.io.IOException; 22 import java.util.Collection;23 22 import java.util.List; 24 23 … … 26 25 import javax.swing.SwingUtilities; 27 26 28 import org.openstreetmap.gui.jmapviewer.Coordinate;29 27 import org.openstreetmap.josm.Main; 30 import org.openstreetmap.josm.data.coor.LatLon;31 import org.openstreetmap.josm.data.imagery.ImageryInfo;32 import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryBounds;33 import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType;34 import org.openstreetmap.josm.data.imagery.Shape;35 import org.openstreetmap.josm.data.osm.BBox;36 28 import org.openstreetmap.josm.data.osm.DataSet; 37 import org.openstreetmap.josm.data.osm.Node;38 import org.openstreetmap.josm.data.osm.OsmPrimitive;39 import org.openstreetmap.josm.data.osm.Relation;40 import org.openstreetmap.josm.data.osm.RelationMember;41 import org.openstreetmap.josm.data.osm.Way;42 29 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 43 30 import org.openstreetmap.josm.io.FileImporter; … … 46 33 import org.openstreetmap.josm.plugins.imageryxmlbounds.XmlBoundsConstants; 47 34 import org.openstreetmap.josm.plugins.imageryxmlbounds.XmlBoundsLayer; 35 import org.openstreetmap.josm.plugins.imageryxmlbounds.data.XmlBoundsConverter; 48 36 import org.xml.sax.SAXException; 49 37 … … 56 44 public XmlBoundsImporter() { 57 45 super(FILE_FILTER); 58 }59 60 public DataSet convertImageryEntries(List<ImageryInfo> entries) {61 DataSet dataSet = new DataSet();62 63 for (ImageryInfo imagery : entries) {64 if (!imagery.isBlacklisted()) {65 ImageryBounds bounds = imagery.getBounds();66 if (bounds != null) {67 dataSet.addPrimitive(convertImagery(imagery, bounds, dataSet));68 }69 }70 }71 return dataSet;72 }73 74 private void safePut(OsmPrimitive p, String key, Object value) {75 if (value != null) {76 if (value instanceof Collection) {77 String s = "";78 for (Object elt : (Collection<?>)value) {79 if (elt != null && elt.toString() != null && !elt.toString().isEmpty()) {80 if (!s.isEmpty()) {81 s += ";";82 }83 s += elt.toString();84 }85 }86 if (!s.isEmpty()) {87 p.put(key, s);88 }89 } else if (!value.equals(0) && value.toString() != null && !value.toString().isEmpty()) {90 p.put(key, value.toString());91 }92 }93 }94 95 private Node getNode(LatLon latlon, DataSet dataSet) {96 List<Node> nodes = dataSet.searchNodes(new BBox(latlon, latlon));97 if (!nodes.isEmpty()) {98 return nodes.get(0);99 } else {100 Node node = new Node(latlon);101 dataSet.addPrimitive(node);102 return node;103 }104 }105 106 private Node getNode(double lat, double lon, DataSet dataSet) {107 return getNode(new LatLon(lat, lon), dataSet);108 }109 110 private void ensureWayIsClosed(Way way) {111 if (!way.getNode(0).equals(way.getNode(way.getNodesCount()-1))) {112 way.addNode(way.getNode(0));113 }114 }115 116 private OsmPrimitive convertImagery(ImageryInfo imagery, ImageryBounds bounds, DataSet dataSet) {117 OsmPrimitive osmImagery = null;118 if (bounds.getShapes().isEmpty()) {119 LatLon bottomLeft = bounds.getMin();120 LatLon topRight = bounds.getMax();121 LatLon topLeft = new LatLon(topRight.lat(), bottomLeft.lon());122 LatLon bottomRight = new LatLon(bottomLeft.lat(), topRight.lon());123 124 Way way = new Way();125 for (LatLon ll : new LatLon[]{bottomLeft, topLeft, topRight, bottomRight}) {126 way.addNode(getNode(ll, dataSet));127 }128 ensureWayIsClosed(way);129 osmImagery = way;130 131 } else {132 Relation relation = new Relation();133 relation.put("type", "multipolygon");134 for (Shape shape : bounds.getShapes()) {135 Way way = new Way();136 for (Coordinate coor : shape.getPoints()) {137 way.addNode(getNode(coor.getLat(), coor.getLon(), dataSet));138 }139 ensureWayIsClosed(way);140 dataSet.addPrimitive(way);141 relation.addMember(new RelationMember("outer", way));142 }143 osmImagery = relation;144 }145 146 safePut(osmImagery, KEY_NAME, imagery.getName());147 safePut(osmImagery, KEY_TYPE, imagery.getImageryType().getUrlString());148 safePut(osmImagery, KEY_DEFAULT, imagery.isDefaultEntry());149 safePut(osmImagery, KEY_URL, imagery.getUrl());150 safePut(osmImagery, KEY_PROJECTIONS, imagery.getServerProjections());151 safePut(osmImagery, KEY_EULA, imagery.getEulaAcceptanceRequired());152 safePut(osmImagery, KEY_ATTR_TEXT, imagery.getAttributionText(0, null, null));153 safePut(osmImagery, KEY_ATTR_URL, imagery.getAttributionLinkURL());154 safePut(osmImagery, KEY_TERMS_TEXT, imagery.getTermsOfUseText());155 safePut(osmImagery, KEY_TERMS_URL, imagery.getTermsOfUseURL());156 safePut(osmImagery, KEY_COUNTRY_CODE, imagery.getCountryCode());157 safePut(osmImagery, KEY_LOGO_URL, imagery.getAttributionImageURL());158 159 if (imagery.getImageryType().equals(ImageryType.TMS)) {160 safePut(osmImagery, KEY_MAX_ZOOM, imagery.getMaxZoom());161 safePut(osmImagery, KEY_MIN_ZOOM, imagery.getMinZoom());162 }163 164 return osmImagery;165 46 } 166 47 … … 191 72 } 192 73 193 return convertImageryEntries(reader.parse());74 return XmlBoundsConverter.convertImageryEntries(reader.parse()); 194 75 } 195 76
Note:
See TracChangeset
for help on using the changeset viewer.