Changeset 11967 in josm


Ignore:
Timestamp:
2017-04-21T23:10:21+02:00 (7 years ago)
Author:
stoecker
Message:

more XML output in Sync script

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/scripts/SyncEditorLayerIndex.groovy

    r11965 r11967  
    1717 * Add option "-h" to show the available command line flags.
    1818 */
     19import java.text.DecimalFormat
    1920import javax.json.Json
    2021import javax.json.JsonArray
     
    4849     */
    4950    static main(def args) {
     51        Locale.setDefault(Locale.ROOT);
    5052        parse_command_line_arguments(args)
    5153        def script = new SyncEditorLayerIndex()
     
    196198    }
    197199
     200    String maininfo(def entry, String offset) {
     201        String res = offset + "<type>${getType(entry)}</type>\n"
     202        res += offset + "<url><![CDATA[${getUrl(entry)}]]></url>\n"
     203        if(getType(entry) == "tms") {
     204            if(getMinZoom(entry) != null)
     205                res += offset + "<min-zoom>${getMinZoom(entry)}</min-zoom>\n"
     206            if(getMaxZoom(entry) != null)
     207                res += offset + "<max-zoom>${getMaxZoom(entry)}</max-zoom>\n"
     208        }
     209        return res
     210    }
     211
     212   
    198213    void printentries(def entries, def stream) {
     214        DecimalFormat df = new DecimalFormat("#.#######")
     215        df.setRoundingMode(java.math.RoundingMode.CEILING)
    199216        stream.write "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
    200217        stream.write "<imagery xmlns=\"http://josm.openstreetmap.de/maps-1.0\">\n"
     
    204221            stream.write "        <name>${getName(e)}</name>\n"
    205222            stream.write "        <id>${getId(e)}</id>\n"
     223            if(getDate(e) != "")
     224                stream.write "        <date>${getDate(e)}</date>\n"
     225            stream.write maininfo(e, "        ")
     226            for (def m : getMirrors(e)) {
     227                    stream.write "        <mirror>\n"+maininfo(m, "            ")+"        </mirror>\n"
     228            }
    206229            def minlat = 1000
    207230            def minlon = 1000
     
    223246                        shapes += sep + "    "
    224247                    }
    225                     shapes += "<point lat='${String.format(Locale.ROOT, "%.7f",lat)}' lon='${String.format(Locale.ROOT, "%.7f",lon)}'/>"
     248                    shapes += "<point lat='${df.format(lat)}' lon='${df.format(lon)}'/>"
    226249                }
    227250                shapes += sep + "</shape>\n"
    228251            }
    229252            if(shapes) {
    230                 stream.write "        <bounds min-lat='${minlat}' min-lon='${minlon}' max-lat='${maxlat}' max-lon='${maxlon}'>\n"
     253                stream.write "        <bounds min-lat='${df.format(minlat)}' min-lon='${df.format(minlon)}' max-lat='${df.format(maxlat)}' max-lon='${df.format(maxlon)}'>\n"
    231254                stream.write shapes + "        </bounds>\n"
    232                 stream.write "    </entry>\n"
    233             }
     255            }
     256            stream.write "    </entry>\n"
    234257        }
    235258        stream.write "</imagery>\n"
     
    580603        return e.get("properties").getString("name")
    581604    }
     605    static List<Object> getMirrors(Object e) {
     606        if (e instanceof ImageryInfo) return e.getMirrors()
     607        return []
     608    }
    582609    static List<Shape> getShapes(Object e) {
    583610        if (e instanceof ImageryInfo) {
Note: See TracChangeset for help on using the changeset viewer.