Merge branch 'master' of github.com:jonatkins/ingress-intel-total-conversion

This commit is contained in:
Philipp Schaefer 2013-10-13 11:12:09 +02:00
commit 1535cd5c57

View File

@ -2,7 +2,7 @@
// @id iitc-plugin-portal-names@zaso
// @name IITC plugin: Portal Names
// @category Layer
// @version 0.1.1.@@DATETIMEVERSION@@
// @version 0.1.2.@@DATETIMEVERSION@@
// @namespace https://github.com/jonatkins/ingress-intel-total-conversion
// @updateURL @@UPDATEURL@@
// @downloadURL @@DOWNLOADURL@@
@ -21,7 +21,6 @@
// use own namespace for plugin
window.plugin.portalNames = function() {};
window.plugin.portalNames.MAX_PORTALS = 400;
window.plugin.portalNames.NAME_WIDTH = 80;
window.plugin.portalNames.NAME_HEIGHT = 23;
@ -93,17 +92,27 @@ window.plugin.portalNames.updatePortalLabels = function() {
}
}
if (Object.keys(portalPoints).length > window.plugin.portalNames.MAX_PORTALS) {
// too manuy VISIBLE portals to handle quickly - clear all
window.plugin.portalNames.labelLayerGroup.clearLayers();
window.plugin.portalNames.labelLayers = {};
return;
}
// for efficient testing of intersection, group portals into buckets based on the label size
var buckets = {};
for (var guid in portalPoints) {
var point = portalPoints[guid];
var bucketId = L.point([Math.floor(point.x/(window.plugin.portalNames.NAME_WIDTH*2)),Math.floor(point.y/window.plugin.portalNames.NAME_HEIGHT)]);
// the guid is added to four buckets. this way, when testing for overlap we don't need to test
// all 8 buckets surrounding the one around the particular portal, only the bucket it is in itself
var bucketIds = [bucketId, bucketId.add([1,0]), bucketId.add([0,1]), bucketId.add([1,1])];
for (var i in bucketIds) {
var b = bucketIds[i].toString();
if (!buckets[b]) buckets[b] = {};
buckets[b][guid] = true;
}
}
var coveredPortals = {};
for (var guid in portalPoints) {
for (var bucket in buckets) {
var bucketGuids = buckets[bucket];
for (var guid in bucketGuids) {
var point = portalPoints[guid];
// the bounds used for testing are twice as wide as the portal name marker. this is so that there's no left/right
// overlap between two different portals text
@ -112,7 +121,7 @@ window.plugin.portalNames.updatePortalLabels = function() {
point.add([window.plugin.portalNames.NAME_WIDTH,window.plugin.portalNames.NAME_HEIGHT])
);
for (var otherGuid in portalPoints) {
for (var otherGuid in bucketGuids) {
if (guid != otherGuid) {
var otherPoint = portalPoints[otherGuid];
@ -124,6 +133,7 @@ window.plugin.portalNames.updatePortalLabels = function() {
}
}
}
}
for (var guid in coveredPortals) {
delete portalPoints[guid];