Hoppa till innehållet

Användare:Sebastian Berlin (WMSE)/Maplink/dok: Skillnad mellan sidversioner

Från Wikipedia
Innehåll som raderades Innehåll som lades till
Ingen redigeringssammanfattning
Märke: 2017-källredigering
Ingen redigeringssammanfattning
Märke: 2017-källredigering
Rad 129: Rad 129:


==Parametrar==
==Parametrar==
===For overall display===
===För visning===
;visa
;visa
:Hur mallen visas. Giltiga värden är:
:Hur mallen visas. Giltiga värden är:
Rad 144: Rad 144:


Ramparametrar
Ramparametrar
Mapframe parameters (only work with inline display)
;ram
;ram
:Sätt till <code>ja</code> för att visa karta i ram istället för länk
:Sätt till <code>ja</code> för att visa karta i ram istället för länk
Rad 169: Rad 168:
:*Hämtas från Wikidata.
:*Hämtas från Wikidata.


===Raw GeoJSON===
=== GeoJSON===
;raw
;
:Raw GeoJSON (preferably transcluded from a subpage of [[Wikipedia:Map data]]) as well as <nowiki><maplink></nowiki> functionality not available via the other parameters. [[#The raw parameter|See below]] for more information.
: GeoJSON och <nowiki><maplink></nowiki>-funktionalitet som inte kan användas med andra parametrar. [[#Råa parametrar|Se nedan]] för mer information.


===For each feature===
===For each feature===
Multiple features can be displayed on a single map. For each additional feature, add a sequential number to the end of the parameter name. For example, the second uses parameters like {{para|type2}}, {{para|id2}}, etc., the third feature {{para|type3}}, {{para|id3}}, etc., and so on.
Flera egenskaper kan visas en och samma karta. Lägg till ett nummer till parameternamn för varje ytterligare egenskap. T.ex. den andra egenskapen använder parametrar som {{para|typ2}} och {{para|id2}}, den tredje egenskapen använder parametrar som {{para|typ3}} och {{para|id3}} o.s.v.
;typ
;type
:Type of data. Valid values are:
:Typ av data. Tillåtna värden är:
::<code>line</code> – a geoline feature from OSM (e.g. a road)
::<code>linje</code>: en geoline-egenskap från OSM (t.ex. en väg)
::<code>shape</code> – a geoshape feature from OSM (e.g. a state or province)
::<code>form</code>: en geoshape-egenskap från OSM (t.ex. en region eller provins)
::<code>shape-inverse</code> – a geomask feature from OSM (the inverse of a geoshape - allows an unobstructed view of the map beneath)
::<code>shape-inverse</code>: en geomask egenskap från OSM. En inverterad geoshape som inte skymmer den underliggande kartan.
::<code>data</code> a geoJSON data page on Commons (parameter is optional in this case)
::<code>data</code>: en GeoJSON-datasida på Commons.
a geoJSON data page on Commons (parameter is optional in this case)
::<code>point</code> a point feature (coordinates)
::<code>punkt</code>: en punktegenskad, d.v.s. koordinater.
<!-- Verkar inte finnas
::<code>named</code> – all named coordinates in an page or section ({{tlx|coord}} templates with {{para|name}} parameter)
::<code>named</code> – all named coordinates in an page or section ({{tlx|coord}} templates with {{para|name}} parameter) -->
::<code>circle</code> – a circle centred on a point's coordinates
::<code>cirkel</code>: en cirkel centrerad på koordinater
;id
;id
:''(or '''ids''')''
:''(or '''ids''')''

Versionen från 7 december 2020 kl. 14.17

Mall:Uses Wikidata Mall:Sister project

Den här mallen lägger till en länk eller en ram som visar kartdata fråm ett att av följande:

  • GeoJSON data lagrat på Commons
  • Koordinater angivna eller från Wikidata

OBS:

  • Har du mycket stora eller långsamma kartor bör du använda mapframe-taggen direkt istället för den här mallen. Anledning är att när mallen används för att anropa taggen räknas renderingen av kartan som Lua-tid, vilket kan resultera i fel då det tar för lång tid.
  • GeoJSON-filer kan inte laddas upp direkt. Skapa istället en sida på Commons i namnrymden Data som slutar med .map. Se mw:Help:Map Data för ytterligare information.
  • För att använda särdrag från OpenStreetMap (OSM), lägg till Wikidata-nycklen till OSM-relationen (och vänta en eller två dagar). Se mw:Help:Extension:Kartographer#External_data och mw:Help:Extension:Kartographer/OSM för ytterligare information.

Användningsområden

Den här mallen går att använda för att visa linjer eller polygoner för t.ex:

  • Vägar
  • Floder
  • Tåg- och tunnelbanelinjer
  • Skepps- och flygplansrutter
  • Upptäcksresor
  • Djurhabitat
  • Länder och deras indelningar

Det går även att använda mallen för att visa en punkt på en karta, d.v.s. koordinater.

Användning

Enkel användning

  • Data sida på Commons (t.ex. Data:ecos.fws.gov/Endangered habitat 58938/Plethodon neomexicanus.map):
    {{maplink|från=}} (ange .map data-sida i från=, utan Data-prefix)
  • Gräns eller annan linje från OSM:
    {{maplink|typ=linje|id=}} (Wikidata-id behövs bara om annan artikels Wikidata-sida används)
  • Form från OSM:
    {{maplink|typ=form|id=}} (Wikidata-id behövs bara om annan artikels Wikidata-sida används)
  • Inverterad form från OSM:
    {{maplink|typ=form-inverterad|id=}} (Wikidata-id behövs bara om annan artikels Wikidata-sida används)
  • Punkt (koordinater):
    ...från Wikidata:
    {{maplink|typ=punkt|id=}} (Wikidata-id behövs bara om annan artikels Wikidata-sida används)
    ...från angivna koordinater:
    {{maplink|typ=punkt|coord=}} (ange koordinater med mallen {{Coord}})
  • Cirkel (centrerad på punktens koordinater):
    ...från Wikidata:
    {{maplink|typ=cirkel|radie=|id=}} (Wikidata-id behövs bara om annan artikels Wikidata-sida används)
    ...från angivna koordinater:
    {{maplink|typ=cirkel|radie=|koordinater=}} (ange koordinater med mallen {{Coord}})
  • För att visa ram, lägg till parametern |ram=ja.
Map
Ramexample
  • Det finns fler parametrar för att anpassa kartan.

Map

Alla parametrar för datasida

{{maplink
|visa=
|från=
|zoom=
|text=
|ikon=
}}

Alla parametrar för linje eller form

{{maplink
|visa=
|typ=
|id=
|titel=
|beskrivning=
|linjefärg=
|linjetjocklek=
|zoom=
|text=
|ikon=
}}

Alla parametrar för punkt

{{maplink
|visa=
|typ=punkt
|id=
|titel=
|beskrivning=
|koordinater=
|markör=
|zoom=
|text=
|ikon=
}}

Alla parametrar för cirkel

{{maplink
|visa=
|type=cirkel
|radie=  <!-- i meter, andra parametrar finns för andra enheter --> 
|id=
|titel=
|beskrivning=
|koordinater=
|markör=
|zoom=
|text=
|ikon=
}}

Parametrar

För visning

visa
Hur mallen visas. Giltiga värden är:
länk - Visa bara länk (behövs inte anges eftersom det här är standard)
titel - Visa bara titel
länk,titel - Visa länk och titel
titel,länk - Samma som ovan
text
Text att visa för länken eller tiel för ram. Standard är "Karta"
ikon
Ange "nej" för att dölja ikonen som visas bredvid länken.
zoom
Zoomnivå mellan 1 och 19. Större nummer zoomar ut. Standard baseras på kartan, om inte bara en punkt har angivits.

Ramparametrar

ram
Sätt till ja för att visa karta i ram istället för länk
ren
Sätt till ja för att bara visa karta utan ram eller rubrik. Parametern text ignoreras.
ramjustering
Justera på sidan: left, center, or right. Standard är right
rambredd
Bredden på kartramen. Standard är 300
ramhöjd
Höjden på kartramen. Standard är 200
ramkoordinater
(Valfri) Alternativa koordinater för placeringen av kartan. Använd mallen {{Coord}} för att ange koordinater (e.g. |frame-coordinates={{Coord|12.34|S|56.78|W}}). Koordinater hämtas från Wikidata om ej angett.
ramlatitud
(ignoreras om |ramkoordinater= är angett)
(Valfir) Alternativ latitudkoordinat för placeringen av kartan.
ramlongitud
(ignoreras om |ramkoordinater= är angett)
(Valfir) Alternativ longitudkoordinat för placeringen av kartan.
Om ramlatitud och -longitud inte anges av parmetrar kan ramkoordinatera automatiskt bestämmas:

If frame latitude and longitude are not set by parameters, then frame coordinates can be determined automatically, either:

  • Baserat på linje och former, eller
  • Punkt specificerad i |koordinater=, eller
  • Hämtas från Wikidata.

Rå GeoJSON

Rå GeoJSON och <maplink>-funktionalitet som inte kan användas med andra parametrar. Se nedan för mer information.

For each feature

Flera egenskaper kan visas på en och samma karta. Lägg till ett nummer till parameternamn för varje ytterligare egenskap. T.ex. den andra egenskapen använder parametrar som |typ2= och |id2=, den tredje egenskapen använder parametrar som |typ3= och |id3= o.s.v.

typ
Typ av data. Tillåtna värden är:
linje: en geoline-egenskap från OSM (t.ex. en väg)
form: en geoshape-egenskap från OSM (t.ex. en region eller provins)
shape-inverse: en geomask egenskap från OSM. En inverterad geoshape som inte skymmer den underliggande kartan.
data: en GeoJSON-datasida på Commons.
a geoJSON data page on Commons (parameter is optional in this case)
punkt: en punktegenskad, d.v.s. koordinater.
cirkel: en cirkel centrerad på koordinater
id
(or ids)
Wikidata id (Q-number) of the point feature, Wikidata id that the OSM line/shape feature is tagged with. Separate multiple ids with a comma. Defaults to the current page's Wikidata id (if |from= not set).
from
Source of map data:
  • If type is data or omitted: The JSON (.map) file from Commons to display (excluding the Data: prefix)
  • If type is named: Page name, or name#section, to get named coordinates from. If omitted, or specified as just #section, then current page will be used.
title
Title of the feature (for features from OSM), displayed when the feature is clicked on; default is the page title
description
Description of the feature (for features from OSM), displayed when the feature is clicked on; optional
stroke-color
(or stroke-colour)
Color code for the color used to draw the feature (for features from OSM); default is #ff0000 (red)
stroke-width
Width for the lines used to draw the feature (for features from OSM); default is 6
stroke-opacity
Opacity for the lines used to draw the feature (for features from OSM) – a number between 0 (fully transparent) and 1 (fully opaque); default is 1
fill
Color code for the fill color of the feature (for shape or shape-inverse features from OSM); default is #000000 (black). Note that a semi-transparent version of the specified color will be used by default, allowing the map below to still be seen.
fill-opacity
Opacity for the fill color of the feature (for shape or shape-inverse features from OSM) – a number between 0 (fully transparent) and 1 (fully opaque); default is 0.5
coord
Coordinates to display for a point feature. Use {{Coord}} template to specify coordinates (e.g. |coord={{Coord|12.34|S|56.78|W}}). If not set, coordinates will be retrieved from Wikidata.
marker
Name of Maki marker image to display at the point feature. See mw:Maps/Icons for options. If not set, a plain marker will be shown without an image.
marker-color
(or marker-colour)
Color code (Hex triplet) specifying marker background color. Default is 5E74F3 (    )
marker-size
Size of the marker. Can be small, medium (default) or large.
radius
(or radius_m), or alternative parameters radius_km, or radius_mi, or radius_ft
Radius of the circle. In metres by default, or in kilometers or miles or feet if the alternative parameters are used.
edges
Number of edges used to construct the circle. Default is 32. Higher numbers will result in a smoother circle but use more Lua processing resources.

Multiple map switcher

An option for Template:Switcher-style switching of multiple mapframes, where specified parameters like zoom, or frame coordinates, or a shape's item id are switched between different values. When using, ensure the number of values in each list are the same.

Instructions:

  1. Add parameter switch to specify labels for the different options: a list separated by either,, or ; if the labels contain commas, or ### if the labels contain semi-colons. Each label will be displayed with a prefix of "Show ".
    Example: |switch=zoomed out, zoomed mid, zoomed in
  2. For each parameter that is to be switched, set its value to Mall:Kbd followed by a list of values to switch between, again separated by , or ; or ###
    Example: |zoom=SWITCH:4,9,14
    Parameters frame, plain, and text should not be switched
  3. Make sure each list has the same number of entries. The position of value in a Mall:Kbd list corresponds to the same position in the list of labels set in |switch=.

Example:

Map
Boston
{{mapframe|frame=yes|type=point|id=Q100|text=Boston|zoom=SWITCH:4,9,14|switch=zoomed out, zoomed mid, zoomed in}}

Examples and tips

Multiple features

Multiple features allow you to:

  • Use external data from both Wikimedia Commons and OpenStreetMap together
  • Apply different styles to different external data features from OpenStreetMap
  • Include multiple links to external data from Wikimedia Commons

Karta

{{Maplink|frame=yes
|type=shape|id=Q3495894|title=Shape|description=Description of shape
|type2=line|id2=Q1318331|title2=Line|description2=Description of line
|type3=point|coord3={{coord|32|S|116|E}}|title3=Point|description3=Description of point
}}

Karta

{{Maplink|frame=yes|plain=yes|frame-width=250|frame-height=280|zoom=6|frame-lat=29.185|frame-long=76.225
|type=shape-inverse|id=Q1174|title=Haryana
|type2=point|id2=Q200663|stroke-width=3|title2=Faridabad
}}

Infoboxes

Mapframes can be included in infoboxes. Using |plain=yes to remove the outer frame is recommended.

For simple cases with a single feature, {{infobox mapframe}} can be used instead (see that template's documentation for details). Mall:Infobox Australian road

{{Infobox Australian road
| location = {{maplink |type=line |frame=yes |plain=yes |frame-align=center |frame-lat=-31.8262 |frame-long=115.7877 |zoom=9}}
  ...  (other parameters omitted)  ...
}}

The raw parameter

The "raw" parameter allows the same inputs as the full <maplink> function. It allows you to:

  • Use GeoJSON data directly
  • Use Wikidata queries to obtain information for the map
  • Use templates - if a map includes direct GeoJSON or many components, placing the data in a template will avoid cluttering the article text

See mw:Help:Extension:Kartographer for instructions.

Raw GeoJSON example

Route map

{{maplink|raw={{Wikipedia:Map data/Main Roads Western Australia/Forrest Highway}}|text=Route map}}

(Link to GeoJSON data subpage: Wikipedia:Map data/Main Roads Western Australia/Forrest Highway)

Raw Wikidata query examples

Ten countries

{{maplink|frame=yes|text=Ten countries|raw={
  "type": "ExternalData",
  "service": "geoshape",
  "query": "
SELECT * WHERE {
  ?id wdt:P463 wd:Q1065 .
} LIMIT 10
"}
|frame-width=600|frame-height=400|frame-lat=25|frame-long=10|zoom=1
}}

Karta

{{maplink|frame=yes|raw={
  "type": "ExternalData",
  "service": "geoshape",
  "query": "
SELECT ?id ?head
  (SAMPLE(?img) as ?img_) 
  (min(?partyId) as ?party) 
  (if(?party = '0', '#800000', if(?party = '1', '#000080', '#008000')) as ?fill)
  (concat('[[', substr(str(?link),31,500),  '{{!}}', ?headLabel, ']]') as ?title)
  (concat(?stateLabel, '\\n', '[[File:', substr(str(?img_), 52, 500), '{{!}}200px]]') as ?description)
WHERE {  
  ?id wdt:P31 wd:Q35657 .
  ?id wdt:P6 ?head .
  ?head wdt:P102 ?party .
  BIND(if(?party = wd:Q29468, '0', if(?party = wd:Q29552, '1', '2')) as ?partyId) 
  SERVICE wikibase:label {
    bd:serviceParam wikibase:language 'en' .
    ?head rdfs:label ?headLabel .
    ?id rdfs:label ?stateLabel .
  }
  OPTIONAL {
    ?head wdt:P18 ?img .
  }
  ?link schema:about ?head .
  ?link schema:isPartOf <https://en.wikipedia.org/> .
} GROUP BY ?id ?head ?headLabel ?link ?stateLabel
"}|frame-width=600|frame-height=400|frame-lat=52|frame-long=-110|zoom=3}}

Gotchas

  • When retrieving lines or shapes from OSM, you can't style the fill color or the opacity level of fills or strokes (unless you use the |raw= parameter)
  • The following code utilising the |raw= parameter won't work because the curly brace to close the GeoJSON is adjacent to the curly braces to close the template:
{{Maplink|raw= {"type": "ExternalData","service": "geoshape","ids": "Q13518258"}}}
To fix it, put a space before the two template braces or move them to a separate line.

Tutorials

Redirects

See also