Changes between Version 4 and Version 5 of Help/Preferences/RemoteControl


Ignore:
Timestamp:
2012-01-23T15:51:48+01:00 (14 years ago)
Author:
bastiK
Comment:

copy doc from the openstreetmap wiki

Legend:

Unmodified
Added
Removed
Modified
  • Help/Preferences/RemoteControl

    v4 v5  
    2424* '''Confirm all Remote Control actions manually'''
    2525
    26 == See also ==
     26== List of Commands ==
     27=== {{{load_and_zoom}}} ===
     28Instructs JOSM to download a bounding box from the API, zoom to the downloaded area and optionally select one or more objects.
     29{{{
     30GET /load_and_zoom?left=...&right=...&top=...&bottom=...&select=object[,object...]
     31}}}
     32where
     33||= '''Parameter''' =||= '''Required/Optional''' =||= '''Meaning''' =||
     34|| `left` || R || minimum longitude ||
     35|| `right` || R || maximum longitude ||
     36|| `bottom` || R || minimum latitude ||
     37|| `top` || R || maximum latitude ||
     38|| `select` || O || comma-separated list of objects that should be selected. Object specifiers are combinations of the words "way", "node", or "relation", and the numerical object id. Example: {{{select=way38473,node12399,node54646}}} ||
     39|| `addtags` || O || Optional parameter to add tags. The key and value is separated by "=" and multiple tags can be separated by a Pipe "|". Try this one for [http://localhost:8111/load_and_zoom?addtags=wikipedia:de=Wei%C3%9Fe_Gasse|maxspeed=5&select=way23071688,way23076176,way23076177,&left=13.739727546842&right=13.740890970188&top=51.049987191025&bottom=51.048466954325 example]. Works also with the zoom-command. The user must review the tags and the selection before the tags are applied to the selected objects. ||
     40
     41==== Example ====
     42
     43Start JOSM (don't forget to enable the RemoteControl feature), then click on:
     44
     45[http://127.0.0.1:8111/load_and_zoom?left=8.19&right=8.20&top=48.605&bottom=48.590&select=node413602999]
     46
     47JOSM should now load an area in the German Schwarzwald and have the specified node selected.
     48
     49=== {{{zoom}}} ===
     50Instructs JOSM to zoom to the specified area and optionally select one or more objects.
     51{{{
     52GET /zoom?left=...&right=...&top=...&bottom=...&select=object[,object...]
     53}}}
     54Accepts the same parameters as the {{{load_and_zoom}}} command and uses the same code for zoom and selection. The only difference is that no data will be loaded from the API.
     55
     56**Hint**: This command can also be used to select objects only. Just enter a small arbitrary area to the left..bottom entries and add the object list to the select= option.
     57=== {{{import}}} ===
     58Instructs JOSM to download the specified OSM file and add it to the current data set.
     59{{{
     60GET /import?url=...
     61}}}
     62=== {{{version}}} ===
     63This command returns the current protocol version of the installed JOSM RemoteControl plugin. Developers can use it to query for a running instance of JOSM and also determine whether the requested functionality is available in the client.
     64{{{
     65GET /version[?jsonp=callback]
     66}}}
     67
     68The command returns a json object containing an application identifier that is always "JOSM RemoteControl", a major number and a minor number. Compatible protocol changes result in an increase of the minor number. Incompatible changes increase the major number. So a client application knowing of protocol version 1.0 can still talk to JOSM having 1.1. But it's not guaranteed to be working with 2.0. So the client should verify the major number.
     69
     70A typical output looks like this:
     71{{{
     72#!js
     73{
     74   "protocolversion": {
     75      "major": 1,
     76      "minor": 0
     77   },
     78   "application": "JOSM RemoteControl"
     79}
     80}}}
     81For older browsers not implementing [http://en.wikipedia.org/wiki/Cross-Origin_Resource_Sharing Cross-Origin Resource Sharing (CORS)] the command provides the possibility for jsonp callback. Load the URL in a script tag and supply the name of a callback that will receive the JSON data.
     82
     83Following is some sample code that checks for CORS capabilities and uses [http://en.wikipedia.org/wiki/JSONP JSONP] as a fallback solution.
     84{{{
     85#!js
     86// in addition to the CC-BY-SA of the wiki feel free to use the following source for any purpose without restrictions (PD)
     87// credits and additions appreciated: http://wiki.openstreetmap.org/wiki/User:Stephankn
     88
     89function checkJOSM(version){
     90   alert(version.application + " uses protocol version " + version.protocolversion.major + "." + version.protocolversion.minor);
     91   // do something useful, maybe showing edit button
     92}
     93
     94var url = "http://127.0.0.1:8111/version";
     95var useFallback = false;
     96// currently FF3.5, Safari 4 and IE8 implement CORS
     97if (XMLHttpRequest) {
     98   var request = new XMLHttpRequest();
     99   if ("withCredentials" in request) {
     100      request.open('GET', url, true);
     101      request.onreadystatechange = function(){
     102         if (request.readyState != 4) {
     103            return;
     104         }
     105         if (request.status == 200) {
     106            checkJOSM(eval('(' + request.responseText + ')'));
     107         }
     108      };
     109      request.send();
     110   }
     111   else if (XDomainRequest) {
     112      var xdr = new XDomainRequest();
     113      xdr.open("get", url);
     114      xdr.onload = function(){
     115         checkJOSM(eval('(' + xdr.responseText + ')'));
     116      };
     117      xdr.send();
     118   } else {
     119      useFallback = true;
     120   }
     121}
     122else {
     123   // no XMLHttpRequest available
     124   useFallback = true;
     125}
     126
     127if (useFallback) {
     128   // Use legacy jsonp call
     129   var s = document.createElement('script');
     130   s.src = url + '?jsonp=checkJOSM';
     131   s.type = 'text/javascript';
     132   
     133   if (document.getElementsByTagName('head').length > 0) {
     134      document.getElementsByTagName('head')[0].appendChild(s);
     135   }
     136   
     137}
     138}}}
     139=== other commands ===
     140Remotecontrol allows other plugins to add additional commands. The other registers a RequestHandler class and specifies a command to be handled by this class. The command syntax has to be defined by the other plugin.
     141
     142Reverter plugin since 27091 makes use of this feature.
     143
     144== See also =
    27145[http://wiki.openstreetmap.org/wiki/JOSM/Plugins/RemoteControl Old JOSM Remote-Plugin page at OSM wiki]
    28146