Code restructure

This commit is contained in:
Xelio
2013-02-16 01:16:20 +08:00
parent 1ed2ee8e8c
commit eab812fbf6
3 changed files with 25 additions and 40 deletions

View File

@ -339,26 +339,25 @@ window.renderResonators = function(ent, portalLayer) {
var resoGuid = portalResonatorGuid(ent[0], i);
// the resonator
var reso = L.circleMarker(Rlatlng, {
radius: ent[0] == selectedPortal ? RADIUS_SELECTED_PORTAL_RESONATOR: RADIUS_NON_SELECTED_PORTAL_RESONATOR,
// #AAAAAA outline seems easier to see the fill opacity
color: ent[0] == selectedPortal ? COLOR_SELECTED_PORTAL_RESONATOR : COLOR_NON_SELECTED_PORTAL_RESONATOR,
var resoProperty = $.extend({
opacity: 1,
weight: ent[0] == selectedPortal ? WEIGHT_SELECTED_PORTAL_RESONATOR : WEIGHT_NON_SELECTED_PORTAL_RESONATOR,
fillColor: COLORS_LVL[rdata.level],
fillOpacity: rdata.energyTotal/RESO_NRG[rdata.level],
clickable: false,
guid: resoGuid // need this here as well for add/remove events
});
guid: resoGuid
}, ent[0] == selectedPortal ? OPTIONS_RESONATOR_SELECTED : OPTIONS_RESONATOR_NON_SELECTED);
var reso = L.circleMarker(Rlatlng, resoProperty);
// line connecting reso to portal
var conn = L.polyline([portalLatLng, Rlatlng], {
weight: ent[0] == selectedPortal ? WEIGHT_SELECTED_PORTAL_RESONATOR_LINE : WEIGHT_NON_SELECTED_PORTAL_RESONATOR_LINE,
var connProperty = $.extend({
color: '#FFA000',
opacity: ent[0] == selectedPortal ? OPACITY_SELECTED_PORTAL_RESONATOR_LINE : OPACITY_NON_SELECTED_PORTAL_RESONATOR_LINE,
dashArray: '0,10,8,4,8,4,8,4,8,4,8,4,8,4,8,4,8,4,8,4',
fill: false,
clickable: false});
clickable: false
}, ent[0] == selectedPortal ? OPTIONS_RESONATOR_LINE_SELECTED : OPTIONS_RESONATOR_LINE_NON_SELECTED);
var conn = L.polyline([portalLatLng, Rlatlng], connProperty);
// put both in one group, so they can be handled by the same logic.
@ -413,16 +412,14 @@ window.portalResetColor = function(portal) {
window.resonatorsResetStyle = function(portalGuid) {
for(var i = 0; i < 8; i++) {
resonatorLayerGroup = resonators[portalResonatorGuid(portalGuid, i)];
//console.log('reset:'+i+','+resonatorLayerGroup);
if(!resonatorLayerGroup) continue;
resonatorLayerGroup.eachLayer(function(layer) {
if (layer.options.guid) {
layer.setStyle({color: COLOR_NON_SELECTED_PORTAL_RESONATOR,
radius: RADIUS_NON_SELECTED_PORTAL_RESONATOR,
weight: WEIGHT_NON_SELECTED_PORTAL_RESONATOR});
// Resonator
layer.setStyle(OPTIONS_RESONATOR_NON_SELECTED);
} else {
layer.setStyle({opacity: OPACITY_NON_SELECTED_PORTAL_RESONATOR_LINE,
weight: WEIGHT_NON_SELECTED_PORTAL_RESONATOR_LINE});
// Resonator line
layer.setStyle(OPTIONS_RESONATOR_LINE_NON_SELECTED);
}
});
}
@ -434,12 +431,11 @@ window.resonatorsSetSelectStyle = function(portalGuid) {
if(!resonatorLayerGroup) continue;
resonatorLayerGroup.eachLayer(function(layer) {
if (layer.options.guid) {
layer.bringToFront().setStyle({color: COLOR_SELECTED_PORTAL_RESONATOR,
radius: RADIUS_SELECTED_PORTAL_RESONATOR,
weight: WEIGHT_SELECTED_PORTAL_RESONATOR});
// Resonator
layer.bringToFront().setStyle(OPTIONS_RESONATOR_SELECTED);
} else {
layer.bringToFront().setStyle({opacity: OPACITY_SELECTED_PORTAL_RESONATOR_LINE,
weight: WEIGHT_SELECTED_PORTAL_RESONATOR_LINE});
// Resonator line
layer.bringToFront().setStyle(OPTIONS_RESONATOR_LINE_SELECTED);
}
});
}

View File

@ -109,10 +109,7 @@ window.setPortalIndicators = function(d) {
window.selectPortal = function(guid) {
var update = selectedPortal === guid;
var oldPortal = portals[selectedPortal];
if(!update && oldPortal) {
resonatorsResetStyle(oldPortal.options.guid);
portalResetColor(oldPortal);
}
if(!update && oldPortal) portalResetColor(oldPortal);
selectedPortal = guid;
@ -127,10 +124,7 @@ window.selectPortal = function(guid) {
window.unselectOldPortal = function() {
var oldPortal = portals[selectedPortal];
if(oldPortal) {
resonatorsResetStyle(oldPortal.options.guid);
oldPortal.setStyle({color: oldPortal.options.fillColor});
}
if(oldPortal) portalResetColor(oldPortal);
selectedPortal = null;
$('#portaldetails').html('');
}