Wikidata提供cool way来在OpenStreetMap上呈现SPARQL结果。对于example:
#Big cities, grouped into map layers by population
#defaultView:Map
SELECT DISTINCT ?city ?cityLabel (SAMPLE(?location) AS ?location) (MAX(?population) AS ?population) (SAMPLE(?layer) AS ?layer)
WHERE
{
?city wdt:P31/wdt:P279* wd:Q515;
wdt:P625 ?location;
wdt:P1082 ?population.
FILTER(?population >= 500000).
BIND(
IF(?population < 1000000, "<1M",
IF(?population < 2000000, "1M-2M",
IF(?population < 5000000, "2M-5M",
IF(?population < 10000000, "5M-10M",
IF(?population < 20000000, "10M-20M",
">20M")))))
AS ?layer).
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
GROUP BY ?city ?cityLabel
我想知道是否有办法控制图例中的项目顺序(右上角)。
答案 0 :(得分:2)
似乎leaflet尝试将图层名称解析为数字。如果失败,图例中图层的顺序对应于表格中第一个外观的顺序(在&#34; Map&#34;和&#34;表&#34;视图之间切换)。
因此,您应该将其他变量与可自然排序的值绑定(然后按这些值对结果进行排序)。也许这可以使用REPLACE
,但我更喜欢使用简单字典。
#--Big cities, grouped into map layers by population--
#defaultView:Map
SELECT DISTINCT ?city ?cityLabel
(SAMPLE(?location) AS ?location) (MAX(?population) AS ?population)
(SAMPLE(?layer) AS ?layer) {
VALUES (?layer ?order) {
("<1M" 1) ("1M-2M" 2) ("2M-5M" 3) ("5M-10M" 4) ("10M-20M" 5) (">20M" 6)}
?city wdt:P31/wdt:P279* wd:Q515;
wdt:P625 ?location;
wdt:P1082 ?population.
FILTER(?population >= 500000).
BIND(
IF(?population < 1000000, "<1M",
IF(?population < 2000000, "1M-2M",
IF(?population < 5000000, "2M-5M",
IF(?population < 10000000, "5M-10M",
IF(?population < 20000000, "10M-20M",
">20M")))))
AS ?layer).
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
} GROUP BY ?city ?cityLabel ORDER BY (SAMPLE(?order))