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
|
// @id iitc-plugin-portal-names@zaso
|
||||||
// @name IITC plugin: Portal Names
|
// @name IITC plugin: Portal Names
|
||||||
// @category Layer
|
// @category Layer
|
||||||
// @version 0.1.1.@@DATETIMEVERSION@@
|
// @version 0.1.2.@@DATETIMEVERSION@@
|
||||||
// @namespace https://github.com/jonatkins/ingress-intel-total-conversion
|
// @namespace https://github.com/jonatkins/ingress-intel-total-conversion
|
||||||
// @updateURL @@UPDATEURL@@
|
// @updateURL @@UPDATEURL@@
|
||||||
// @downloadURL @@DOWNLOADURL@@
|
// @downloadURL @@DOWNLOADURL@@
|
||||||
@ -21,7 +21,6 @@
|
|||||||
// use own namespace for plugin
|
// use own namespace for plugin
|
||||||
window.plugin.portalNames = function() {};
|
window.plugin.portalNames = function() {};
|
||||||
|
|
||||||
window.plugin.portalNames.MAX_PORTALS = 400;
|
|
||||||
window.plugin.portalNames.NAME_WIDTH = 80;
|
window.plugin.portalNames.NAME_WIDTH = 80;
|
||||||
window.plugin.portalNames.NAME_HEIGHT = 23;
|
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) {
|
// for efficient testing of intersection, group portals into buckets based on the label size
|
||||||
// too manuy VISIBLE portals to handle quickly - clear all
|
var buckets = {};
|
||||||
window.plugin.portalNames.labelLayerGroup.clearLayers();
|
for (var guid in portalPoints) {
|
||||||
window.plugin.portalNames.labelLayers = {};
|
var point = portalPoints[guid];
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
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 = {};
|
var coveredPortals = {};
|
||||||
|
|
||||||
for (var guid in portalPoints) {
|
for (var bucket in buckets) {
|
||||||
var point = portalPoints[guid];
|
var bucketGuids = buckets[bucket];
|
||||||
// the bounds used for testing are twice as wide as the portal name marker. this is so that there's no left/right
|
for (var guid in bucketGuids) {
|
||||||
// overlap between two different portals text
|
var point = portalPoints[guid];
|
||||||
var largeBounds = L.bounds (
|
// the bounds used for testing are twice as wide as the portal name marker. this is so that there's no left/right
|
||||||
point.subtract([window.plugin.portalNames.NAME_WIDTH,0]),
|
// overlap between two different portals text
|
||||||
point.add([window.plugin.portalNames.NAME_WIDTH,window.plugin.portalNames.NAME_HEIGHT])
|
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];
|
for (var otherGuid in bucketGuids) {
|
||||||
|
if (guid != otherGuid) {
|
||||||
if (largeBounds.contains(otherPoint)) {
|
var otherPoint = portalPoints[otherGuid];
|
||||||
// another portal is within the rectangle for this one's name - so no name for this one
|
|
||||||
coveredPortals[guid] = true;
|
if (largeBounds.contains(otherPoint)) {
|
||||||
break;
|
// 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