optQry2.qry

  Download

More scripts: Style By Script

Syntax Highlighing:

comments, key words, predefined symbols, class members & methods, functions & classes
            
# OptQry2
# Point CartoScript to use town populations to
# rank towns and draw different point symbol for each
# rank.  Labels are added with different colors by rank,
# using full label optimization to reposition labels to
# to resolve collisions.
# Script from Using CartoScripts tutorial.
# Label sizes for three sizes of towns
small = 2500;	med = 3500;		big = 4500;
# Rank towns by population
pop = TownData.POP90;
if (pop < 1000) then {
	rank = 1;	height = small;
	}
else {
	if (pop >= 30000 ) then { 
		rank = 3;	height = big;
		}
	else {
		rank = 2;	height = med;
		}
	}
# Draw circle with size based on rank
radius = rank * 500;
LineStyleSetColor(255,0,0);
LineStyleDrawCircle(radius,1);
# Read label text and determine dimensions
LineStyleSetFont("ARIALBD.TTF");
LineStyleTextNextPosition(TownData.NAME,height,0,0,next_x,next_y,length);
# Define parameters for optimization
xstart = Internal.x;				ystart  = Internal.y;
xlast = xstart + length;		ylast = ystart + height;
dooptimize = 1;					dodelete = 0;
LineStyleAddToOptimizer(xstart,ystart,xlast,ylast,rank,dooptimize,dodelete);
# Define required function to draw labels after optimization
func FuncDrawLabel() {
	small = 2500;	med = 3500;		big = 4500;
	pop = TownData.POP90;
	if (pop < 1000) {
		height = small;	LineStyleSetTextColor(0,0,0);
		}
	else {
		if (pop >= 30000 ) { 
			height = big;		LineStyleSetTextColor(255,0,0);
		}
		else {
			height = med;		LineStyleSetTextColor(0,0,255);
			}
		}
	LineStyleSetFont("ARIALBD.TTF");
	LineStyleDrawText(TownData.NAME,height,0,0);
	}