Widget:Map/JS

function GetMarkerArray(e,a){for(var t=[],r=0;r-1){var o,n=e.childNodes[r],m=$.csv.toArrays(n.dataset.coordinate,{separator:";"});o=sceneid>0?[m[0][3],0,m[0][2]]:[m[0][2],0,m[0][1]];var i=L.marker(GetTransformedCoordinates(a,sceneid,o),{title:n.dataset.name,icon:cursorIcon});i.bindPopup(""+n.dataset.name+"").on("click",i.openPopup.bind(i)),t[t.length]=i}return t}function GetTransformedCoordinates(e,a,t){return a>0?_(this).mapScene(e,a,t):_(this).mapContinent(e,t)}for(var cursorIcon=L.icon({iconUrl:"http://sotawiki.net/images/2/29/Cursor-down.png",iconSize:[46,46],iconAnchor:[23,46],popupAnchor:[0,-30]}),maps=document.getElementsByClassName("sotamap"),i=0;i<maps.length;i++){var mapElem=maps[i],sceneid=0,continentid=1,centerX=150,centerY=150,zoom=1,hidezoom=0,hideattribution=0;mapElem.hasAttribute("data-continentid")&&(continentid=Number(mapElem.dataset.continentid)),mapElem.hasAttribute("data-sceneid")&&(sceneid=Number(mapElem.dataset.sceneid)),mapElem.hasAttribute("data-centerX")&&(centerX=Number(mapElem.dataset.centerx)),mapElem.hasAttribute("data-centerY")&&(centerY=Number(mapElem.dataset.centery)),mapElem.hasAttribute("data-zoom")&&(zoom=Number(mapElem.dataset.zoom)),mapElem.hasAttribute("data-hidezoom")&&(hidezoom=Number(mapElem.dataset.hidezoom)),mapElem.hasAttribute("data-hideattribution")&&(hideattribution=Number(mapElem.dataset.hideattribution));var mapLoc="http://fenyx4.com/sota/map/"+continentid+"/{z}/{x}/{y}.png";0!=sceneid&&(mapLoc="http://fenyx4.com/sota/map/"+continentid+"/scenes/"+sceneid+"/{z}/{x}/{y}.png");var center=GetTransformedCoordinates(continentid,sceneid,[centerY,0,centerX]),map=L.map(mapElem,{crs:L.CRS.Simple,zoom:6,minZoom:1,maxZoom:6,continuousWorld:!0,noWrap:!0,tms:!0,zoomControl:1!=hidezoom}).setView(center,zoom);L.tileLayer(mapLoc,{zoom:6,minZoom:1,maxZoom:6,continuousWorld:!0,noWrap:!0,tms:!0}).addTo(map),1==hideattribution&&map.attributionControl.setPrefix("");var markerArray=GetMarkerArray(mapElem,continentid,sceneid);for(var markerIdx in markerArray)markerArray[markerIdx].addTo(map);for(var baseMaps={},overlayMaps={},layerControl=L.control.layers(baseMaps,overlayMaps),addLayerControl=!1,j=0;j-1){addLayerControl=!0;var gElem=mapElem.childNodes[j],markerArr=GetMarkerArray(gElem,continentid,sceneid),resultLayerGroup=L.layerGroup(markerArr);layerControl.addOverlay(resultLayerGroup,gElem.dataset.name),resultLayerGroup.addTo(map)}addLayerControl&&layerControl.addTo(map)}