Changes between Version 11 and Version 12 of Help/Plugin/Scripting/Python


Ignore:
Timestamp:
2017-10-09T17:11:44+02:00 (8 days ago)
Author:
Polyglot
Comment:

fixed 2 scripts now that mapView isn't needed anymore

Legend:

Unmodified
Added
Removed
Modified
  • Help/Plugin/Scripting/Python

    v11 v12  
    120120
    121121This code illustrates how to use Jython to:
    122 * Download all referrer for an element
     122* Download all referrers for an element
    123123
    124124'''
    125125from javax.swing import JOptionPane
    126126from org.openstreetmap.josm import Main
    127 import org.openstreetmap.josm.data.osm.Node as Node
    128 import org.openstreetmap.josm.data.osm.Way as Way
    129 import org.openstreetmap.josm.data.osm.Relation as Relation
    130 import org.openstreetmap.josm.data.osm.TagCollection as TagCollection
    131 import org.openstreetmap.josm.data.osm.DataSet as DataSet
    132 import org.openstreetmap.josm.data.osm.RelationMember as RelationMember
    133127import org.openstreetmap.josm.actions.DownloadReferrersAction as DownloadReferrersAction
    134 #import org.openstreetmap.josm.actions.downloadtasks.DownloadReferrersTask as DownloadReferrersTask;
    135 
    136 def getMapView():
    137     if Main.main and Main.main.map:
    138         return Main.main.map.mapView
    139     else:
    140         return None
    141 
    142 mv = getMapView()
    143 if mv and mv.editLayer and mv.editLayer.data:
    144     selectedElements = mv.editLayer.data.getSelected()
     128
     129editLayer = Main.getLayerManager().getEditLayer()
     130if editLayer and editLayer.data:
     131    selectedElements = editLayer.data.getSelected()
    145132   
    146133    if not(selectedElements):
    147134        JOptionPane.showMessageDialog(Main.parent, "Please select an element")
    148135    else:
    149         DownloadReferrersAction.downloadReferrers(mv.editLayer, selectedElements)
     136        DownloadReferrersAction.downloadReferrers(editLayer, selectedElements)
    150137}}}
    151138
    152139
    153140Download missing relation members:
    154 
    155141
    156142{{{
     
    183169import org.openstreetmap.josm.gui.dialogs.relation.DownloadRelationMemberTask as DownloadRelationMemberTask
    184170
    185 def getMapView():
    186     if Main.main and Main.main.map:
    187         return Main.main.map.mapView
    188     else:
    189         return None
    190 
    191 mv = getMapView()
    192 if mv and mv.editLayer and mv.editLayer.data:
    193     selectedRelations = mv.editLayer.data.getSelectedRelations()
     171editLayer = Main.getLayerManager().getEditLayer()
     172if editLayer:
     173    selectedRelations = editLayer.data.getSelectedRelations()
    194174   
    195175    if not(selectedRelations):
    196         JOptionPane.showMessageDialog(Main.parent, "Please select a node")
     176        JOptionPane.showMessageDialog(Main.parent, "Please select a relation")
    197177    else:
    198178        for relation in selectedRelations:
     
    200180                #print dir(relation)
    201181                print dir(DownloadRelationMemberTask)
    202                 DownloadRelationMemberTask.run(DownloadRelationMemberTask(relation, relation.getIncompleteMembers(), mv.editLayer ))
    203 
     182                DownloadRelationMemberTask.run(DownloadRelationMemberTask(relation, relation.getIncompleteMembers(), editLayer ))
    204183}}}
    205184