Changeset 13536 in josm


Ignore:
Timestamp:
2018-03-17T17:01:12+01:00 (6 years ago)
Author:
stoecker
Message:

add possibility to change map ids (see #14655), add overlay flag for imagery

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/data/maps.xsd

    r13284 r13536  
    2020        <!-- exclude white space characters and characters that are not valid for file names in Windows -->
    2121        <xs:restriction base="xs:string">
    22             <xs:pattern value='[^\s/\\:*?"&lt;>|]+' />
     22            <xs:pattern value='[^\s/\\:*?"&lt;>|,;]+' />
    2323        </xs:restriction>
    2424    </xs:simpleType>
     25
     26    <xs:complexType name="oldid">
     27        <xs:simpleContent>
     28            <xs:extension base="tns:id">
     29                <!-- date of the retirement of this ID -->
     30                <xs:attribute name="date" type="xs:date" use="required" />
     31            </xs:extension>
     32        </xs:simpleContent>
     33    </xs:complexType>
    2534
    2635    <xs:simpleType name="type">
     
    623632                            <!-- A unique id for the imagery source -->
    624633                            <xs:element name="id" minOccurs="0" maxOccurs="1" type="tns:id" />
     634                            <!-- Historic id for the imagery source -->
     635                            <xs:element name="oldid" minOccurs="0" maxOccurs="unbounded" type="tns:oldid" />
    625636                            <!-- The type. Can be tms, wms and html. In addition, there are the special types bing and scanex
    626637                                with hardcoded behaviour. -->
     
    666677                                    <xs:all>
    667678                                        <xs:element name="type" minOccurs="1" maxOccurs="1" type="tns:type" />
     679                                        <xs:element name="id" minOccurs="0" maxOccurs="1" type="tns:id" />
    668680                                        <xs:element name="url" minOccurs="1" maxOccurs="1" type="xs:string" />
    669681                                        <xs:element name="projections" minOccurs="0" maxOccurs="1" type="tns:projections" />
     
    707719                    <xs:attribute name="last-check" type="xs:date" use="optional" />
    708720                    <xs:attribute name="eli-best" type="xs:boolean" use="optional" />
     721                    <xs:attribute name="overlay" type="xs:boolean" use="optional" />
    709722                </xs:complexType>
    710723            </xs:element>
  • trunk/scripts/SyncEditorLayerIndex.groovy

    r13533 r13536  
    272272        stream.write "<imagery xmlns=\"http://josm.openstreetmap.de/maps-1.0\">\n"
    273273        for (def e : entries) {
    274             def best = "eli-best".equals(getQuality(e))
    275             stream.write "    <entry"+(best ? " eli-best=\"true\"" : "" )+">\n"
     274            stream.write("    <entry"
     275                + ("eli-best".equals(getQuality(e)) ? " eli-best=\"true\"" : "" )
     276                + (getOverlay(e) ? " overlay=\"true\"" : "" )
     277                + ">\n")
    276278            stream.write "        <name>${cdata(getName(e), true)}</name>\n"
    277279            stream.write "        <id>${getId(e)}</id>\n"
     
    608610                }
    609611            }
     612            et = getOverlay(e)
     613            jt = getOverlay(j)
     614            if (!et.equals(jt)) {
     615                if (!jt) {
     616                    myprintln "! Missing JOSM overlay flag: ${getDescription(j)}"
     617                } else if (!options.nomissingeli) {
     618                    myprintln "+ Missing ELI overlay flag: ${getDescription(j)}"
     619                }
     620            }
    610621        }
    611622        myprintln "*** Mismatching shapes: ***"
     
    936947            && e.get("properties").getBoolean("best")) ? "eli-best" : null
    937948    }
     949    static Boolean getOverlay(Object e) {
     950        if (e instanceof ImageryInfo) return e.isOverlay()
     951        return (e.get("properties").containsKey("overlay")
     952            && e.get("properties").getBoolean("overlay"))
     953    }
    938954    static String getIcon(Object e) {
    939955        if (e instanceof ImageryInfo) return e.getIcon()
  • trunk/src/org/openstreetmap/josm/data/imagery/ImageryInfo.java

    r13516 r13536  
    2727import org.openstreetmap.gui.jmapviewer.tilesources.TileSourceInfo;
    2828import org.openstreetmap.josm.data.Bounds;
     29import org.openstreetmap.josm.data.StructUtils;
    2930import org.openstreetmap.josm.data.StructUtils.StructEntry;
    3031import org.openstreetmap.josm.io.Capabilities;
    3132import org.openstreetmap.josm.io.OsmApi;
    3233import org.openstreetmap.josm.spi.preferences.Config;
     34import org.openstreetmap.josm.spi.preferences.IPreferences;
    3335import org.openstreetmap.josm.tools.CheckParameterUtil;
    3436import org.openstreetmap.josm.tools.ImageProvider;
     
    199201      */
    200202    private boolean bestMarked;
     203    /**
     204      * marked as overlay
     205      * @since 13536
     206      */
     207    private boolean overlay;
     208    /**
     209      * list of old IDs, only for loading, not handled anywhere else
     210      * @since 13536
     211      */
     212    private Collection<String> oldIds;
    201213    /** mirrors of different type for this entry */
    202214    private List<ImageryInfo> mirrors;
     
    245257        @StructEntry boolean bestMarked;
    246258        @StructEntry boolean modTileFeatures;
     259        @StructEntry boolean overlay;
    247260        // TODO: disabled until change of layers is implemented
    248261        // @StructEntry String default_layers;
     
    271284            date = i.date;
    272285            bestMarked = i.bestMarked;
     286            overlay = i.overlay;
    273287            logo_image = i.attributionImage;
    274288            logo_url = i.attributionImageURL;
     
    439453        date = e.date;
    440454        bestMarked = e.bestMarked;
     455        overlay = e.overlay;
    441456        termsOfUseText = e.terms_of_use_text;
    442457        termsOfUseURL = e.terms_of_use_url;
     
    494509        this.date = i.date;
    495510        this.bestMarked = i.bestMarked;
     511        this.overlay = i.overlay;
    496512        // do not copy field {@code mirrors}
    497513        this.icon = i.icon;
     
    526542                Objects.equals(this.modTileFeatures, other.modTileFeatures) &&
    527543                Objects.equals(this.bestMarked, other.bestMarked) &&
     544                Objects.equals(this.overlay, other.overlay) &&
    528545                Objects.equals(this.isGeoreferenceValid, other.isGeoreferenceValid) &&
    529546                Objects.equals(this.cookies, other.cookies) &&
     
    901918
    902919    /**
     920     * Return the sorted list of activated Imagery IDs
     921     * @since 13536
     922     */
     923    static public Collection<String> getActiveIds() {
     924        ArrayList<String> ids = new ArrayList<String>();
     925        IPreferences pref = Config.getPref();
     926        if (pref != null) {
     927            List<ImageryPreferenceEntry> entries = StructUtils.getListOfStructs(
     928                pref, "imagery.entries", null, ImageryPreferenceEntry.class);
     929            if (entries != null) {
     930                for (ImageryPreferenceEntry prefEntry : entries) {
     931                    if(prefEntry.id != null && prefEntry.id.length() != 0)
     932                        ids.add(prefEntry.id);
     933                }
     934                Collections.sort(ids);
     935            }
     936        }
     937        return ids;
     938    }
     939   
     940    /**
    903941     * Returns a tool tip text for display.
    904942     * @return The text
     
    917955            html = true;
    918956        }
     957        if (overlay) {
     958            res.append("<br>").append(tr("This imagery is an overlay."));
     959            html = true;
     960        }
    919961        String desc = getDescription();
    920962        if (desc != null && !desc.isEmpty()) {
     
    12151257
    12161258    /**
     1259     * Returns the overlay indication.
     1260     * @return <code>true</code> if it is and overlay.
     1261     * @since 13536
     1262     */
     1263    public boolean isOverlay() {
     1264        return overlay;
     1265    }
     1266
     1267    /**
    12171268     * Sets an indicator that in other editors it is marked as best imagery
    12181269     * @param bestMarked <code>true</code> if it is marked as best in other editors.
     
    12211272    public void setBestMarked(boolean bestMarked) {
    12221273        this.bestMarked = bestMarked;
     1274    }
     1275
     1276    /**
     1277     * Sets overlay indication
     1278     * @param overlay <code>true</code> if it is an overlay.
     1279     * @since 13536
     1280     */
     1281    public void setOverlay(boolean overlay) {
     1282        this.overlay = overlay;
     1283    }
     1284
     1285    /**
     1286     * Adds an old Id.
     1287     *
     1288     * @param id the Id to be added
     1289     * @since 13536
     1290     */
     1291    public void addOldId(String id) {
     1292       if (oldIds == null) {
     1293           oldIds = new ArrayList<>();
     1294       }
     1295       oldIds.add(id);
     1296    }
     1297
     1298    /**
     1299     * Get old Ids.
     1300     *
     1301     * @return collection of ids
     1302     * @since 13536
     1303     */
     1304    public Collection<String> getOldIds() {
     1305        return oldIds;
    12231306    }
    12241307
  • trunk/src/org/openstreetmap/josm/data/imagery/ImageryLayerInfo.java

    r12851 r13536  
    5050
    5151    private static final String[] DEFAULT_LAYER_SITES = {
    52         Main.getJOSMWebsite()+"/maps"
     52        Main.getJOSMWebsite()+"/maps%<?ids=>"
    5353    };
    5454
     
    224224                }
    225225                idMap.put(i.getId(), i);
     226                Collection<String> old = i.getOldIds();
     227                if(old != null) {
     228                    for (String id : old) {
     229                        if (idMap.containsKey(id)) {
     230                            Logging.error("Old Id ''{0}'' is not unique - used by ''{1}'' and ''{2}''!",
     231                                    i.getId(), i.getName(), idMap.get(i.getId()).getName());
     232                        } else {
     233                            idMap.put(id, i);
     234                        }
     235                    }
     236                }
    226237            }
    227238        }
  • trunk/src/org/openstreetmap/josm/io/CachedFile.java

    r13204 r13536  
    7575    protected File cacheFile;
    7676    protected boolean initialized;
     77    protected String parameter;
    7778
    7879    public static final long DEFAULT_MAXTIME = -1L;
     
    173174    }
    174175
     176    /**
     177     * Sets additional URL parameter (used e.g. for maps)
     178     * @param parameter the URL parameter
     179     * @since 13536
     180     */
     181    public void setParam(String parameter) {
     182        this.parameter = parameter;
     183    }
     184
    175185    public String getName() {
     186        if(parameter != null)
     187            return name.replaceAll("%<(.*)>", "");
    176188        return name;
    177189    }
     
    284296        }
    285297        if (cacheFile == null)
    286             throw new IOException("Unable to get cache file for "+name);
     298            throw new IOException("Unable to get cache file for "+getName());
    287299        return cacheFile;
    288300    }
     
    298310     * @param extension  the extension of the file we're looking for
    299311     * @param namepart the name part
    300      * @return The zip entry path of the matching file. Null if this cached file
     312     * @return The zip entry path of the matching file. <code>null</code> if this cached file
    301313     * doesn't represent a zip file or if there was no matching
    302314     * file in the ZIP file.
     
    312324     * @param extension  the extension of the file we're looking for
    313325     * @param namepart the name part
    314      * @return InputStream to the matching file. Null if this cached file
     326     * @return InputStream to the matching file. <code>null</code> if this cached file
    315327     * doesn't represent a zip file or if there was no matching
    316328     * file in the ZIP file.
     
    380392            url = new URL(name);
    381393            if (!"file".equals(url.getProtocol())) {
    382                 String prefKey = getPrefKey(url, destDir);
     394                String prefKey = getPrefKey(url, destDir, null);
    383395                List<String> localPath = new ArrayList<>(Config.getPref().getList(prefKey));
    384396                if (localPath.size() == 2) {
     
    403415     * @return Preference key
    404416     */
    405     private static String getPrefKey(URL url, String destDir) {
     417    private static String getPrefKey(URL url, String destDir, String parameter) {
    406418        StringBuilder prefKey = new StringBuilder("mirror.");
    407419        if (destDir != null) {
    408420            prefKey.append(destDir).append('.');
    409421        }
    410         prefKey.append(url.toString());
     422        if (parameter != null) {
     423            prefKey.append(url.toString().replaceAll("%<(.*)>", ""));
     424        } else {
     425            prefKey.append(url.toString());
     426        }
    411427        return prefKey.toString().replaceAll("=", "_");
    412428    }
    413429
    414430    private File checkLocal(URL url) throws IOException {
    415         String prefKey = getPrefKey(url, destDir);
     431        String prefKey = getPrefKey(url, destDir, parameter);
    416432        String urlStr = url.toExternalForm();
     433        if (parameter != null)
     434            urlStr = urlStr.replaceAll("%<(.*)>", "");
    417435        long age = 0L;
    418436        long maxAgeMillis = maxAge;
     
    460478        }
    461479
     480        if(parameter != null) {
     481            String u = url.toExternalForm();
     482            String uc;
     483            if("".equals(parameter)) {
     484                uc = u.replaceAll("%<(.*)>", "");
     485            } else {
     486                uc = u.replaceAll("%<(.*)>", "$1"+parameter);
     487            }
     488            if(!uc.equals(u))
     489                url = new URL(uc);
     490        }
     491
    462492        String a = urlStr.replaceAll("[^A-Za-z0-9_.-]", "_");
    463493        String localPath = "mirror_" + a;
  • trunk/src/org/openstreetmap/josm/io/imagery/ImageryReader.java

    r13272 r13536  
    8585        try {
    8686            cachedFile = new CachedFile(source);
     87            cachedFile.setParam(Utils.join(",", ImageryInfo.getActiveIds()));
    8788            cachedFile.setFastFail(fastFail);
    8889            try (BufferedReader in = cachedFile
     
    168169                        entry.setBestMarked(true);
    169170                    }
     171                    String overlay = atts.getValue("overlay");
     172                    if (TRUE.equals(overlay)) {
     173                        entry.setOverlay(true);
     174                    }
    170175                }
    171176                break;
     
    174179                        "type",
    175180                        "url",
     181                        "id",
    176182                        MIN_ZOOM,
    177183                        MAX_ZOOM,
     
    189195                        "name",
    190196                        "id",
     197                        "oldid",
    191198                        "type",
    192199                        "description",
     
    328335                        }
    329336                        break;
     337                    case "id":
     338                        mirrorEntry.setId(accumulator.toString());
     339                        break;
    330340                    case "url":
    331341                        mirrorEntry.setUrl(accumulator.toString());
     
    379389                case "id":
    380390                    entry.setId(accumulator.toString());
     391                    break;
     392                case "oldid":
     393                    entry.addOldId(accumulator.toString());
    381394                    break;
    382395                case "type":
Note: See TracChangeset for help on using the changeset viewer.