Ignore:
Timestamp:
2011-11-05T19:25:22+01:00 (13 years ago)
Author:
donvip
Message:

JOSM Imagery-XML-Bounds plugin version 1.3 : allow to edit selected default imagery entries from Preferences dialog

Location:
applications/editors/josm/plugins/imagery-xml-bounds
Files:
4 added
6 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/imagery-xml-bounds

    • Property svn:ignore
      •  

        old new  
        11build
        22.settings
         3bin
  • applications/editors/josm/plugins/imagery-xml-bounds/build.xml

    r26990 r27015  
    3232    <property name="commit.message" value="Commit message"/>
    3333    <!-- enter the *lowest* JOSM version this plugin is currently compatible with -->
    34     <property name="plugin.main.version" value="4549"/>
     34    <property name="plugin.main.version" value="4577"/>
    3535    <!-- should not be necessary to change the following properties -->
    3636    <property name="josm" location="../../core/dist/josm-custom.jar"/>
  • applications/editors/josm/plugins/imagery-xml-bounds/src/org/openstreetmap/josm/plugins/imageryxmlbounds/ImageryXmlBoundsPlugin.java

    r26900 r27015  
    2121import org.openstreetmap.josm.data.osm.DataSet;
    2222import org.openstreetmap.josm.gui.MapFrame;
     23import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
    2324import org.openstreetmap.josm.plugins.Plugin;
    2425import org.openstreetmap.josm.plugins.PluginInformation;
     
    3334 * Main class of Imagery XML bounds plugin.
    3435 * @author Don-vip
    35  * @version 1.2
     36 * @version 1.3
    3637 * History:
     38 * 1.3 05-Nov-2011 Update for JOSM 4577 (allow to edit selected default imagery entries from Preferences dialog)
    3739 * 1.2 17-Oct-2011 Update for #6960 and JOSM 4523 (allow to download imagery XML bounds with Ctrl-L)
    3840 * 1.1 08-Oct-2011 Update for #6934 and JOSM 4506, code refactorisation, removing debug code
     
    6264       
    6365        /**
     66         * Class modifying the Imagery preferences panel
     67         */
     68        private final XmlBoundsPreferenceSetting preferenceSetting = new XmlBoundsPreferenceSetting();
     69       
     70        /**
    6471         * Initializes the plugin.
    6572         * @param info
     
    7986                }
    8087        }
     88       
     89    /* (non-Javadoc)
     90     * @see org.openstreetmap.josm.plugins.Plugin#getPreferenceSetting()
     91     */
     92    @Override
     93    public PreferenceSetting getPreferenceSetting() {
     94        return this.preferenceSetting;
     95    }
    8196
    8297        /* (non-Javadoc)
  • applications/editors/josm/plugins/imagery-xml-bounds/src/org/openstreetmap/josm/plugins/imageryxmlbounds/XmlBoundsConstants.java

    r26896 r27015  
    3333         * Plugin version.
    3434         */
    35         public static final String PLUGIN_VERSION = "1.2";
     35        public static final String PLUGIN_VERSION = "1.3";
    3636       
    3737        /**
  • applications/editors/josm/plugins/imagery-xml-bounds/src/org/openstreetmap/josm/plugins/imageryxmlbounds/XmlBoundsLayer.java

    r26776 r27015  
    8080        private static final Map<JosmAction, Boolean> actionsStates = new HashMap<JosmAction, Boolean>();
    8181       
     82        public XmlBoundsLayer(DataSet data) {
     83                this(data, OsmDataLayer.createNewName(), null);
     84        }
     85
    8286        public XmlBoundsLayer(DataSet data, String name, File associatedFile) {
    8387                super(data, name, associatedFile);
  • applications/editors/josm/plugins/imagery-xml-bounds/src/org/openstreetmap/josm/plugins/imageryxmlbounds/io/XmlBoundsImporter.java

    r26896 r27015  
    2020import java.io.File;
    2121import java.io.IOException;
    22 import java.util.Collection;
    2322import java.util.List;
    2423
     
    2625import javax.swing.SwingUtilities;
    2726
    28 import org.openstreetmap.gui.jmapviewer.Coordinate;
    2927import 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;
    3628import 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;
    4229import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    4330import org.openstreetmap.josm.io.FileImporter;
     
    4633import org.openstreetmap.josm.plugins.imageryxmlbounds.XmlBoundsConstants;
    4734import org.openstreetmap.josm.plugins.imageryxmlbounds.XmlBoundsLayer;
     35import org.openstreetmap.josm.plugins.imageryxmlbounds.data.XmlBoundsConverter;
    4836import org.xml.sax.SAXException;
    4937
     
    5644        public XmlBoundsImporter() {
    5745                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;
    16546        }
    16647       
     
    19172        }
    19273       
    193         return convertImageryEntries(reader.parse());
     74        return XmlBoundsConverter.convertImageryEntries(reader.parse());
    19475        }
    19576       
Note: See TracChangeset for help on using the changeset viewer.