User:Bjohas/OSMgadget

= A Mediawiki gadget to pull in OSM data. =

This mediawiki gadget adds an unattractive box below the sitenotice, that may or may not display related information from httpː//www.openstreetmap.org. E.g. for en:Nuraghe_Santu_Antine it looks like this (collapsed):



Fully expanded, it looks like this:

Just with map:

See more examples in the image gallery here: http://bjohas.de/wiki/Maps/Linking_wikipedia_to_OSM/image_gallery.

= How it works=

The gadget facilitates making new links between wikipedia and OpenStreeMap by displaying the result of an OSM search for wikidata and title. If nothing is found, you can use a direct link to OSM to try and spot the object manually.

It works in several steps:
 * On load, the script fetches the coords/WD from the wiki page, and offers an OSM/JOSM link for the bounding box.
 * It then asynchronously does an overpass search based on wiki title (search OSM for "wikipedia=") and WD (search OSM for "wikidata="). If a match is found, the OSM/JOSM links are replaced by edit/load links for the found OSM object. If several matches are found, additional links to those objects are appended. This only finds existing objects (obviously), i.e. OSM objects that are tagged with wp/wd tags.
 * The Gadget now also queries https://osm.wikipedia.link, which can provide suggestions for matches where the link doesn't already exist. It runs a more complex query, able to discover potential matches for as yet untagged objects
 * The gadget can display an iframe with an overpass-turbo map, http://overpass-turbo.de

= How to use it = The UI is not great, and can be a bit cryptic. Here's some guidance: The script adds link texts that explain what the links do - hover over a link to see them.
 * Top line:
 * Brief information, such as the wikidata item, and links to OSM/iD/JOSM, overpass map. These links are amended as data from overpass is loaded.
 * Show results / show map buttons: These can be used to show/hide the following elements. The state is remembers.
 * Results box: Results from overpass and from osm.wikidata.link.
 * Overpass: Shows results from overpass
 * Matcher: Shows results from osm.wikidata.link. Results from osm.wikidata.link are only fetched once the overpass query is complete. Where items are found that were already returned by the ovepass query, the results are added to that list.
 * Map
 * Map from overpass. Only fetched once the overpass query has returned results.

Viewing and adding data: * and +
You'll see "OSM", "iD" and "JOSM", which refer to the OSM site, the iD editor, and the JOSM editor. If certain options are not possible, the script crosses these out, e.g. JOSM.
 * Where you see OSM / iD, they view the area.
 * Where you see OSM* / iD* / JOSM*, an OSM object has been found, which can be viewed on OSM, edited with iD, or loaded into JOSM (via remote control)
 * Where you see a "+" something can be added to OSM.
 * e.g. +wd (usually near a JOSM*), means that the wd tag can be added to the existing JOSM object;
 * or JOSM+node+tags, means a new object is added to OSM. (Wikidata is CC0, so we can copy wikidata to openstreetmap.)

Coordinate mismatches
The script also shows various distances (as d=...m). These are distances between different coordinates (all referring to the same object). Note that there can also be offsets between wikipedia and OSM coordinates. That's normal, as they cannot be copied from one service to the other (that's a bit unfortunate, but it's due to licensing, and has it's own reasons). However, if you see a large mismatch between objects that clearly are the same on wikipedia and OSM, then something is wrong.
 * The distances displayed near overpass results are the difference between the WP coordinate and the OSM coordinate. (only for nodes!)
 * The distances displayed near osm.wikidata.link results are the difference between the WD coordinate and the OSM coordinate. (for all types of OSM objects)

Wthin WP/WD, the coordinates unfortunately can vary as follows:
 * Within the wikipedia page: Coordinates are added to the page in different ways, and the script does some basic consistency checkes. A pink box will show errors.
 * Between wikidata and wikipedia (in the results retrieved by osm.wikidata.link). Unfortunately it seems that wikidata coordinates are often not checked against wikipedia coordinates (also on different language sites). The coordinates can be mismatched. This is shown near "Wikidata_coords=". Again, a pink box is added for large differences.

Options
The Gadget now has an options box, that allows you to try out some experimental features.

= Report an issue =

Report an issue hereː User_talk:Bjohas/OSMgadget or here https://github.com/bjohas/OSM-Wikipedia-Monkey/issues

Script tested in
 * Chrome (OS X, Android, iOS)

Code

 * Current code: User:Bjohas/common.js
 * Also: https://github.com/bjohas/OSM-Wikipedia-Monkey/blob/master/Gadget%20Wikipedia%20to%20OSM.js
 * Ideas for improvement
 * First version avaialble here: https://github.com/bjohas/OSM-Wikipedia-Monkey (see ).

Installation
To install this script, go to the wikipedia on which you want to run it, and then go to "USERPAGE/common.js", e.g. this is my USERPAGE/common.js on wikipedia: https://en.wikipedia.org/wiki/User:Bjohas/common.js. You page will be https://en.wikipedia.org/wiki/User:SOMEBODY/common.js.

Copy this text to the page: /* Code available at https://www.mediawiki.org/wiki/User:Bjohas/common.js Documentation available at https://www.mediawiki.org/wiki/User:Bjohas/OSMgadget mw.loader.load("//www.mediawiki.org/w/index.php?title=User:Bjohas/common.js&action=raw&ctype=text/javascript"); (Strictly speaking you don't need the comment, but it helps others find the script.) You'll need to do this on each wikipedia where you want to use it.

Important
The gadget now puts a switch into the left-hand tools menu, that allows you to enable/disable the gadget.

Related

 * https://osm.wikidata.link/ - a tool for creating links (used by the gadget)
 * en:Module:OSM (by en:User:Polyglot) - a module to perform searches and insert search results into wikipedia pages. The main difference is that the OSMgadget is installed by yourself, and once installed it's active on all pages that you visit. It's thus good for running a 'campaign' to create a set of new links between wikipedia and OSM. The Module:OSM needs to be embedded into a page, to show output from searches. It's thus ideal for making the Wikipedia-OSM links permanently visible for all users.
 * Wikidata can also accommodate OSM tags, see e.g. https://www.wikidata.org/wiki/Q33506