| 101 | | |
| 102 | | |
| | 101 | Download missing parent elements for the selected element: |
| | 102 | |
| | 103 | |
| | 104 | {{{ |
| | 105 | #!/bin/jython |
| | 106 | ''' |
| | 107 | |
| | 108 | This code is released under the GNU General |
| | 109 | Public License v2 or later. |
| | 110 | |
| | 111 | The GPL v3 is accessible here: |
| | 112 | http://www.gnu.org/licenses/gpl.html |
| | 113 | |
| | 114 | The GPL v2 is accessible here: |
| | 115 | http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
| | 116 | |
| | 117 | It comes with no warranty whatsoever. |
| | 118 | |
| | 119 | This code illustrates how to use Jython to: |
| | 120 | * Download all referrer for an element |
| | 121 | |
| | 122 | ''' |
| | 123 | from javax.swing import JOptionPane |
| | 124 | from org.openstreetmap.josm import Main |
| | 125 | import org.openstreetmap.josm.data.osm.Node as Node |
| | 126 | import org.openstreetmap.josm.data.osm.Way as Way |
| | 127 | import org.openstreetmap.josm.data.osm.Relation as Relation |
| | 128 | import org.openstreetmap.josm.data.osm.TagCollection as TagCollection |
| | 129 | import org.openstreetmap.josm.data.osm.DataSet as DataSet |
| | 130 | import org.openstreetmap.josm.data.osm.RelationMember as RelationMember |
| | 131 | import org.openstreetmap.josm.actions.DownloadReferrersAction as DownloadReferrersAction |
| | 132 | #import org.openstreetmap.josm.actions.downloadtasks.DownloadReferrersTask as DownloadReferrersTask; |
| | 133 | |
| | 134 | def getMapView(): |
| | 135 | if Main.main and Main.main.map: |
| | 136 | return Main.main.map.mapView |
| | 137 | else: |
| | 138 | return None |
| | 139 | |
| | 140 | mv = getMapView() |
| | 141 | if mv and mv.editLayer and mv.editLayer.data: |
| | 142 | selectedElements = mv.editLayer.data.getSelected() |
| | 143 | |
| | 144 | if not(selectedElements): |
| | 145 | JOptionPane.showMessageDialog(Main.parent, "Please select an element") |
| | 146 | else: |
| | 147 | DownloadReferrersAction.downloadReferrers(mv.editLayer, selectedElements) |
| | 148 | }}} |
| | 149 | |
| | 150 | |
| | 151 | Download missing relation members: |
| | 152 | |
| | 153 | |
| | 154 | {{{ |
| | 155 | #!/bin/jython |
| | 156 | ''' |
| | 157 | |
| | 158 | This code is released under the GNU General |
| | 159 | Public License v2 or later. |
| | 160 | |
| | 161 | The GPL v3 is accessible here: |
| | 162 | http://www.gnu.org/licenses/gpl.html |
| | 163 | |
| | 164 | The GPL v2 is accessible here: |
| | 165 | http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
| | 166 | |
| | 167 | It comes with no warranty whatsoever. |
| | 168 | |
| | 169 | This code illustrates how to use Jython to: |
| | 170 | * Download all missing members of a relation |
| | 171 | |
| | 172 | ''' |
| | 173 | from javax.swing import JOptionPane |
| | 174 | from org.openstreetmap.josm import Main |
| | 175 | import org.openstreetmap.josm.data.osm.Node as Node |
| | 176 | import org.openstreetmap.josm.data.osm.Way as Way |
| | 177 | import org.openstreetmap.josm.data.osm.Relation as Relation |
| | 178 | import org.openstreetmap.josm.data.osm.TagCollection as TagCollection |
| | 179 | import org.openstreetmap.josm.data.osm.DataSet as DataSet |
| | 180 | import org.openstreetmap.josm.data.osm.RelationMember as RelationMember |
| | 181 | import org.openstreetmap.josm.gui.dialogs.relation.DownloadRelationMemberTask as DownloadRelationMemberTask |
| | 182 | |
| | 183 | def getMapView(): |
| | 184 | if Main.main and Main.main.map: |
| | 185 | return Main.main.map.mapView |
| | 186 | else: |
| | 187 | return None |
| | 188 | |
| | 189 | mv = getMapView() |
| | 190 | if mv and mv.editLayer and mv.editLayer.data: |
| | 191 | selectedRelations = mv.editLayer.data.getSelectedRelations() |
| | 192 | |
| | 193 | if not(selectedRelations): |
| | 194 | JOptionPane.showMessageDialog(Main.parent, "Please select a node") |
| | 195 | else: |
| | 196 | for relation in selectedRelations: |
| | 197 | if relation.hasIncompleteMembers(): |
| | 198 | #print dir(relation) |
| | 199 | print dir(DownloadRelationMemberTask) |
| | 200 | DownloadRelationMemberTask.run(DownloadRelationMemberTask(relation, relation.getIncompleteMembers(), mv.editLayer )) |
| | 201 | }}} |