Module:ExportMapToCargo
Jump to navigation
Jump to search
Documentation for this module may be created at Module:ExportMapToCargo/doc
--assumes marker.id only has 1 "." (if any) and only at the end to concatenate 1 or more characters to make id unique.
local p = {}
local mID = ""
local underScore = 0
local periodSeperator = 0
local lt = ""
local regionText = ''
local regionAssociation = ''
function p.export( f )
local data = mw.text.jsonDecode( mw.title.new( f.args._map ):getContent() )
for associations, markers in pairs( data.markers ) do
local group = associations:match("[^ ]+")
for _, marker in ipairs( markers ) do
underScore = nil
-- extract region value from associations text
regionAssociation = associations:match("region:[^ ]+")
if regionAssociation == nil
then
regionText = ''
else
regionText = string.sub(regionAssociation,8)
end
-- marker without id will use x,y coordinates in url
if marker.id == nil
then
mID = ""
f:callParserFunction{
name = '#cargo_store',
args = {
'_table=' .. f.args._table,
Map = f.args._map,
MarkerGroup = group,
Region = regionText,
Id = marker.id,
Name = marker.name,
X = marker.x,
Y = marker.y,
JoinKey= mID,
Icon = marker.icon,
-- LinkText = "[{{fullurl:"..f.args._map.."|marker="..group.."@"..string.format("%.3f",marker.y)..":"..string.format("%.3f",marker.x).."}} "..marker.name.."@"..f.args._map.."]"
LinkText = "[{{fullurl:"..f.args._map.."|marker="..group.."@"..string.format("%.3f",marker.y)..":"..string.format("%.3f",marker.x).."}} "..marker.name.."]"
-- Tooltip syntax: [[Link destination|<span title="tooltip text goes here">Link text</span>]]
}
}
else
mID = marker.id
underScore = string.find(marker.id,'_',1) or 0
periodSeperator = string.find(marker.id,'%.',1) or 0
-- strip out seperator and following text if any
if (periodSeperator ~= 0)
then
mID=string.sub(marker.id,1,periodSeperator-1)
end
-- replace any underscores with spaces
if (underScore == nil) --(underScore > 0) and
then
else
-- mID = underScore
mID=string.gsub(mID,'_',' ')
end
f:callParserFunction{
name = '#cargo_store',
args = {
'_table=' .. f.args._table,
Map = f.args._map,
MarkerGroup = group,
Region = regionText,
Id = marker.id,
Name = marker.name,
X = marker.x,
Y = marker.y,
JoinKey = mID,
Icon=marker.icon,
LinkText = "[{{fullurl:"..f.args._map.."|marker="..marker.id.."}} "..regionText.."]"
}
}
end
end
end
end
return p