Line 1: |
Line 1: |
− | {{High-risk|1,000,000+}} | + | {{Module rating|release}}{{Module rating|protected}} |
− | {{Uses Wikidata|P625}} | + | '''Careful, this function is live, and called by {{tl|Location}} template. The documentation might not be complete''' |
− | {{Tracks Wikidata|P625}} | |
− | {{Module rating|protected}}
| |
| | | |
− | '''Note:''' The code which this module's main function (<code>coord</code>) outputs is directly parsed and/or manipulated by [[Module:Location map]] and other functions of this module itself (<code>coord2text</code> and <code>coordinsert</code>). If the structure of the output changes (for example, to use [[:mw:Help:Extension:Kartographer|the <code><nowiki><mapframe></nowiki></code> and <code><nowiki><maplink></nowiki></code> tags]]), please update the aforementioned scripts as well.
| + | This module provides most of the logic behind {{tl|location}} and related geolocation templates. |
| + | It provides several methods visible to the templates: |
| + | |
| + | *'''<nowiki>{{#Invoke:Coordinates | parseAttribute|</nowiki> ''attribute string'' | ''attribute name'' <nowiki>}}</nowiki>''' : parse {{tl|location}} attribute parameter ''attribute string'' and return value of the ''attribute name'' parameter |
| | | |
− | ==Using the module with coordinsert==
| + | *'''<nowiki>{{#Invoke:Coordinates | getHeader|</nowiki> ''attribute string'' <nowiki>}}</nowiki>''' : parse {{tl|location}} attribute parameter ''attribute string'' and return the numeric value of the header attribute. |
− | When using the {{tl|Coord}} template inside another template, like an infobox, there may be parameters (like <code><var>type</var>:<var>airport</var></code>) which should be added automatically. To do so, do something like this:
| |
− | <code>{{#if:{{{coordinates|}}}|{{#invoke:Coordinates|coordinsert|{{{coordinates|}}}|<var>parameter1:value1|parameter2:value2|parameter3:value3…</var>}}|</code>
| |
| | | |
− | Do not add more vertical bars <code>|</code> than necessary.
| + | *'''<nowiki>{{#Invoke:Coordinates | GeoHack_link|</nowiki> lat=... | lon=... |lang=''xx'' | site=... | globe=... <nowiki>}}</nowiki>''': creates link to GeoHack tool and display location coordinates. The URLs are based on website and latitude/longitude coordinates. Language is used so it can be passes to the website. Globe parameter is used to allow specifying coordinates on planets other than earth. |
| | | |
− | ==Using the module with coord2text to extract latitude or longitude== | + | :*'''<nowiki>{{#Invoke:Coordinates | lat_lon|</nowiki> lat=... | lon=... |lang=''xx'' <nowiki>}}</nowiki>''': create coordinate location string based on decimal degrees latitude and longitude number. Language is used to localize the presentation of the numbers. |
− | Developers maintaining legacy code may need to extract latitude or longitude to use a parameters in other code, or a mathematical expression.
| |
− | The module's "coord2text" function can be used to extract data from the {{tl|Coord}} template. To extract the latitude from a Coord template, use:
| |
| | | |
− | <code><nowiki>{{#invoke:coordinates|coord2text|{{Coord|57|18|22|N|4|27|32|E}}|lat}}</nowiki></code> → {{#invoke:coordinates|coord2text|{{Coord|57|18|22|N|4|27|32|E}}|lat}}
| + | ::*'''<nowiki>{{#Invoke:Coordinates | deg2dms|</nowiki> ''degrees''|lang=''xx'' <nowiki>}}</nowiki>''': create dms (degree/minute/second) string based on decimal degrees number. Language is used to localize the presentation of the numbers. |
| | | |
− | To extract the longitude, use:
| + | :*'''<nowiki>{{#Invoke:Coordinates | externalLink|</nowiki> site=... | globe=... | lat=... | lon=... |lang=''xx'' <nowiki>}}</nowiki>''': create URLs for different sites which are used by coordinate location templates. The URLs are based on website and latitude/longitude coordinates. Language is used so it can be passes to the website. Globe parameter is used to allow specifying coordinates on planets other than earth. |
| | | |
− | <code><nowiki>{{#invoke:coordinates|coord2text|{{Coord|57|18|22|N|4|27|32|E}}|long}}</nowiki></code> → {{#invoke:coordinates|coord2text|{{Coord|57|18|22|N|4|27|32|E}}|long}} | + | == Examples== |
| + | Functions: |
| + | *'''deg2dms'''(degree, degree_precision, language) |
| + | :*<nowiki>{{#invoke:Coordinates| deg2dms | 12.3456789}}</nowiki> will display "{{#invoke:Coordinates| deg2dms | 12.3456789}}" |
| + | :*<nowiki>{{#invoke:Coordinates| deg2dms | 12.3456789 |1}}</nowiki> will display "{{#invoke:Coordinates| deg2dms | 12.3456789 |1 }}" |
| + | :*<nowiki>{{#invoke:Coordinates| deg2dms | 12.3456789 |1e-1}}</nowiki> will display "{{#invoke:Coordinates| deg2dms | 12.3456789 |1e-1}}" |
| + | :*<nowiki>{{#invoke:Coordinates| deg2dms | 12.3456789 |1e-3}}</nowiki> will display "{{#invoke:Coordinates| deg2dms | 12.3456789 |1e-3 }}" |
| + | :*<nowiki>{{#invoke:Coordinates| deg2dms | 12.3456789 |1e-4}}</nowiki> will display "{{#invoke:Coordinates| deg2dms | 12.3456789 |1e-4 }}" |
| + | :*<nowiki>{{#invoke:Coordinates| deg2dms | 12.3456789 |1e-5}}</nowiki> will display "{{#invoke:Coordinates| deg2dms | 12.3456789 |1e-5 }}" |
| + | *'''lat_lon''' |
| + | :*<nowiki>{{#invoke:Coordinates| lat_lon | lat=51.48 | lon=0}}</nowiki> will display "{{#invoke:Coordinates| lat_lon | lat=51.48 | lon=0}}" |
| + | *'''GeoHack_link''' |
| + | :*<nowiki>{{#invoke:Coordinates| GeoHack_link | lat=51.48123 | lon=0}}</nowiki> will display {{#invoke:Coordinates| GeoHack_link | lat=51.48123 | lon=0}} |
| + | :*<nowiki>{{#invoke:Coordinates| GeoHack_link | lat=51.48123 | lon=0 | lang=en }}</nowiki> will display {{#invoke:Coordinates| GeoHack_link | lat=51.48123 | lon=0 | lang=en }} |
| + | :*<nowiki>{{#invoke:Coordinates| GeoHack_link | lat=51.48123 | lon=0 | lang=ru }}</nowiki> will display {{#invoke:Coordinates| GeoHack_link | lat=51.48123 | lon=0 | lang=ru }} |
| + | :*<nowiki>{{#invoke:Coordinates| GeoHack_link | lat= | lon=0 | lang=ru }}</nowiki> (with missing latitude value) will display "{{#invoke:Coordinates| GeoHack_link | lat= | lon=0 | lang=ru }}" |
| + | *'''externalLinksSection''' |
| + | *:<nowiki>{{#invoke:Coordinates| externalLinksSection | globe = Earth| lat=51.48 | lon=0 | lang=en | namespace=File}}</nowiki> displays "{{#invoke:Coordinates| externalLinksSection | globe = Earth| lat=51.48 | lon=0 | lang=en | namespace=File}}" |
| + | :*<nowiki>{{#invoke:Coordinates| externalLinksSection | globe = Earth| lat=51.48 | lon=0 | lang=en | namespace=Category}}</nowiki> displays "{{#invoke:Coordinates| externalLinksSection | globe = Earth| lat=51.48 | lon=0 | lang=en | namespace=Category}}" |
| + | :*<nowiki>{{#invoke:Coordinates| externalLinksSection | globe = Earth| lat=51.48 | lon=0 | lang=ru | namespace=Category}}</nowiki> displays "{{#invoke:Coordinates| externalLinksSection | globe = Earth| lat=51.48 | lon=0 | lang=ru | namespace=Category}}" |
| + | :*<nowiki>{{#invoke:Coordinates| externalLinksSection | globe = Mars| lat=51.48 | lon=0 | lang=en | namespace=File}}</nowiki> displays "{{#invoke:Coordinates| externalLinksSection | globe = Mars| lat=51.48 | lon=0 | lang=en | namespace=File}}" |
| + | :*<nowiki>{{#invoke:Coordinates| externalLinksSection | globe = Moon| lat=51.48 | lon=0 | lang=en | namespace=File}}</nowiki> displays "{{#invoke:Coordinates| externalLinksSection | globe = Moon| lat=51.48 | lon=0 | lang=en | namespace=File}}" |
| + | *'''LocationTemplateCore''' |
| + | :*<nowiki>{{#invoke:Coordinates| LocationTemplateCore | globe = Earth| lat=51.48 | lon=0 | lang=en | namespace=File| attributes=elevation:10_heading:W | mode=camera | bare = 1| secondary=1}}</nowiki> displays "{{#invoke:Coordinates| LocationTemplateCore | globe = Earth| lat=51.48 | lon=0 | lang=en | namespace=File| attributes=elevation:10_heading:W | mode=camera | bare = 1| secondary=1}}" |
| + | :*<nowiki>{{#invoke:Coordinates| LocationTemplateCore | globe = Earth| lat=51.48 | lon=0 | lang=en | namespace=File| attributes=elevation:10_heading:W | mode=camera | bare = 0| secondary=1}}</nowiki> displays "{{#invoke:Coordinates| LocationTemplateCore | globe = Earth| lat=51.48 | lon=0 | lang=en | namespace=File| attributes=elevation:10_heading:W | mode=camera | bare = 0 | secondary=1}}" |
| + | See [[Module talk:Coordinates/testcases |testcases]] to see more examples. |
| | | |
− | == Modules using this module directly == | + | ==Dependencies== |
− | * [[Module:HS listed building]]
| + | Relies on [[Module:I18n/coordinates]] for all of the internationalization translations. |
− | | |
− | == Tracking categories ==
| |
− | * {{clc|Pages with malformed coordinate tags}}
| |
− | * {{clc|Coordinates not on Wikidata}}
| |
− | * {{clc|Coordinates on Wikidata}}
| |
− | * {{clc|Coordinates on Wikidata set to no value}}
| |
− | * {{clc|Coordinates on Wikidata set to unknown value}}
| |
− | | |
− | <includeonly>{{#switch:{{SUBPAGENAME}}|sandbox2|sandbox=|
| |
− | [[Category:Modules that add a tracking category]]
| |
− | }}</includeonly>
| |