Ignore:
Timestamp:
2018-04-24T07:48:05+02:00 (6 years ago)
Author:
mkyral
Message:

PointInfo: Add Spanish Cadastre Web Services module.

Patch by Javier Sánchez Portero.

Location:
applications/editors/josm/plugins/pointInfo/src/org/openstreetmap/josm/plugins/pointinfo
Files:
9 added
4 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/pointInfo/src/org/openstreetmap/josm/plugins/pointinfo/PointInfoAction.java

    r33549 r34168  
    2525import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    2626import org.openstreetmap.josm.gui.util.GuiHelper;
    27 import org.openstreetmap.josm.plugins.pointinfo.ruian.RuianModule;
     27import org.openstreetmap.josm.plugins.pointinfo.AbstractPointInfoModule;
    2828import org.openstreetmap.josm.tools.ImageProvider;
    2929import org.openstreetmap.josm.tools.Logging;
     
    3737
    3838    protected boolean cancel;
    39     protected RuianModule mRuian = new RuianModule();
     39    protected AbstractPointInfoModule module;
    4040
    4141    private String htmlText = "";
     
    7676
    7777        try {
     78            module = PointInfoPlugin.getModule(pos);
    7879            PleaseWaitRunnable infoTask = new PleaseWaitRunnable(tr("Connecting server")) {
    7980                @Override
     
    9596                        msgLabel.addHyperlinkListener(hle -> {
    9697                            if (HyperlinkEvent.EventType.ACTIVATED.equals(hle.getEventType())) {
     98                                Logging.info(hle.getURL().toString());
    9799                                if (hle.getURL() == null || hle.getURL().toString().isEmpty()) {
    98100                                    return;
    99101                                }
    100                                 System.out.println("URL: "+ hle.getURL());
    101102                                if (!hle.getURL().toString().startsWith("http")) {
    102                                     mRuian.performAction(hle.getURL().toString());
     103                                    module.performAction(hle.getURL().toString());
    103104                                } else {
    104105                                    String ret = OpenBrowser.displayUrl(hle.getURL().toString());
     
    132133        progressMonitor.beginTask(null, 3);
    133134        try {
    134             mRuian.prepareData(pos);
    135             htmlText = mRuian.getHtml();
     135            module.prepareData(pos);
     136            htmlText = module.getHtml();
    136137            coordinatesText = PointInfoUtils.formatCoordinates(pos.lat(), pos.lon());
    137138
  • applications/editors/josm/plugins/pointInfo/src/org/openstreetmap/josm/plugins/pointinfo/PointInfoPlugin.java

    r33549 r34168  
    22package org.openstreetmap.josm.plugins.pointinfo;
    33
     4import java.io.IOException;
     5import java.util.ArrayList;
     6import java.util.HashMap;
     7import java.util.Iterator;
     8import java.util.List;
     9
     10import org.openstreetmap.josm.Main;
     11import org.openstreetmap.josm.data.coor.LatLon;
     12import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
    413import org.openstreetmap.josm.gui.MainApplication;
    514import org.openstreetmap.josm.gui.MainMenu;
    615import org.openstreetmap.josm.plugins.Plugin;
    716import org.openstreetmap.josm.plugins.PluginInformation;
     17import org.openstreetmap.josm.plugins.pointinfo.ruian.RuianModule;
     18import org.openstreetmap.josm.plugins.pointinfo.catastro.CatastroModule;
    819
    920/**
     
    1223 */
    1324public class PointInfoPlugin extends Plugin {
     25
     26    private static final HashMap<String, AbstractPointInfoModule> modules = new HashMap<>();
     27    static {
     28        registerModule(new RuianModule());
     29        registerModule(new CatastroModule());
     30    }
    1431
    1532    /**
     
    2138        MainMenu.add(MainApplication.getMenu().moreToolsMenu, new PointInfoAction());
    2239    }
     40
     41    @Override
     42    public PreferenceSetting getPreferenceSetting() {
     43        return new PointInfoPreference();
     44    }
     45
     46    /**
     47     * Register a module as available to select in the preferences.
     48     * @param module PointInfo module
     49     */
     50    public static void registerModule(AbstractPointInfoModule module) {
     51        modules.put(module.getName(), module);
     52    }
     53
     54    /**
     55     * Returns a list of available modules names
     56     * @return modsList
     57     */
     58    public static List<String> getModules() {
     59        return new ArrayList<>(modules.keySet());
     60    }
     61
     62    /**
     63     * Returns a valid module for this point. If auto mode is selected, returns
     64     * the first valid module for the area in the given position
     65     the currently selected module
     66     * @param pos position LatLon
     67     * @return module
     68     * @throws IOException if any IO error occurs.
     69    */
     70    public static AbstractPointInfoModule getModule(LatLon pos) throws IOException {
     71        AbstractPointInfoModule module;
     72        module = null;
     73        if (Main.pref.getBoolean("plugin.pointinfo.automode", true)) {
     74            ReverseRecord r = ReverseFinder.queryNominatim(pos);
     75            Iterator i = modules.values().iterator();
     76            while (module == null && i.hasNext()) {
     77                AbstractPointInfoModule m = (AbstractPointInfoModule) i.next();
     78                if (r.matchAnyArea(m.getArea())) {
     79                    module = m;
     80                }
     81            }
     82        } else {
     83            module = modules.get(Main.pref.get("plugin.pointinfo.module", "RUIAN"));
     84        }
     85        if (module == null) {
     86            module = modules.get("RUIAN");
     87        }
     88        return module;
     89    }
    2390}
  • applications/editors/josm/plugins/pointInfo/src/org/openstreetmap/josm/plugins/pointinfo/PointInfoUtils.java

    r32848 r34168  
    3838    /**
    3939     * Return text representation of coordinates.
    40      # @param  lat Lat coordinate
    41      # @param  lon Lon coordinate
     40     * @param lat the lat part of coordinates
     41     * @param lon the lon part of coordinates
    4242     * @return String coordinatesText
    4343     */
  • applications/editors/josm/plugins/pointInfo/src/org/openstreetmap/josm/plugins/pointinfo/ruian/RuianModule.java

    r33549 r34168  
    88import org.openstreetmap.josm.tools.Logging;
    99
     10import org.openstreetmap.josm.plugins.pointinfo.AbstractPointInfoModule;
     11
    1012/**
    1113 * A module for the Czech RUIAN database
    1214 * @author Marián Kyral
    1315 */
    14 public class RuianModule {
     16public class RuianModule extends AbstractPointInfoModule {
    1517
    16     private String URL = "http://josm.poloha.net/pointInfo/v4/index.php";
     18    private static final String moduleName = "RUIAN";
     19    private static final String areaName = "cz";
     20    private static final String URL = "http://josm.poloha.net/pointInfo/v4/index.php";
    1721
    1822    private RuianRecord m_record = new RuianRecord();
     
    2226    }
    2327
    24     /**
    25      * Return Html text representation
    26      * @return String htmlText
    27      */
     28    @Override
    2829    public String getHtml() {
    2930        return m_record.getHtml();
    3031    }
    3132
    32     /**
    33      * Perform given action
    34      *  e.g.: copy tags to clipboard
    35      * @param act Action to be performed
    36      */
     33    @Override
    3734    public void performAction(String act) {
    3835        m_record.performAction(act);
     
    4340     * @param pos Position on the map
    4441     */
     42    @Override
    4543    public void prepareData(LatLon pos) {
    4644        try {
     
    5149        }
    5250    }
     51
     52    @Override
     53    public String getName() {
     54        return moduleName;   
     55    }
     56
     57    @Override
     58    public String getArea() {
     59        return areaName;
     60    }
    5361}
Note: See TracChangeset for help on using the changeset viewer.