On https://query.wikidata.org/, you can easily display the result of a query on a dynamic map (see the Venues in Broadway for example). But if you want to add this map to Wikipedia or any other Wikimedia project, you can't (except if you take a screenshot..).
Description
Event Timeline
It is possible look here for example:
https://de.wikivoyage.org/wiki/Spiekeroog
@Yurik can explain you how it works.
I see only one map in this page which (if I'm not wrong) is not based on a SPARQL query. Are you sure this is the right page?
@Evad37 has just confirmed here that this is not currently possible.
Since Kartographer already supports SPARQL queries (for geoshapes) and fetching coordinates from Wikidata based on a fixed list of Wikidata ids, I assume that it shouldn't be such a big change to display the results of a SPARQL query as geopoints on a map. WDQ already do that very well.
To clarify, what is wanted is a new external data service that takes in a query, looks up the P625 for each item from the query, and displays these as point features on a map
(in a similar way to how point features are displayed for geoJSON like { "type": "Point", "coordinates": [-150, 64] })
Basically, we should be able to use syntax like
<mapframe> { "type": "ExternalData", "service": "geopoint", "query": " // query goes here "} </mapframe>
to display point features based on wikidata coordinates, without having to know the wikidata ids in advance.
It would also be nice if there was a way to individually specify the Maki marker image, similar to how the geoshape example can specify fill colours for shapes.
Plus if there was also a way to just specify one or more wikidata ids without a query, then T178321 could be solved without having to use Lua.
I want this too. Actually a deceptively simple thing that would be quite useful on Wikimedia Commons as well.
For instance, on gallery pages about artist James Ensor I want to include dynamic Wikidata-driven maps indicating the cultural institutions that have his works in their collection (simple query), where the map auto-updates as we add more works (and corresponding collections/institutions) on Wikidata.
I believe this ticket can now be closed since T302297: Display geopoint SPARQL queries in a map in Wikipedia (GeoPoints) was deployed to all wikis on Sept 26. Kartographer generated maps can now display the result of a SPARQL query with geopoints/markers instead of only geoshapes as it was previously.
See the help page for how to use it. It works basically as @Evad37 suggested in T188291#4266453.
I did a quick test, here's a very simple one I just created! https://commons.wikimedia.org/wiki/User:Spinster/Map_test
Is it possible to populate the marker text in the popup via the query as in the geoshape example?
I tried to pass the text in ?description execting that it would generate the clickable marker.
https://it.wikipedia.org/wiki/Utente:Sabas88/Maps/Staglieno
If you enter that query into the query service, you’ll notice that ur description is still empty, so it’s logical that it didn’t work for you
It's possible, but not straightforward. With a few Wikimedians we're trying to figure it out.
Examples for now:
- Second map at https://commons.wikimedia.org/wiki/User:Spinster/Map_test has colored pins and small cards (no images)
- https://sv.wikipedia.org/wiki/Anv%C3%A4ndare:Ainali/kartographer uses map pin symbols, colors, cards that include images
I would also like to include links to Wikipedia articles but am stuck. I have requested SPARQL help at https://www.wikidata.org/wiki/Wikidata:Request_a_query#Help_with_a_SPARQL_query_for_Kartographer
I can imagine a big collection of Kartographer-SPARQL examples would make sense; the examples at https://www.mediawiki.org/wiki/Help:Extension:Kartographer#Via_Wikidata_query are good but not enough to help people like me to build things with confidence.
@Spinster In this diff I added links to articles if they exist: https://sv.wikipedia.org/w/index.php?title=Anv%C3%A4ndare:Ainali/kartographer&type=revision&diff=51241405&oldid=51237475&diffmode=source
Is it possible to get dots rather than pushpins? Disadvantage of the latter is that very many of them - e.g. in the example above or at https://commons.wikimedia.org/wiki/User:Spinster/Map_test - occlude the map altogether & will be completely inappropriate for many SPARQL-derived applications.
I don't think anything but pushpins are currently supported by Kartographer. There is T131618: Customize map markers in Kartographer as a request.
BTW. You can set ('small' AS ?marker_size) to make the markers the smaller version.
I've tried with a simple query which is working fine on WQS but got not result: https://www.wikidata.org/wiki/User:Ayack/Draft
Is there a max number of items to be displayed?
There are always limits. In this case though, I wonder if it is because some of your results are set to the special value 'unknown'.
Confirmed. Adding FILTER (!wikibase:isSomeValue(?geo)). fixed it by removing values of which the location is unknown.
There are always limits. In this case though, I wonder if it is because some of your results are set to the special value 'unknown'.
Confirmed. Adding FILTER (!wikibase:isSomeValue(?geo)). fixed it by removing values of which the location is unknown.
Thanks! I hadn't thought of that.
Nice I got it working with colors and popup https://it.wikipedia.org/wiki/Utente:Sabas88/Maps/Staglieno
I've tried to use it in a template but it seems the parameter is not passed to it: https://www.wikidata.org/wiki/User:Ayack/Draft
Any idea where it comes from please?
Edit: You have to use
{{#tag:mapframe | { "type": "ExternalData", "service": "geopoint", "query": "SELECT ..." } }}
Here is an example with the link to the article as part of the title and the image being part of the description.
SELECT ?id ?geo (CONCAT("[[w:", SUBSTR(STR(?article), 31 , 400 ), "{{!}}", ?label, "]]") AS ?title) (CONCAT(?descr, ' [[File:', SUBSTR(STR(?image), 52 , 400 ), '{{!}}200px]]') AS ?description) ?image ?article WHERE { VALUES ?id { wd:Q1431922 } ?id wdt:P625 ?geo; schema:description ?descr; rdfs:label ?label; wdt:P18 ?image . ?article schema:about ?id; schema:inLanguage "en" . FILTER (SUBSTR(str(?article), 1, 25) = "https://en.wikipedia.org/") FILTER(LANGMATCHES(LANG(?label), "EN")) FILTER(LANGMATCHES(LANG(?descr), "EN")) }