Модуль:Mapframe маркер розташування

{{i}} Документація модуля[створити]
local p = {}

function ie(var)
	if(var) then
		if(string.len(var)>0) then return false; else return true; end
	else return true; end
end

function coord(c_dir, c_deg, c_min, c_sec)
	if(c_dir=="S" or c_dir=="W") then c_dir = -1; else c_dir = 1; end
	return c_dir*(c_deg + (c_min/60) + (c_sec/3600))
end

function p.main(frame)
	parent = frame:getParent();
	args = parent.args;

	errormessage = "[[Категорія:Сторінки із некоректними мапами]]";
	templatescat = "[[Категорія:Шаблони, в яких використовується mapframe]]";
	no_p625 = "[[Категорія:Вікідані:P625:відсутня]]";
	if(not ie(args["no_p625"])) then no_p625 = "[["..args["no_p625"].."]]"; end

	if(ie(args["ширина"])) then args["ширина"] = 250; end
	if(ie(args["висота"])) then args["висота"] = 250; end
	if(ie(args["масштаб"])) then args["масштаб"] = 16; end

	if(ie(args["колір"])) then args["колір"] = "00f";
	else args["колір"] = string.sub(args["колір"],-6); end
	if(args["колір"]=="E3E3E3") then args["колір"] = "00f"; end

	if(not ie(args["назва"])) then 
		args["назва"] = string.gsub(args["назва"], '"', """);
		args["назва"] = string.gsub(args["назва"], "'", "'");
	else args["назва"] = ""; end

	if(not ie(args["маркер"])) then 
		args["маркер"] = ', "marker-symbol": "'..args["маркер"]..'"';
	else args["маркер"] = ""; end

	if(ie(args["широта"]) and ie(args["довгота"])) then 
		if(not ie(args["lat_dir"]) and not ie(args["lat_deg"]) and 
		  not ie(args["lat_min"]) and not ie(args["lat_sec"]) and 
		  not ie(args["lon_dir"]) and not ie(args["lon_deg"]) and 
		  not ie(args["lon_min"]) and not ie(args["lon_sec"])) then
			args["широта"] = coord(args["lat_dir"], args["lat_deg"], args["lat_min"], args["lat_sec"]);
			args["довгота"] = coord(args["lon_dir"], args["lon_deg"], args["lon_min"], args["lon_sec"]);
		else
			element = mw.wikibase.getEntityIdForCurrentPage();
			 if(not element) then return errormessage; end
			item = mw.wikibase.getEntity(element);
			 if(not item) then return errormessage; end
			if(item:getBestStatements('P625')[1]) then 
				args["широта"] = item:getBestStatements('P625')[1].mainsnak.datavalue.value.latitude;
				args["довгота"] = item:getBestStatements('P625')[1].mainsnak.datavalue.value.longitude;
			elseif(item:getBestStatements('P159')[1] and 
			  item:getBestStatements('P159')[1].qualifiers and 
			  item:getBestStatements('P159')[1].qualifiers.P625) then
				args["широта"] = item:getBestStatements('P159')[1].qualifiers.P625[1].datavalue.value.latitude;
				args["довгота"] = item:getBestStatements('P159')[1].qualifiers.P625[1].datavalue.value.longitude;
			elseif(string.find(tostring(mw.title.getCurrentTitle()), "Шаблон:")) then 
				return templatescat;
			else return no_p625; end
		end
	end
	
	if(ie(args["префікс"])) then args["префікс"] = ""; end
	if(ie(args["постфікс"])) then args["постфікс"] = ""; end

	res = {args["префікс"], '{{anchor|map-osm}}<mapframe align=center frameless width=', 
		args["ширина"], ' height=', args["висота"], ' zoom=', args["масштаб"], 
		' longitude=', args["довгота"], ' latitude=', args["широта"], 
		'>{"type": "Feature", "properties": {"title": "', args["назва"], 
		'"', args["маркер"], ', "marker-color": "', args["колір"], 
		'"}, "geometry": {"type": "Point", "coordinates": [', 
		args["довгота"], ', ', args["широта"], ']}}</mapframe>', args["постфікс"]};
	return frame:preprocess(table.concat(res));
end

return p;