पटलम्:Location map/info
दिखावट
This module displays values for the map data modules such as Module:Location map/data/Belgium. These templates are used by Module:Location map to obtain values such as the file name and the border coordinates of each location map.
Usage
[सम्पादयतु]This module is automatically used as documentation for map data modules and should not normally be called manually.
The name
parameter
[सम्पादयतु]The {{Location map}} family of templates uses the value assigned to name
to generate alt text. It is used to construct the sentence "label
is located in name
". Assign a value to <name>
that fits in the sentence. For example:
- Chicago is located in the United States. So
|name=the United states
. - Santo Domingo is located in the Dominican Republic. So
|name=the Dominican Republic
.
local p = {}
function p.main(frame)
local map = mw.loadData(string.gsub(mw.title.getCurrentTitle().prefixedText,'/doc$',''))
local retval =
[=[{| class="wikitable" style="text-align:center; margin-top:0;"
|+ Location map of ]=] .. map.name .. '\n' .. [=[
|-
! name
|colspan="3"| [[]=] .. map.name .. [=[]]
|-
]=]
if map.top then
retval = retval ..
[=[!rowspan="4"|border<br/>coordinates
|-
|colspan="3"| ]=] .. map.top .. '\n' .. [=[
|-
|style="width:7em;"| ]=] .. map.left .. '\n' .. [=[
| ←↕→
|style="width:7em;"| ]=] .. map.right
if map.right > 180 then
retval = retval .. ' (' .. map.right - 360 .. ')'
end
retval = retval .. '\n' .. [=[
|-
|colspan="3"| ]=] .. map.bottom .. '\n' .. [=[
|-
! map center
|colspan="4"| ]=]
local right = map.right
-- normalize right to be bigger than map.left by the smallest increment possible
while right - map.left < 0 do
right = right + 360
end
while right - map.left >= 360 do
right = right - 360
end
local center = (map.left + right)/2
-- normalize center to be between -180 and 180
while center < -180 do
center = center + 360
end
while center >= 180 do
center = center - 360
end
retval = retval .. frame:expandTemplate{title = 'coord', args = { (map.top + map.bottom)/2, center }}
retval = retval .. '\n' .. [=[
|-]=]
end
if map.x then
retval = retval .. '\n' .. [=[
! x
|colspan="3" style="overflow: auto; white-space: auto; width: 350px"| ]=] .. map.x .. '\n' .. [=[
|-
! y
|colspan="3" style="overflow: auto; white-space: auto; width: 350px"| ]=] .. map.y .. '\n' .. [=[
|-]=]
end
retval = retval .. '\n' .. [=[
! image
|colspan="3"| <tt>[[:File:]=] .. map.image .. '|' .. map.image .. [=[]]</tt>
|-
|colspan="4"|[[File:]=] .. map.image .. [=[|400x400px]]
|-]=]
if map.image1 then
retval = retval .. '\n' .. [=[
! image1
|colspan="3"| <tt>[[:File:]=] .. map.image1 .. '|' .. map.image1 .. [=[]]</tt>
|-
|colspan="4"|[[File:]=] .. map.image1 .. [=[|400x400px]]
|-]=]
end
if map.image2 then
retval = retval .. '\n' .. [=[
! image2
|colspan="3"| <tt>[[:File:]=] .. map.image2 .. '|' .. map.image2 .. [=[]]</tt>
|-
|colspan="4"|[[File:]=] .. map.image2 .. [=[|400x400px]]
|-]=]
end
if map.skew then
retval = retval .. '\n' .. [=[
! skew
|colspan="3"| ]=] .. map.skew .. '\n' .. [=[
|-]=]
end
if map.lat_skew then
retval = retval .. '\n' .. [=[
! lat_skew
|colspan="3"| ]=] .. map.lat_skew .. '\n' .. [=[
|-]=]
end
if map.mark then
retval = retval .. '\n' .. [=[
! mark
|colspan="3"| <tt>[[:File:]=] .. map.mark .. '|' .. map.mark .. [=[]]</tt>
|-]=]
end
if map.marksize then
retval = retval .. '\n' .. [=[
! marksize
|colspan="3"| ]=] .. map.marksize .. '\n' .. [=[
|-]=]
end
retval = retval .. '\n|}'
return retval
end
function p.moduloMathDetails(frame)
local args = require('Module:Arguments').getArgs(frame)
local top, bottom, left, right = args.top or 0, args.bottom or 100, args.left or 0, args.right or 100
local map = mw.loadData(string.gsub(mw.title.getCurrentTitle().prefixedText,'/doc$',''))
local retval = [=[For a map using an [[equirectangular projection]] which does not cross +/-180 longitude, or +/-90 latitude, the following expressions can be used:
<code>x = 100*(''long'' - ''left'')/(''right'' - ''left'')</code><br />
<code>y = 100*(''lat'' - ''top'')/(''bottom'' - ''top'')</code>
where ''lat'' and ''long'' are the degrees latitude and longitude respectively. Here, ''top'' and ''bottom'' are the degrees latitude of the top and bottom edges of the map, ''left'' and ''right'' are the degrees latitude of the left and right edges of the map.
Things are a bit more complicated when the map crosses +/-180 longitude, and some sort of "modulo arithmetic" is required. Here, we add 360 if the longitude is less than 0, then use a mapping based on positive coordinates. The following table can be used to check if the expressions are working as desired:
{| class="wikitable"
! location !! lat !! long !! (x,y) test !! (x,y) exact
|-
| top/left || ]=] .. top .. ' ||' .. left .. '|| '
retval = retval .. '(' .. frame:callParserFunction('#expr', mw.message.newRawMessage(map.x, top, left):plain() .. ' round 1') .. ',' .. frame:callParserFunction('#expr', mw.message.newRawMessage(map.y, top, left):plain() .. ' round 1') .. ')'
retval = retval .. [=[ || (0,0)
|-
| top/right || ]=] .. top .. ' ||' .. right .. '|| '
retval = retval .. '(' .. frame:callParserFunction('#expr', mw.message.newRawMessage(map.x, top, right):plain() .. ' round 1') .. ',' .. frame:callParserFunction('#expr', mw.message.newRawMessage(map.y, top, right):plain() .. ' round 1') .. ')'
retval = retval .. [=[ || (100,0)
|-
| bottom/left || ]=] .. bottom .. ' ||' .. left .. '|| '
retval = retval .. '(' .. frame:callParserFunction('#expr', mw.message.newRawMessage(map.x, bottom, left):plain() .. ' round 1') .. ',' .. frame:callParserFunction('#expr', mw.message.newRawMessage(map.y, bottom, left):plain() .. ' round 1') .. ')'
retval = retval .. [=[ || (0,100)
|-
| bottom/right || ]=] .. bottom .. ' ||' .. right .. '|| '
retval = retval .. '(' .. frame:callParserFunction('#expr', mw.message.newRawMessage(map.x, bottom, right):plain() .. ' round 1') .. ',' .. frame:callParserFunction('#expr', mw.message.newRawMessage(map.y, bottom, right):plain() .. ' round 1') .. ')'
retval = retval .. [=[ || (100,100)
|-
| center || ]=]
retval = retval .. (top + bottom)/2 .. ' ||' .. (left + right + ((right < left) and 360 or 0))/2 .. '|| '
retval = retval .. '(' .. frame:callParserFunction('#expr', mw.message.newRawMessage(map.x, (top + bottom)/2, (left + right + ((right < left) and 360 or 0))/2):plain() .. ' round 1') .. ',' .. frame:callParserFunction('#expr', mw.message.newRawMessage(map.y, (top + bottom)/2, (left + right + ((right < left) and 360 or 0))/2):plain() .. ' round 1') .. ')'
retval = retval .. [=[ || (50,50)
|}]=]
return retval
end
return p