optQry1.qry

  Download

More scripts: Style By Script

Syntax Highlighing:

comments, key words, predefined symbols, class members & methods, functions & classes
            
# OptQry1
# Point CartoScript to use town populations to
# rank towns and draw different point symbol for each
# rank.  Labels are added using label optimization to
# resolve label collisions.  Lower-rank colliding labels
# are deleted by the optimizer.
# Script from Using CartoScripts tutorial.
# Rank towns by population
pop = TownData.POP90
if (pop < 1000) then rank = 1;
else {
	if (pop >= 30000 ) then rank = 3;
		else rank = 2;
	}
# Draw circle with size based on rank
radius = rank * 500;
LineStyleSetColor(255,0,0);
LineStyleDrawCircle(radius,1);
# Read label text and determine dimensions
height = 3500;
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 = 0;				dodelete = 1;
LineStyleAddToOptimizer(xstart,ystart,xlast,ylast,rank,dooptimize,dodelete);
# Define required function to draw labels after optimization
func FuncDrawLabel() {
	LineStyleSetFont("ARIALBD.TTF");
	LineStyleSetTextColor(0,0,0);
	height = 3500;
	LineStyleDrawText(TownData.NAME,height,0,0);
	}