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

(Note that this means the script performs searches on overpass and osm.wikipedia.link for you. This means that - depending on your configuration - the script effectively send the title/wikidata tag to those sites. In 'viewing' mode, see below, this information is send for each page you visit. In 'view on demand' mode, it is only sent by explicit confirmation.)

= 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.

Using the 'tabs': results, map, options
You can use the Gadget just to view OSM maps within the wiki page - that's the default mode after installation. Only the 'map' is displayed.
 * You can decide what you see using the "results" and "map" 'tabs': Just click the 'tab' and the pane appears/disappears.
 * You can use the options 'tab' to configure the map height, and choose defaults standard confgurations.
 * There are also advanced options - they are set by the defaults links. They can't really break anything, but using those may lead to unexpected behaviour.

The Standard configurations (accessed from the options tab) are
 * viewing: standard confguration for viewing. In this configuration, the first overpass query always runs to determine whether an object exists. If no object exists, the 'map' label changes to 'no map'. Otherwise, an object exists. If an object exists: If the map tab is closed, click it to show the map. If the the map tab is open, the map loads automatically.
 * viewing on demand: standard confguration for viewing (on demand). In this configuration, no queries are made until you click on one of the menu items (e.g. 'map').
 * matching: standard confguration for matching (various searches enabled).
 * megalithic sites with queries as needed: standard confguration for matching megalithic sites (various searches enabled, added default tags).
 * megalithic sites with all queries: same as previous, but with always running all queries.

Viewing and adding data: * and +
The gadget was developed to create better links between Wikipedia/wikidata and OSM. In the UI, 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 your "USERPAGE/common.js". You can just click here to go to it:
 * en en:Special:MyPage/common.js.
 * de de:Special:MyPage/common.js.
 * es es:Special:MyPage/common.js.
 * ca ca:Special:MyPage/common.js.
 * fr fr:Special:MyPage/common.js.
 * it it:Special:MyPage/common.js.

Then copy this text to that page: /* Documentation available at https://www.mediawiki.org/wiki/User:Bjohas/OSMgadget Code available at https://github.com/bjohas/OSM-Wikipedia-Monkey/blob/master/Gadget%20Wikipedia%20to%20OSM.js mw.loader.load( 'https://rawgit.com/bjohas/OSM-Wikipedia-Monkey/master/Gadget%20Wikipedia%20to%20OSM.js'); (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