Mòdul:Map: diferència entre les revisions

Contingut suprimit Contingut afegit
actualització de ca.wiki, canvis menors en el zoom
actualització, nou paràmetre commons
 
Línia 5:
-- CSGNetwork at http://www.csgnetwork.com/degreelenllavcalc.html via @enwiki
-- OpenStreetMap
-- Version: 2018270520181028
 
local p = {}
Línia 116:
end
return stack
end
 
-- remove duplicated points, they may affect zoom calculation
local function setUniquePoints(t)
-- build set of unique values
local uniqueElements = {}
for _, point in ipairs(t) do
if not uniqueElements[point[1]] then
uniqueElements[point[1]] = {}
end
uniqueElements[point[1]][point[2]] = true
end
-- convert the set
local result = {}
for lon, _ in pairs(uniqueElements) do
for lat, _ in pairs(uniqueElements[lon]) do
table.insert(result, {lon, lat})
end
end
return result
end
 
Linha 205 ⟶ 226:
printError('ids-invalid', id)
else
value = mw.wikibase.getEntityObjectgetBestStatements(id, snak[2])
for i in= ipairs(3, #snak) do
if value == nil then break end
value = value[snak[i]]
Linha 235 ⟶ 256:
local id = mw.text.split(ids, '%s*,%s*')
if #coord ~= #id then return {} end
local id_parent = nil
if #id == 1 then
id_parent = fetchWikidata(id[1], {'claims', 'P131', 1, 'mainsnak', 'datavalue', 'value', 'id'})
if id_parent ~= nil then
id[2] = id_parent -- P131: located in the administrative territorial entity, last try
coord[2] = coord[1]
end
end
local bounds = {}
-- try to fetch Wikidata in this order: area, watershed area, population, and finally by administrative entity
local snak_area = {'claims', 'P2046', 1, 'mainsnak', 'datavalue', 'value'} -- area and unit
local snak_warea = {'claims', 'P2053', 1, 'mainsnak', 'datavalue', 'value'} -- area and unit
Linha 244 ⟶ 273:
-- query Wikidata: http://tinyurl.com/j8aez2g
for i = 1, #id do
if i == 2 and id[2] == id_parent and #bounds > 0 then break end -- only if not found previously
local amount, unit, area
local value = fetchWikidata(id[i], snak_area) or fetchWikidata(id[i], snak_warea)
Linha 307 ⟶ 337:
tagArgs.class = args.class
end
local wdid = args.item or mw.wikibase.getEntityIdForCurrentPage()
if args['coordinates1'] == nil and args['geotype1'] == nil then -- single feature
Linha 313 ⟶ 345:
args['coordinates1'] = args['latitude'] .. ',' .. args['longitude']
elseif args['coordinates1'] == nil then
args['coordinates1'] = getCoordinatesById(mw.wikibase.getEntityIdForCurrentPage()wdid)
end
args['title1'] = args['title1'] or args['title']
Linha 319 ⟶ 351:
args['description1'] = args['description1'] or args['description']
args['geotype1'] = args['geotype1'] or args['geotype']
args['commons1'] = args['commons1'] or args['commons']
end
local externalData = {['geoshape'] = true, ['geomask'] = true, ['geoline'] = true, ['page'] = true, ['none'] = true}
local featureCollection = {['Point'] = true, ['MultiPoint'] = true, ['LineString'] = true, ['Polygon'] = true}
local myfeatures, myexternal, allpoints = {}, {}, {}
local i, j = 1, 1
while args['coordinates'..i] or externalData[args['geotype'..i]] or args['commons'..i] do
local geotypex = args['geotype'..i] or args['geotype']
if geotypex == nil and args['commons'..i] then
geotypex = 'page'
end
if geotypex ~= nil and not (featureCollection[geotypex] or externalData[geotypex]) then
printError('geotype-invalid', geotypex)
Linha 332 ⟶ 368:
end
if geotypex == 'none' then -- skip this object
local mystack
i = i + 1
if externalData[geotypex or ''] then
else
mystack = myexternal
jlocal = #mystack + 1
if externalData[geotypex or ''] then
mystack[j] = {}
mystack[j]['type'] = "ExternalData"myexternal
j = #mystack + 1
mystack[j]['service'] = geotypex
mystack[j] = {}
mystack[j]['ids'] = args['ids'..i] or args['ids'] or mw.wikibase.getEntityIdForCurrentPage()
if mystack[j]['idstype'] == nil then printError('ids-not-found'); break end"ExternalData"
mystack[j]['service'] = geotypex
local mycoordinates = args['coordinates'..i]
if geotypex == "page" then
if mycoordinates == nil and (tagArgs.latitude == nil or tagArgs.longitude == nil or tagArgs.zoom == nil) then
local page_name = args['commons'..i]
mycoordinates = getCoordinatesById(mystack[j]['ids'])
if mw.ustring.find(page_name, "Data:", 1, true) == 1 then
end
page_name = string.sub(page_name, 6)
if mycoordinates ~= nil then
end
local mypoints = getBoundsById(mystack[j]['ids'], mycoordinates)
if #mypointsmw.ustring.find(page_name, ".map", -4, true) == 0nil then
page_name = page_name .. '.map'
mypoints = parseGeoSequence(mycoordinates, mycoordinates:find(';') and 'MultiPoint' or 'Point')
end
mystack[j]['title'] = page_name
else
mystack[j]['ids'] = args['ids'..i] or args['ids'] or wdid
if mystack[j]['ids'] == nil then printError('ids-not-found'); break end
end
local mycoordinates = args['coordinates'..i]
allpoints = mergePoints(allpoints, mypoints)
if mycoordinates == nil and (tagArgs.latitude == nil or tagArgs.longitude == nil or tagArgs.zoom == nil) then
mycoordinates = getCoordinatesById(mystack[j]['ids'])
end
if mycoordinates ~= nil then
local mypoints = getBoundsById(mystack[j]['ids'], mycoordinates)
if #mypoints == 0 then
mypoints = parseGeoSequence(mycoordinates, mycoordinates:find(';') and 'MultiPoint' or 'Point')
end
allpoints = mergePoints(allpoints, mypoints)
end
else
mystack = myfeatures
j = #mystack + 1
mystack[j] = {}
mystack[j]['type'] = "Feature"
mystack[j]['geometry'] = {}
mystack[j]['geometry']['type'] = geotypex or findGeotype(args['coordinates'..i])
mystack[j]['geometry']['coordinates'] = parseGeoSequence(args['coordinates'..i], mystack[j]['geometry']['type'])
allpoints = mergePoints(allpoints, mystack[j]['geometry']['coordinates'])
addCategories(mystack[j]['geometry']['type'], i)
end
mystack[j]['properties'] = {}
else
mystack[j]['properties']['title'] = args['title'..i] or (geotypex and geotypex .. i) or mystack[j]['geometry']['type'] .. i
mystack = myfeatures
if args['image'..i] then
j = #mystack + 1
args['description'..i] = (args['description'..i] or '') .. '[[File:' .. args['image'..i] .. '|300px]]'
mystack[j] = {}
end
mystack[j]['type'] = "Feature"
mystack[j]['geometryproperties']['description'] = {}args['description'..i]
mystack[j]['geometryproperties']['typemarker-size'] = geotypex or findGeotype(args['coordinatesmarker-size'..i]) or args['marker-size']
mystack[j]['geometryproperties']['coordinatesmarker-symbol'] = parseGeoSequence(args['coordinatesmarker-symbol'..i], mystack[j]['geometry']or args['typemarker-symbol'])
mystack[j]['properties']['marker-color'] = args['marker-color'..i] or args['marker-color']
allpoints = mergePoints(allpoints, mystack[j]['geometry']['coordinates'])
addCategories(mystack[j]['geometryproperties']['typestroke'], = args['stroke'..i)] or args['stroke']
mystack[j]['properties']['stroke-opacity'] = tonumber(args['stroke-opacity'..i] or args['stroke-opacity'])
end
mystack[j]['properties']['stroke-width'] = {}tonumber(args['stroke-width'..i] or args['stroke-width'])
mystack[j]['properties']['titlefill'] = args['titlefill'..i] or (geotypex and geotypex .. i) or mystack[j]args['geometryfill']['type'] .. i
mystack[j]['properties']['fill-opacity'] = tonumber(args['fill-opacity'..i] or args['fill-opacity'])
if args['image'..i] then
args['description'..i] = (args['description'..i] or '') .. '[[File:' .. args['image'..i] .. '|300px]]'
i = i + 1
end
mystack[j]['properties']['description'] = args['description'..i]
mystack[j]['properties']['marker-size'] = args['marker-size'..i] or args['marker-size']
mystack[j]['properties']['marker-symbol'] = args['marker-symbol'..i] or args['marker-symbol']
mystack[j]['properties']['marker-color'] = args['marker-color'..i] or args['marker-color']
mystack[j]['properties']['stroke'] = args['stroke'..i] or args['stroke']
mystack[j]['properties']['stroke-opacity'] = tonumber(args['stroke-opacity'..i] or args['stroke-opacity'])
mystack[j]['properties']['stroke-width'] = tonumber(args['stroke-width'..i] or args['stroke-width'])
mystack[j]['properties']['fill'] = args['fill'..i] or args['fill']
mystack[j]['properties']['fill-opacity'] = tonumber(args['fill-opacity'..i] or args['fill-opacity'])
i = i + 1
end
Linha 389 ⟶ 440:
if tagArgs.zoom == nil then
if tagname == "mapframe" then
local uniquepoints = setUniquePoints(allpoints)
if #allpoints == 1 then
if #uniquepoints == 1 then
local currentId = mw.wikibase.getEntityIdForCurrentPage()
local coordInput = allpointsuniquepoints[1][2] .. ',' .. allpointsuniquepoints[1][1]
local mybounds = getBoundsById(currentIdwdid, coordInput) -- try to fetch by area
allpointsuniquepoints = mergePoints(allpointsuniquepoints, mybounds)
end
if #allpointsuniquepoints <= 1 then
tagArgs.zoom = defaultzoom or 9
else
tagArgs.zoom = getZoom(allpointsuniquepoints, tagArgs.height, tagArgs.width)
end
else