added a renderlimit for the plugin
This commit is contained in:
parent
df40a182be
commit
a94bf4475b
@ -43,13 +43,16 @@
|
|||||||
// redrawn. It is called early on in the
|
// redrawn. It is called early on in the
|
||||||
// code/map_data.js#renderPortal as long as there was an
|
// code/map_data.js#renderPortal as long as there was an
|
||||||
// old portal for the guid.
|
// old portal for the guid.
|
||||||
|
// checkRenderLimit: callback is passed the argument of
|
||||||
|
// {reached : false} to indicate that the renderlimit is reached
|
||||||
|
// set reached to true.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
window._hooks = {}
|
window._hooks = {}
|
||||||
window.VALID_HOOKS = ['portalAdded', 'portalDetailsUpdated',
|
window.VALID_HOOKS = ['portalAdded', 'portalDetailsUpdated',
|
||||||
'publicChatDataAvailable', 'portalDataLoaded', 'beforePortalReRender'];
|
'publicChatDataAvailable', 'portalDataLoaded', 'beforePortalReRender',
|
||||||
|
'checkRenderLimit'];
|
||||||
|
|
||||||
window.runHooks = function(event, data) {
|
window.runHooks = function(event, data) {
|
||||||
if(VALID_HOOKS.indexOf(event) === -1) throw('Unknown event type: ' + event);
|
if(VALID_HOOKS.indexOf(event) === -1) throw('Unknown event type: ' + event);
|
||||||
|
@ -128,7 +128,9 @@ window.renderLimitReached = function() {
|
|||||||
if(Object.keys(portals).length >= MAX_DRAWN_PORTALS) return true;
|
if(Object.keys(portals).length >= MAX_DRAWN_PORTALS) return true;
|
||||||
if(Object.keys(links).length >= MAX_DRAWN_LINKS) return true;
|
if(Object.keys(links).length >= MAX_DRAWN_LINKS) return true;
|
||||||
if(Object.keys(fields).length >= MAX_DRAWN_FIELDS) return true;
|
if(Object.keys(fields).length >= MAX_DRAWN_FIELDS) return true;
|
||||||
return false;
|
var param = { 'reached': false };
|
||||||
|
window.runHooks('checkRenderLimit', param);
|
||||||
|
return param.reached;
|
||||||
}
|
}
|
||||||
|
|
||||||
window.getMinPortalLevel = function() {
|
window.getMinPortalLevel = function() {
|
||||||
|
@ -20,9 +20,10 @@ function wrapper() {
|
|||||||
|
|
||||||
// use own namespace for plugin
|
// use own namespace for plugin
|
||||||
window.plugin.maxLinks = function() {};
|
window.plugin.maxLinks = function() {};
|
||||||
|
|
||||||
|
window.plugin.maxLinks.MAX_DRAWN_LINKS = 400;
|
||||||
var MAX_LINK_COLOR = '#FF0000';
|
var MAX_LINK_COLOR = '#FF0000';
|
||||||
|
|
||||||
var Triangle = function (a, b, c) {
|
var Triangle = function (a, b, c) {
|
||||||
this.a = a;
|
this.a = a;
|
||||||
this.b = b;
|
this.b = b;
|
||||||
@ -203,7 +204,8 @@ function wrapper() {
|
|||||||
|
|
||||||
window.plugin.maxLinks.layer = null;
|
window.plugin.maxLinks.layer = null;
|
||||||
|
|
||||||
var updating = false;
|
var updating = false;
|
||||||
|
var renderLimitReached = false;
|
||||||
window.plugin.maxLinks.updateLayer = function() {
|
window.plugin.maxLinks.updateLayer = function() {
|
||||||
if (updating || window.plugin.maxLinks.layer === null || !window.map.hasLayer(window.plugin.maxLinks.layer))
|
if (updating || window.plugin.maxLinks.layer === null || !window.map.hasLayer(window.plugin.maxLinks.layer))
|
||||||
return;
|
return;
|
||||||
@ -230,14 +232,28 @@ function wrapper() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
var triangles = window.plugin.maxLinks.triangulate(locations);
|
var triangles = window.plugin.maxLinks.triangulate(locations);
|
||||||
|
var drawnLinks = 0;
|
||||||
|
renderLimitReached = false;
|
||||||
$.each(triangles, function(idx, triangle) {
|
$.each(triangles, function(idx, triangle) {
|
||||||
triangle.draw(window.plugin.maxLinks.layer, minX, minY)
|
if (drawnLinks <= window.plugin.maxLinks.MAX_DRAWN_LINKS) {
|
||||||
|
triangle.draw(window.plugin.maxLinks.layer, minX, minY);
|
||||||
|
drawnLinks += 3;
|
||||||
|
} else {
|
||||||
|
renderLimitReached = true;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
updating = false;
|
updating = false;
|
||||||
|
window.renderUpdateStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
var setup = function() {
|
var setup = function() {
|
||||||
window.plugin.maxLinks.layer = L.layerGroup([]);
|
window.plugin.maxLinks.layer = L.layerGroup([]);
|
||||||
|
|
||||||
|
window.addHook('checkRenderLimit', function(e) {
|
||||||
|
if (window.map.hasLayer(window.plugin.maxLinks.layer) && renderLimitReached)
|
||||||
|
e.reached = true;
|
||||||
|
});
|
||||||
|
|
||||||
window.map.on('layeradd', function(e) {
|
window.map.on('layeradd', function(e) {
|
||||||
if (e.layer === window.plugin.maxLinks.layer)
|
if (e.layer === window.plugin.maxLinks.layer)
|
||||||
window.plugin.maxLinks.updateLayer();
|
window.plugin.maxLinks.updateLayer();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user