Widget:Map Purge

==Map Purges Widget==

Use the following code to invoke:

Currently, all of the data on locations is included in this page, but it's defined in a way that it could be loaded from the data extract.

The page also includes all formatting data.





.leaflet-container { background-color:rgba(255,0,0,0.0); }

// load external data for the map var data; loadJSON(function(response) {		// Parse JSON string into object		data = JSON.parse(response);	});

// focus (if necessary) var focus = ""

// define a standard map marker var MapIcon = L.Icon.extend({	 	options: {			//shadowUrl: 'icons/T_Map_Icon_capital_vanir.png',			iconSize:    [32, 32],			//shadowSize:   [32, 32],			iconAnchor:   [16, 16],			//shadowAnchor: [0, 0],			popupAnchor:  [0, 0]		}	});

// map center and zoom defaults var mapCenter = [38, 65] var mapZoom = 0.5

// Define all of the different icons for the map var iconPurge = new MapIcon({iconUrl: 'https://gamepedia.cursecdn.com/conanexiles_gamepedia/thumb/d/da/T_Map_Icon_Purge.png/24px-T_Map_Icon_Purge.png'});

// Define overlay layers for the different types of locations var overlayPurges = L.layerGroup; var overlayFocus = L.layerGroup;

// Define the map and options for it. var map = L.map('map', {		crs: L.CRS.Simple,		minZoom: 0,		maxZoom: 5,		zoomDelta: 0.25,		zoomSnap: 0.25,		layers: [overlayPurges,overlayFocus]	});

// The map goes from approx x -340, y -445 to x 470, y 370 so define this for the boundaries var bounds = -370,-342], [445,475;

// Provide the full URL to the map image that has been uploaded. May fail if the image is updated by someone. var image = L.imageOverlay('https://gamepedia.cursecdn.com/conanexiles_gamepedia/1/13/T_FullscreenMap.jpg?version=cee7b028a0c48669d0783f655bad8499', bounds).addTo(map); map.fitBounds(bounds);

// Now add the markers to the map. // VERY IMPORTANT - the format for adding the coordinates is different to in Conan. // L.marker([-, ], {icon: }).addTo.bindPopup(' '); // The mapdata entries are in the format [ "Name", X, Y, "Icon"] var purge2AreaMap = new Array;

for (var i in data) { var purge = data[i]; console.log(purge);

// define a new layer per area var overlayPurgeArea if(purge["firstWave"] == focus) {

overlayPurgeArea = overlayFocus; mapCenter = prepareMarker(purge["marker"]) // center the map to the focus area mapZoom = 0 // minimal zoom } else { overlayPurgeArea = L.layerGroup; }		// define rectangle geographical bounds var bounds = prepareBounds(purge["bounds"]); //-purge[2], purge[1, [-purge[4], purge[3]]];

// create an rectangle var rec = L.rectangle(bounds, {color: "#004eff", fillColor: "#58baff", weight: 1, fillOpacity: 0.25, opacity: 1.0}).addTo(overlayPurgeArea)

// prepare popup content var popup = " " + purge["name"] + " " popup += "Difficulty Threshold: " + purge["difficultyMin"] + " to " + purge["difficultyMax"] + " " popup += "Waves: up to " + purge["waveCount"]

var marker = L.marker(prepareMarker(purge["marker"]), {icon: iconPurge}).addTo(overlayPurges).bindPopup(popup)

purge2AreaMap[L.stamp(marker)] = overlayPurgeArea;

marker.on("mouseover", function(event) {			var layer = purge2AreaMap[L.stamp(event.target)];			if(layer != undefined && layer != overlayFocus) {				map.addLayer(layer);			}		}); marker.on("mouseout", function(event) {			var layer = purge2AreaMap[L.stamp(event.target)];			if(layer != undefined && layer != overlayFocus) {				map.removeLayer(layer);			}		}); }

// Define the layers for the map var baseMaps = {}; var overlayMaps = { "Purges": overlayPurges, };

// Add a control for the layers // L.control.layers(baseMaps, overlayMaps,{"sortLayers":true,"collapsed":false}).addTo(map);

// The centre of the map is NOT 0,0 - define the real centre for initial display // setView( center,  zoom,  options?) map.setView( mapCenter, mapZoom);

function prepareBounds(bounds) { // -purge[2], purge[1, [-purge[4], purge[3]]] return -bounds[1], bounds[0, [-bounds[3], bounds[2]]] }

function prepareMarker(marker) { // [-purgeData[i][6], purgeData[i][5]] return [-marker[1], marker[0]] }

// helper function to load github hosted data function loadJSON(callback) { var xobj = new XMLHttpRequest; xobj.overrideMimeType("application/json"); xobj.open('GET', 'https://raw.githubusercontent.com/Juijang/wikidata/master/data_purge1.json', false); xobj.onreadystatechange = function { if (xobj.readyState == 4 && xobj.status == 200) { callback(xobj.responseText); }		};		xobj.send(null); }