Skip to content

Commit

Permalink
Small bugfixes for classification
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin authored and Martin committed Nov 12, 2012
1 parent 4ba6a50 commit 88f3351
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 24 deletions.
1 change: 0 additions & 1 deletion generateColorRamp.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ function generateColor(theColorBegin, theColorEnd, theNumSteps) {
theB = interpolate(theB0, theB1, i, theNumSteps);
theVal = (((theR << 8) | theG) << 8) | theB;
colorArray[i] = theVal.toString(16);
console.log(theVal.toString(16));
}
return colorArray;
}
31 changes: 31 additions & 0 deletions generateColorRamp.js~
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
function interpolate(pBegin, pEnd, pStep, pMax) {
if (pBegin < pEnd) {
return ((pEnd - pBegin) * (pStep / pMax)) + pBegin;
} else {
return ((pBegin - pEnd) * (1 - (pStep / pMax))) + pEnd;
}

}

function generateColor(theColorBegin, theColorEnd, theNumSteps) {
var colorArray = new Array();
theColorBegin = parseInt(theColorBegin, 16);
theColorEnd = parseInt(theColorEnd, 16);

theR0 = (theColorBegin & 0xff0000) >> 16;
theG0 = (theColorBegin & 0x00ff00) >> 8;
theB0 = (theColorBegin & 0x0000ff) >> 0;
theR1 = (theColorEnd & 0xff0000) >> 16;
theG1 = (theColorEnd & 0x00ff00) >> 8;
theB1 = (theColorEnd & 0x0000ff) >> 0;

for (i = 0; i <= theNumSteps; i++) {
theR = interpolate(theR0, theR1, i, theNumSteps);
theG = interpolate(theG0, theG1, i, theNumSteps);
theB = interpolate(theB0, theB1, i, theNumSteps);
theVal = (((theR << 8) | theG) << 8) | theB;
colorArray[i] = theVal.toString(16);
console.log(theVal.toString(16));
}
return colorArray;
}
23 changes: 4 additions & 19 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,22 +282,7 @@ function colorChange(count) {
* This method is used to initially set classes - only used at startup!
*/
function initialColorization(){
symbol = new esri.symbol.SimpleFillSymbol();
symbol.setColor(new dojo.Color([150, 150, 150, 0.75]));
var renderer = new esri.renderer.ClassBreaksRenderer(symbol, attributeFields[activeLayer]);

//the values are layer dependent, so if another initial layer is chosen, these values MUST be changed
renderer.addBreak(0,1702,new esri.symbol.SimpleFillSymbol().setColor(new dojo.Color("#FF0000")));

renderer.addBreak(1703,3404,new esri.symbol.SimpleFillSymbol().setColor(new dojo.Color("#FFFF00")));

renderer.addBreak(3405,5107,new esri.symbol.SimpleFillSymbol().setColor(new dojo.Color("#00FF00")));

featureLayer.setRenderer(renderer);
featureLayer.refresh();

legend.refresh();

addEqualBreaks(3, "FF0000", "00FF00");
}

/**
Expand Down Expand Up @@ -357,9 +342,9 @@ function layerChange(layerNr) {
* method for automatic (equal) breaks
*/
function addEqualBreaks(number, colorStart, colorEnd) {

var breakStep = (maxValues[activeLayer] - minValues[activeLayer]) / (number + 1);
var colorArray = generateColor(colorStart, colorEnd, number);
var breakStep = (maxValues[activeLayer] - minValues[activeLayer]) / (number);
var colorArray = generateColor(colorStart, colorEnd, number-1);
colorArray.reverse();

symbol = new esri.symbol.SimpleFillSymbol();
symbol.setColor(new dojo.Color([150, 150, 150, 0.75]));
Expand Down
10 changes: 6 additions & 4 deletions main.js~
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ function colorChange(count) {
* This method is used to initially set classes - only used at startup!
*/
function initialColorization(){
/**
symbol = new esri.symbol.SimpleFillSymbol();
symbol.setColor(new dojo.Color([150, 150, 150, 0.75]));
var renderer = new esri.renderer.ClassBreaksRenderer(symbol, attributeFields[activeLayer]);
Expand All @@ -297,7 +298,8 @@ function initialColorization(){
featureLayer.refresh();

legend.refresh();

*/
addEqualBreaks(3, "FF0000", "00FF00");
}

/**
Expand Down Expand Up @@ -357,9 +359,9 @@ function layerChange(layerNr) {
* method for automatic (equal) breaks
*/
function addEqualBreaks(number, colorStart, colorEnd) {

var breakStep = (maxValues[activeLayer] - minValues[activeLayer]) / (number + 1);
var colorArray = generateColor(colorStart, colorEnd, number);
var breakStep = (maxValues[activeLayer] - minValues[activeLayer]) / (number);
var colorArray = generateColor(colorStart, colorEnd, number-1);
colorArray.reverse();

symbol = new esri.symbol.SimpleFillSymbol();
symbol.setColor(new dojo.Color([150, 150, 150, 0.75]));
Expand Down

0 comments on commit 88f3351

Please sign in to comment.