This is a wiki for a reason. Anyone can contribute. If you see something that is inaccurate or can be improved, don't ask that it be fixed--just improve it.
[ Disclaimer, Create new user --- Wiki markup help, Install P99 ]

Difference between revisions of "MediaWiki:LocMaps.js"

From Project 1999 Wiki
Jump to: navigation, search
(Created page with " (function() { var zones = { 'Eastern Wastes': { height: 452, image: 'Map_eastern_wastes.jpg', modifier: -.0380, test: {...")
 
Line 1: Line 1:
    (function() {
+
(function() {
  
    var zones = {
+
var zones = {
      'Eastern Wastes': {
+
  'Eastern Wastes': {
          height: 452,
+
      height: 452,
          image: 'Map_eastern_wastes.jpg',  
+
      image: 'Map_eastern_wastes.jpg',  
          modifier: -.0380,
+
      modifier: -.0380,
          test: {
+
      test: {
            maxX: 7000,
+
        maxX: 7000,
            maxY: 1000,
+
        maxY: 1000,
            minX: -6000,
+
        minX: -6000,
            minY: -9000
+
        minY: -9000
          },
+
      },
          width: 550,
+
      width: 550,
          zeroX: 284,
+
      zeroX: 284,
          zeroY: 62
+
      zeroY: 62
      }
+
  }
    };
+
};
  
  
    var makeX = function(x, y, zone) {
+
var makeX = function(x, y, zone) {
      $('img[alt="' + zone.image + '"]')
+
  $('img[alt="' + zone.image + '"]')
        .parent()
+
    .parent()
        .css({position: 'absolute'})
+
    .css({position: 'absolute'})
        .append(
+
    .append(
          $('<div class="x">x</div>')
+
      $('<div class="x">x</div>')
            .css({
+
        .css({
              color: 'red',
+
          color: 'red',
              fontSize: '2em',
+
          fontSize: '2em',
              fontWeight: 'bold',
+
          fontWeight: 'bold',
              left: zone.zeroX + x * zone.modifier,
+
          left: zone.zeroX + x * zone.modifier,
              position: 'absolute',
+
          position: 'absolute',
              top: zone.zeroY + y * zone.modifier
+
          top: zone.zeroY + y * zone.modifier
            }));
+
        }));
    };
+
};
  
    var testMakeX = function(zone) {
+
var testMakeX = function(zone) {
      for (var x = zone.test.maxX; x >= zone.test.minX; x -= 1000) {
+
  for (var x = zone.test.maxX; x >= zone.test.minX; x -= 1000) {
        for (var y = zone.test.maxY; y >= zone.test.minY; y -= 1000) {
+
    for (var y = zone.test.maxY; y >= zone.test.minY; y -= 1000) {
          makeX(x, y, zone);
+
      makeX(x, y, zone);
        }
+
      };
+
 
     }
 
     }
 +
  };
 +
}
  
  
    var addMap = function($locTd, imageName, width, height) {
+
var addMap = function($locTd, imageName, width, height) {
      if ($('.map-wrapper').length) return;
+
  if ($('.map-wrapper').length) return;
  
      $locTd.append(
+
  $locTd.append(
        '<div class="map-wrapper" style="position:relative">'+
+
    '<div class="map-wrapper" style="position:relative">'+
          '<img alt="' + imageName + '" ' +
+
      '<img alt="' + imageName + '" ' +
              'src="/images/'+ imageName + '" ' +
+
          'src="/images/'+ imageName + '" ' +
              'width="' + width + '" ' +
+
          'width="' + width + '" ' +
              'height="'+ height + '" ' +
+
          'height="'+ height + '" ' +
              'class="thumbborder" ' +
+
          'class="thumbborder" ' +
              'title="' + imageName + '">' +
+
          'title="' + imageName + '">' +
        '</div>'
+
    '</div>'
      );
+
  );
    }
+
}
  
    var showLocOnMap = function($locTd, zone, x, y) {
+
var showLocOnMap = function($locTd, zone, x, y) {
      addMap($locTd, zone.image, zone.width, zone.height);
+
  addMap($locTd, zone.image, zone.width, zone.height);
      makeX(x, y, zone);
+
  makeX(x, y, zone);
      // uncomment this to produce a series of x's for checking the alignment
+
  // uncomment this to produce a series of x's for checking the alignment
      //testMakeX(zone)
+
  //testMakeX(zone)
    };
+
};
  
    try {
+
try {
      var $locTd = $('b:contains("Location:")').parent();
+
  var $locTd = $('b:contains("Location:")').parent();
      var match = $locTd.text().match(/\( *(\-?\d+), *(\-?\d+)\)/);
+
  var match = $locTd.text().match(/\( *(\-?\d+), *(\-?\d+)\)/);
      var y = match[1]
+
  var y = match[1]
      var x = match[2];
+
  var x = match[2];
      var $zoneTd = $('b:contains("Zone:")').parent().text();
+
  var $zoneTd = $('b:contains("Zone:")').parent().text();
      var zoneName = $zoneTd.split('Zone:')[1].trim();
+
  var zoneName = $zoneTd.split('Zone:')[1].trim();
      var zone = zones[zoneName];
+
  var zone = zones[zoneName];
      if (!zone) return;
+
  if (!zone) return;
  
      var $link = $(' <a href="#">(Show on Map)</a>');
+
  var $link = $(' <a href="#">(Show on Map)</a>');
      $link
+
  $link
        .on('mouseover', function(e) {
+
    .on('mouseover', function(e) {
          showLocOnMap($locTd, zone, x, y);
+
      showLocOnMap($locTd, zone, x, y);
        })
+
    })
        .on('mouseleave', function(e) {
+
    .on('mouseleave', function(e) {
          $('.map-wrapper').remove();
+
      $('.map-wrapper').remove();
        });
+
    });
      $locTd.append($link)  
+
  $locTd.append($link)  
    } catch (err) {/* Didn't work, move on */}
+
} catch (err) {/* Didn't work, move on */}
  
  
    })();
+
})();

