User:Yurik/maplink

From Wikipedia, the free encyclopedia
<maplink latitude="42.68" longitude="-114.79" zoom="3" width="600" height="400" align="left" text="Governors of US states with their party affiliation">
{
"type": "ExternalData",
"service": "geoshape",
"query": "SELECT ?id ?head
  (SAMPLE(?img) as ?img) 
  (SAMPLE(?fill) as ?fill) 
  (concat('[[wikipedia:', 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, '#800000', if(?party = wd:Q29552, '#000080', '#008000')) as ?fill) 
  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"
}
</maplink>

Produces this link:

<maplink>: Couldn't parse JSON: Control character error, possibly incorrectly encoded

Try it at query.wikidata.org.

See also - Kartographer help page.