portal-names plugin:

- use RequestFinished hook to update names while loading
- use map.project to get coordinates - this is floating point, so less likely to have two portals with different horizontal but identical vertical position which causes neither to show a name
This commit is contained in:
Jon Atkins 2013-10-09 05:30:09 +01:00
parent d2661874c6
commit 3c8c03e9e5

View File

@ -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.0.@@DATETIMEVERSION@@ // @version 0.1.1.@@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,7 @@
// use own namespace for plugin // use own namespace for plugin
window.plugin.portalNames = function() {}; window.plugin.portalNames = function() {};
window.plugin.portalNames.MAX_PORTALS = 250; 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;
@ -88,7 +88,7 @@ window.plugin.portalNames.updatePortalLabels = function() {
for (var guid in window.portals) { for (var guid in window.portals) {
var p = window.portals[guid]; var p = window.portals[guid];
if (p._map) { // only consider portals added to the map if (p._map) { // only consider portals added to the map
var point = map.latLngToLayerPoint(p.getLatLng()); var point = map.project(p.getLatLng());
portalPoints[guid] = point; portalPoints[guid] = point;
} }
} }
@ -150,6 +150,7 @@ var setup = function() {
window.plugin.portalNames.labelLayerGroup = new L.LayerGroup(); window.plugin.portalNames.labelLayerGroup = new L.LayerGroup();
window.addLayerGroup('Portal Names', window.plugin.portalNames.labelLayerGroup, true); window.addLayerGroup('Portal Names', window.plugin.portalNames.labelLayerGroup, true);
window.addHook('requestFinished', window.plugin.portalNames.updatePortalLabels);
window.addHook('mapDataRefreshEnd', window.plugin.portalNames.updatePortalLabels); window.addHook('mapDataRefreshEnd', window.plugin.portalNames.updatePortalLabels);
window.map.on('overlayadd overlayremove', window.plugin.portalNames.updatePortalLabels); window.map.on('overlayadd overlayremove', window.plugin.portalNames.updatePortalLabels);
} }