Revision as of 01:53, 5 July 2019

(function() {

var zones = {
  'Eastern Wastes': {
      height: 452,
      image: 'Map_eastern_wastes.jpg', 
      modifier: -.0380,
      test: {
        maxX: 7000,
        maxY: 1000,
        minX: -6000,
        minY: -9000
      },
      width: 550,
      zeroX: 284,
      zeroY: 62
  }
};


var makeX = function(x, y, zone) {
  $('img[alt="' + zone.image + '"]')
    .parent()
    .css({position: 'absolute'})
    .append(
      $('<div class="x">x</div>')
        .css({
          color: 'red',
          fontSize: '2em',
          fontWeight: 'bold',
          left: zone.zeroX + x * zone.modifier,
          position: 'absolute',
          top: zone.zeroY + y * zone.modifier
        }));
};

var testMakeX = function(zone) {
  for (var x = zone.test.maxX; x >= zone.test.minX; x -= 1000) {
    for (var y = zone.test.maxY; y >= zone.test.minY; y -= 1000) {
      makeX(x, y, zone);
    }
  };
}


var addMap = function($locTd, imageName, width, height) {
  if ($('.map-wrapper').length) return;

  $locTd.append(
    '<div class="map-wrapper" style="position:relative">'+
      '<img alt="' + imageName + '" ' +
           'src="/images/'+ imageName + '" ' +
           'width="' + width + '" ' +
           'height="'+ height + '" ' +
           'class="thumbborder" ' +
           'title="' + imageName + '">' +
    '</div>'
  );
}

var showLocOnMap = function($locTd, zone, x, y) {
  addMap($locTd, zone.image, zone.width, zone.height);
  makeX(x, y, zone);
  // uncomment this to produce a series of x's for checking the alignment
  //testMakeX(zone)
};

try {
  var $locTd = $('b:contains("Location:")').parent();
  var match = $locTd.text().match(/\( *(\-?\d+), *(\-?\d+)\)/);
  var y = match[1]
  var x = match[2];
  var $zoneTd = $('b:contains("Zone:")').parent().text();
  var zoneName = $zoneTd.split('Zone:')[1].trim();
  var zone = zones[zoneName];
  if (!zone) return;

  var $link = $(' <a href="#">(Show on Map)</a>');
  $link
    .on('mouseover', function(e) {
      showLocOnMap($locTd, zone, x, y);
    })
    .on('mouseleave', function(e) {
      $('.map-wrapper').remove();
    });
  $locTd.append($link) 
} catch (err) {/* Didn't work, move on */}


})();