Merge branch 'master' of github.com:jonatkins/ingress-intel-total-conversion
This commit is contained in:
commit
1535cd5c57
@ -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,33 +92,44 @@ 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) {
|
||||
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
|
||||
var largeBounds = L.bounds (
|
||||
point.subtract([window.plugin.portalNames.NAME_WIDTH,0]),
|
||||
point.add([window.plugin.portalNames.NAME_WIDTH,window.plugin.portalNames.NAME_HEIGHT])
|
||||
);
|
||||
|
||||
for (var otherGuid in portalPoints) {
|
||||
if (guid != otherGuid) {
|
||||
var otherPoint = portalPoints[otherGuid];
|
||||
|
||||
if (largeBounds.contains(otherPoint)) {
|
||||
// another portal is within the rectangle for this one's name - so no name for this one
|
||||
coveredPortals[guid] = true;
|
||||
break;
|
||||
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
|
||||
var largeBounds = L.bounds (
|
||||
point.subtract([window.plugin.portalNames.NAME_WIDTH,0]),
|
||||
point.add([window.plugin.portalNames.NAME_WIDTH,window.plugin.portalNames.NAME_HEIGHT])
|
||||
);
|
||||
|
||||
for (var otherGuid in bucketGuids) {
|
||||
if (guid != otherGuid) {
|
||||
var otherPoint = portalPoints[otherGuid];
|
||||
|
||||
if (largeBounds.contains(otherPoint)) {
|
||||
// another portal is within the rectangle for this one's name - so no name for this one
|
||||
coveredPortals[guid] = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user