download overview-summary-scalebar.js.html
Language: NonCode
LOC: 0
Project Info
ka-map
Server: Maptools
Type: cvs
Maptools\k\ka‑map\ka‑map\docs\
   _BrowserIdent.html
   _eventManager.html
   _layer.html
   _map.html
   _overlayLayer.html
   _queueManager.html
   _wmsLayer.html
   allclasses-frame.html
   allclasses-noframe.html
   GLOBALS.html
   help-doc.html
   index-all.html
   index.html
   kaDoc.html
   kaKeymap.html
   kaLegend.html
   kaMap.html
   kaNavigator.html
   kaOverlay.html
   kaQuery.html
   kaTool.html
   kaXmlFeature.html
   kaXmlGraphicElement.html
   kaXmlIcon.html
   kaXmlLabel.html
   kaXmlLinestring.html
   kaXmlOverlay.html
   kaXmlPoint.html
   kaXmlPolygon.html
   kaXmlSymbol.html
   overview-DHTMLapi.js.html
   overview-frame.html
   overview-kaKeymap.js.html
   overview-kaLegend.js.html
   overview-kaMap.js.html
   overview-kaOverlay.js.html
   overview-kaQuery.js.html
   ...view-kaScalebar.js.html
   overview-kaTool.js.html
   ...ew-kaXmlOverlay.js.html
   overview-kaZoomer.js.html
   ...ew-overlayLayer.js.html
   overview-scalebar.js.html
   ...ummary-DHTMLapi.js.html
   ...ummary-kaKeymap.js.html
   ...ummary-kaLegend.js.html
   ...w-summary-kaMap.js.html
   ...mmary-kaOverlay.js.html
   ...summary-kaQuery.js.html
   ...mary-kaScalebar.js.html
   ...-summary-kaTool.js.html
   ...ry-kaXmlOverlay.js.html
   ...ummary-kaZoomer.js.html
   ...ry-overlayLayer.js.html
   ...ummary-scalebar.js.html
   ...ummary-wmsLayer.js.html
   ...iew-summary-xhr.js.html
   overview-summary.html
   overview-tree.html
   overview-wmsLayer.js.html
   overview-xhr.js.html
   ScaleBar.html
   stylesheet.css

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
<!doctype html public "-//W3C//DTD HTML 4.0 Frameset//EN""http://www.w3.org/TR/REC-html40/frameset.dtd">
<html>
<head>
<title>
ka-Map Overview
</title>
<link rel ="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<script>
function asd() {
	
		parent.document.title="scalebar.js Overview";
	
}
</script>
</head>
<body bgcolor="white" onload="asd();">

<!-- ========== START OF NAVBAR ========== -->
<a name="navbar_top"><!-- --></a>
<table border="0" width="100%" cellpadding="1" cellspacing="0">
<tr>
<td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1">
<a name="navbar_top_firstrow"><!-- --></a>
<table border="0" cellpadding="0" cellspacing="3">
  <tr align="center" valign="top">
  
  
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a>&nbsp;</td>
  <td bgcolor="#FFFFFF" class="NavBarCell1Rev">	&nbsp;<font class="NavBarFont1Rev"><b>File</b></font>&nbsp;</td>
  

  <td bgcolor="#FFFFFF" class="NavBarCell1"> 	<font class="NavBarFont1">Class</font>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a>&nbsp;</td>
  </tr>
</table>
</td>
<td bgcolor="#EEEEFF" align="right" valign="top">
<em>
<b>ka-Map</b></em>
</td>
</tr>

<tr>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
&nbsp;PREV&nbsp;
&nbsp;NEXT</font></td>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
  <a href="index.html" target="_top"><b>FRAMES</b></a>  &nbsp;
&nbsp;<a href="overview-summary.html" target="_top"><b>NO FRAMES</b></a>
&nbsp;&nbsp;
<script>
  <!--
  if(window==top) {
    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
  }
  //-->
</script>
<noscript>
<a href="allclasses-noframe.html" target=""><b>All Classes</b></a>
</noscript>
</font></td>
</tr>
</table>
<!-- =========== END OF NAVBAR =========== -->

<hr>
<center>
	
	   <h2>scalebar.js</h2>
	
</center>

	


<h4>Summary</h4>
<p>
	
		No overview generated for 'scalebar.js'<BR/><BR/>
	
</p>

<hr>


    <table border="1" cellpadding="3" cellspacing="0" width="100%">
    <tr bgcolor="#CCCCFF" class="TableHeadingColor">
    <td colspan=2><font size="+2">
    
        <b>Class Summary</b>
    
    </font></td>
    </tr>
    
    <tr bgcolor="white" class="TableRowColor">
    <td width="15%"><b><a href="ScaleBar.html">ScaleBar</a></b></td>
    <td>&nbsp;</td>
    </tr>
    
    </table>
    <hr/> 


<!-- ========== METHOD SUMMARY =========== -->

<!-- ========== END METHOD SUMMARY =========== -->


        <pre class="sourceview"><span class="comment">/*
JavaScript Scalebar for MapServer (scalebar.js)

Copyright (c) 2005 Tim Schaub of CommEn Space (http://www.commenspace.org)

This is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the
Free Software Foundation; either version 2.1 of the License, or (at
your option) any later version.

This software is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
License for more details.

You should have received a copy of the GNU Lesser General Public License
along with this software; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

v1.3.1 - removed a typo that affected .sbBar with borders (thanks jlivni)
       - scalebar is now centered on .sbWrapper div by default, more css control
       - reduced likelihood of displaying very large numbers
       - added condition to deal with <span class="attrib">@import</span> styles (thanks dokai)

*/</span>

<span class="reserved">function</span> ScaleBar(scaleDenominator) {
    <span class="comment">// default properties</span>
    <span class="comment">// may be modified after construction</span>
    <span class="comment">// if modified after ScaleBar.place(), use ScaleBar.update()</span>
    <span class="reserved">this</span>.scaleDenominator = (scaleDenominator == null) ? 1 : scaleDenominator;
    <span class="reserved">this</span>.displaySystem = <span class="literal">'metric'</span>; <span class="comment">// metric or english supported</span>
    <span class="reserved">this</span>.minWidth = 100; <span class="comment">// pixels</span>
    <span class="reserved">this</span>.maxWidth = 200; <span class="comment">// pixels</span>
    <span class="reserved">this</span>.divisions = 2;
    <span class="reserved">this</span>.subdivisions = 2;
    <span class="reserved">this</span>.showMinorMeasures = false;
    <span class="reserved">this</span>.abbreviateLabel = false;
    <span class="reserved">this</span>.singleLine = false;
    <span class="reserved">this</span>.resolution = 72; <span class="comment">// dpi</span>
    <span class="reserved">this</span>.align = <span class="literal">'center'</span>; <span class="comment">// left, center, or right supported</span>
    <span class="comment">// create scalebar elements</span>
    <span class="reserved">this</span>.container = document.createElement(<span class="literal">'div'</span>);
    <span class="reserved">this</span>.container.className = <span class="literal">'sbWrapper'</span>;
    <span class="reserved">this</span>.labelContainer = document.createElement(<span class="literal">'div'</span>);
    <span class="reserved">this</span>.labelContainer.className = <span class="literal">'sbUnitsContainer'</span>;
    <span class="reserved">this</span>.labelContainer.style.position = <span class="literal">'absolute'</span>;
    <span class="reserved">this</span>.graphicsContainer = document.createElement(<span class="literal">'div'</span>);
    <span class="reserved">this</span>.graphicsContainer.style.position = <span class="literal">'absolute'</span>;
    <span class="reserved">this</span>.graphicsContainer.className = <span class="literal">'sbGraphicsContainer'</span>;
    <span class="reserved">this</span>.numbersContainer = document.createElement(<span class="literal">'div'</span>);
    <span class="reserved">this</span>.numbersContainer.style.position = <span class="literal">'absolute'</span>;
    <span class="reserved">this</span>.numbersContainer.className = <span class="literal">'sbNumbersContainer'</span>;
    <span class="comment">// private functions</span>
    <span class="comment">// put in some markers and bar pieces so style attributes can be grabbed</span>
    <span class="comment">// this is a solution for Safari support</span>
    var markerMajor = document.createElement(<span class="literal">'div'</span>);
    markerMajor.className = <span class="literal">'sbMarkerMajor'</span>;
    <span class="reserved">this</span>.graphicsContainer.appendChild(markerMajor);
    var markerMinor = document.createElement(<span class="literal">'div'</span>);
    markerMinor.className = <span class="literal">'sbMarkerMinor'</span>;
    <span class="reserved">this</span>.graphicsContainer.appendChild(markerMinor);
    var barPiece = document.createElement(<span class="literal">'div'</span>);
    barPiece.className = <span class="literal">'sbBar'</span>;
    <span class="reserved">this</span>.graphicsContainer.appendChild(barPiece);
    var barPieceAlt = document.createElement(<span class="literal">'div'</span>);
    barPieceAlt.className = <span class="literal">'sbBarAlt'</span>;
    <span class="reserved">this</span>.graphicsContainer.appendChild(barPieceAlt);
}
ScaleBar.<span class="reserved">prototype</span>.update = <span class="reserved">function</span>(scaleDenominator) {
    <span class="reserved">if</span>(scaleDenominator != null) {
        <span class="reserved">this</span>.scaleDenominator = scaleDenominator;
    }
    <span class="comment">// local functions (and object constructors)</span>
    <span class="reserved">function</span> HandsomeNumber(smallUglyNumber, bigUglyNumber, sigFigs) {
        var sigFigs = (sigFigs == null) ? 10 : sigFigs;
        var bestScore = Number.POSITIVE_INFINITY;
        var bestTieBreaker = Number.POSITIVE_INFINITY;
        <span class="comment">// if all else fails, return a small ugly number</span>
        var handsomeValue = smallUglyNumber;
        var handsomeNumDec = 3;
        <span class="comment">// try the first three comely multiplicands (in order of comliness)</span>
        <span class="reserved">for</span>(var halvingExp = 0; halvingExp &lt; 3; ++halvingExp) {
            var comelyMultiplicand = Math.pow(2, (-1 * halvingExp));
            var maxTensExp = Math.floor(Math.log(bigUglyNumber / comelyMultiplicand) / Math.LN10)
            <span class="reserved">for</span>(var tensExp = maxTensExp; tensExp &gt; (maxTensExp - sigFigs + 1); --tensExp) {
                var numDec = Math.max(halvingExp - tensExp, 0);
                var testMultiplicand = comelyMultiplicand * Math.pow(10, tensExp);
                <span class="comment">// check if there is an integer multiple of testMultiplicand between smallUglyNumber and bigUglyNumber</span>
                <span class="reserved">if</span>((testMultiplicand * Math.floor(bigUglyNumber / testMultiplicand)) &gt;= smallUglyNumber) {
                    <span class="comment">// check if smallUglyNumber is an integer multiple of testMultiplicand</span>
                    <span class="reserved">if</span>(smallUglyNumber % testMultiplicand == 0) {
                        var testMultiplier = smallUglyNumber / testMultiplicand;
                    }
                    <span class="comment">// otherwise go for the smallest integer multiple between small and big</span>
                    <span class="reserved">else</span> {
                        var testMultiplier = Math.floor(smallUglyNumber / testMultiplicand) + 1;
                    }
                    <span class="comment">// test against the best (lower == better)</span>
                    var testScore = testMultiplier + (2 * halvingExp);
                    var testTieBreaker = (tensExp &lt; 0) ? (Math.abs(tensExp) + 1) : tensExp;
                    <span class="reserved">if</span>((testScore &lt; bestScore) || ((testScore == bestScore) &amp;&amp; (testTieBreaker &lt; bestTieBreaker))) {
                        bestScore = testScore;
                        bestTieBreaker = testTieBreaker;
                        handsomeValue = (testMultiplicand * testMultiplier).toFixed(numDec);
                        handsomeNumDec = numDec;
                    }
                }
            }
        }
        <span class="reserved">this</span>.value = handsomeValue;
        <span class="reserved">this</span>.score = bestScore;
        <span class="reserved">this</span>.tieBreaker = bestTieBreaker;
        <span class="reserved">this</span>.numDec = handsomeNumDec;
    }
    HandsomeNumber.<span class="reserved">prototype</span>.toString = <span class="reserved">function</span>() {
        <span class="reserved">return</span> <span class="reserved">this</span>.value.toString();
    }
    HandsomeNumber.<span class="reserved">prototype</span>.valueOf = <span class="reserved">function</span>() {
        <span class="reserved">return</span> <span class="reserved">this</span>.value;
    }
    <span class="reserved">function</span> styleValue(aSelector, styleKey) {
        <span class="comment">// returns an integer value associated with a particular selector and key</span>
        <span class="comment">// given a stylesheet with .someSelector {border: 2px solid red}</span>
        <span class="comment">// styleValue('.someSelector', 'borderWidth') returns 2</span>
        var aValue = 0;
        <span class="reserved">if</span>(document.styleSheets) {
            <span class="reserved">for</span>(var sheetIndex = document.styleSheets.length - 1; sheetIndex &gt;= 0; --sheetIndex) {
                var aSheet = document.styleSheets[sheetIndex];
                <span class="reserved">if</span>(!aSheet.disabled) {
                    var allRules;
                    <span class="reserved">if</span>(typeof(aSheet.cssRules) == <span class="literal">'undefined'</span>) {
                        <span class="reserved">if</span>(typeof(aSheet.rules) == <span class="literal">'undefined'</span>) {
                            <span class="comment">// can't get rules, assume zero</span>
                            <span class="reserved">return</span> 0;
                        }
                        <span class="reserved">else</span> {
                            allRules = aSheet.rules;
                        }
                    }
                    <span class="reserved">else</span> {
                        allRules = aSheet.cssRules;
                    }
                    <span class="reserved">for</span>(var ruleIndex = 0; ruleIndex &lt; allRules.length; ++ruleIndex) {
                        var aRule = allRules[ruleIndex];
                        <span class="reserved">if</span>(aRule.selectorText &amp;&amp; (aRule.selectorText.toLowerCase() == aSelector.toLowerCase())) {
                            <span class="reserved">if</span>(aRule.style[styleKey] != <span class="literal">''</span>) {
                                aValue = parseInt(aRule.style[styleKey]);
                            }
                        }
                    }
                }
            }
        }
        <span class="comment">// if the styleKey was not found, the equivalent value is zero</span>
        <span class="reserved">return</span> aValue ? aValue : 0;
    }
    <span class="reserved">function</span> formatNumber(aNumber, numDecimals) {
        numDecimals = (numDecimals) ? numDecimals : 0;
        var formattedInteger = <span class="literal">''</span> + Math.round(aNumber);
        var thousandsPattern = /(-?[0-9]+)([0-9]{3})/;
        <span class="reserved">while</span>(thousandsPattern.test(formattedInteger)) {
            formattedInteger = formattedInteger.replace(thousandsPattern, <span class="literal">'$1,$2'</span>);
        }
        <span class="reserved">if</span>(numDecimals &gt; 0) {
            var formattedDecimal = Math.floor(Math.pow(10, numDecimals) * (aNumber - Math.round(aNumber)));
            <span class="reserved">if</span>(formattedDecimal == 0) {
                <span class="reserved">return</span> formattedInteger;
            }
            <span class="reserved">else</span> {
                <span class="reserved">return</span> formattedInteger + <span class="literal">'.'</span> + formattedDecimal;
            }
        }
        <span class="reserved">else</span> {
            <span class="reserved">return</span> formattedInteger;
        }
    }
    <span class="comment">// update the container title (for displaying scale as a tooltip)</span>
    <span class="reserved">this</span>.container.title = <span class="literal">'scale 1:'</span> + formatNumber(<span class="reserved">this</span>.scaleDenominator);
    <span class="comment">// measurementProperties holds display units, abbreviations,</span>
    <span class="comment">// and conversion to inches (since we're using dpi) - per measurement sytem</span>
    var measurementProperties = new Object();
    measurementProperties.english = {
        units: [<span class="literal">'miles'</span>, <span class="literal">'feet'</span>, <span class="literal">'inches'</span>],
        abbr: [<span class="literal">'mi'</span>, <span class="literal">'ft'</span>, <span class="literal">'in'</span>],
        inches: [63360, 12, 1]
    }
    measurementProperties.metric = {
        units: [<span class="literal">'kilometers'</span>, <span class="literal">'meters'</span>, <span class="literal">'centimeters'</span>],
        abbr: [<span class="literal">'km'</span>, <span class="literal">'m'</span>, <span class="literal">'cm'</span>],
        inches: [39370.07874, 39.370079, 0.393701]
    }
    <span class="comment">// check each measurement unit in the display system</span>
    var comparisonArray = new Array();
    <span class="reserved">for</span>(var unitIndex = 0; unitIndex &lt; measurementProperties[<span class="reserved">this</span>.displaySystem].units.length; ++unitIndex) {
        comparisonArray[unitIndex] = new Object();
        var pixelsPerDisplayUnit = <span class="reserved">this</span>.resolution * measurementProperties[<span class="reserved">this</span>.displaySystem].inches[unitIndex] / <span class="reserved">this</span>.scaleDenominator;
        var minSDDisplayLength = (<span class="reserved">this</span>.minWidth / pixelsPerDisplayUnit) / (<span class="reserved">this</span>.divisions * <span class="reserved">this</span>.subdivisions);
        var maxSDDisplayLength = (<span class="reserved">this</span>.maxWidth / pixelsPerDisplayUnit) / (<span class="reserved">this</span>.divisions * <span class="reserved">this</span>.subdivisions);
        <span class="comment">// add up scores for each marker (even if numbers aren't displayed)</span>
        <span class="reserved">for</span>(var valueIndex = 0; valueIndex &lt; (<span class="reserved">this</span>.divisions * <span class="reserved">this</span>.subdivisions); ++valueIndex) {
            var minNumber = minSDDisplayLength * (valueIndex + 1);
            var maxNumber = maxSDDisplayLength * (valueIndex + 1);
            var niceNumber = new HandsomeNumber(minNumber, maxNumber);
            comparisonArray[unitIndex][valueIndex] = {value: (niceNumber.value / (valueIndex + 1)), score: 0, tieBreaker: 0, numDec: 0, displayed: 0};
            <span class="comment">// now tally up scores for all values given this subdivision length</span>
            <span class="reserved">for</span>(var valueIndex2 = 0; valueIndex2 &lt; (<span class="reserved">this</span>.divisions * <span class="reserved">this</span>.subdivisions); ++valueIndex2) {
                displayedValuePosition = niceNumber.value * (valueIndex2 + 1) / (valueIndex + 1);
                niceNumber2 = new HandsomeNumber(displayedValuePosition, displayedValuePosition);
                var isMajorMeasurement = ((valueIndex2 + 1) % <span class="reserved">this</span>.subdivisions == 0);
                var isLastMeasurement = ((valueIndex2 + 1) == (<span class="reserved">this</span>.divisions * <span class="reserved">this</span>.subdivisions));
                <span class="reserved">if</span>((<span class="reserved">this</span>.singleLine &amp;&amp; isLastMeasurement) || (!<span class="reserved">this</span>.singleLine &amp;&amp; (isMajorMeasurement || <span class="reserved">this</span>.showMinorMeasures))) {
                    <span class="comment">// count scores for displayed marker measurements</span>
                    comparisonArray[unitIndex][valueIndex].score += niceNumber2.score;
                    comparisonArray[unitIndex][valueIndex].tieBreaker += niceNumber2.tieBreaker;
                    comparisonArray[unitIndex][valueIndex].numDec = Math.max(comparisonArray[unitIndex][valueIndex].numDec, niceNumber2.numDec);
                    comparisonArray[unitIndex][valueIndex].displayed += 1;
                }
                <span class="reserved">else</span> {
                    <span class="comment">// count scores for non-displayed marker measurements</span>
                    comparisonArray[unitIndex][valueIndex].score += niceNumber2.score / <span class="reserved">this</span>.subdivisions;
                    comparisonArray[unitIndex][valueIndex].tieBreaker += niceNumber2.tieBreaker / <span class="reserved">this</span>.subdivisions;
                }
            }
            <span class="comment">// adjust scores so numbers closer to 1 are preferred for display</span>
            var scoreAdjustment = (unitIndex + 1) * comparisonArray[unitIndex][valueIndex].tieBreaker / comparisonArray[unitIndex][valueIndex].displayed;
            comparisonArray[unitIndex][valueIndex].score *= scoreAdjustment;
        }
    }
    <span class="comment">// get the value (subdivision length) with the lowest cumulative score</span>
    var subdivisionDisplayLength = null;
    var displayUnits = null;
    var displayUnitsAbbr = null;
    var subdivisionPixelLength = null;
    var bestScore = Number.POSITIVE_INFINITY;
    var bestTieBreaker = Number.POSITIVE_INFINITY;
    var numDec = 0;
    <span class="reserved">for</span>(var unitIndex = 0; unitIndex &lt; comparisonArray.length; ++unitIndex) {
        <span class="reserved">for</span>(valueIndex in comparisonArray[unitIndex]) {
            <span class="reserved">if</span>((comparisonArray[unitIndex][valueIndex].score &lt; bestScore) || ((comparisonArray[unitIndex][valueIndex].score == bestScore) &amp;&amp; (comparisonArray[unitIndex][valueIndex].tieBreaker &lt; bestTieBreaker))) {
                bestScore = comparisonArray[unitIndex][valueIndex].score;
                bestTieBreaker = comparisonArray[unitIndex][valueIndex].tieBreaker;
                subdivisionDisplayLength = comparisonArray[unitIndex][valueIndex].value;
                numDec = comparisonArray[unitIndex][valueIndex].numDec;
                displayUnits = measurementProperties[<span class="reserved">this</span>.displaySystem].units[unitIndex];
                displayUnitsAbbr = measurementProperties[<span class="reserved">this</span>.displaySystem].abbr[unitIndex];
                pixelsPerDisplayUnit = <span class="reserved">this</span>.resolution * measurementProperties[<span class="reserved">this</span>.displaySystem].inches[unitIndex] / <span class="reserved">this</span>.scaleDenominator;
                subdivisionPixelLength = pixelsPerDisplayUnit * subdivisionDisplayLength; <span class="comment">// round before use in style</span>
            }
        }
    }
    <span class="comment">// determine offsets for graphic elements</span>
    var xOffsetMarkerMajor = (styleValue(<span class="literal">'.sbMarkerMajor'</span>, <span class="literal">'borderLeftWidth'</span>) + styleValue(<span class="literal">'.sbMarkerMajor'</span>, <span class="literal">'width'</span>) + styleValue(<span class="literal">'.sbMarkerMajor'</span>, <span class="literal">'borderRightWidth'</span>)) / 2;
    var xOffsetMarkerMinor = (styleValue(<span class="literal">'.sbMarkerMinor'</span>, <span class="literal">'borderLeftWidth'</span>) + styleValue(<span class="literal">'.sbMarkerMinor'</span>, <span class="literal">'width'</span>) + styleValue(<span class="literal">'.sbMarkerMinor'</span>, <span class="literal">'borderRightWidth'</span>)) / 2;
    var xOffsetBar = (styleValue(<span class="literal">'.sbBar'</span>, <span class="literal">'borderLeftWidth'</span>) + styleValue(<span class="literal">'.sbBar'</span>, <span class="literal">'borderRightWidth'</span>)) / 2;
    var xOffsetBarAlt = (styleValue(<span class="literal">'.sbBarAlt'</span>, <span class="literal">'borderLeftWidth'</span>) + styleValue(<span class="literal">'.sbBarAlt'</span>, <span class="literal">'borderRightWidth'</span>)) / 2;
    <span class="comment">// support for browsers without the Document.styleSheets property (Opera)</span>
    <span class="reserved">if</span>(!document.styleSheets) {
        <span class="comment">// this is a two part hack, one for the offsets here and one for the css below</span>
        xOffsetMarkerMajor = 0.5;
        xOffsetMarkerMinor = 0.5;
    }
    <span class="comment">// clean out any old content from containers</span>
    <span class="reserved">while</span>(<span class="reserved">this</span>.labelContainer.hasChildNodes()) {
        <span class="reserved">this</span>.labelContainer.removeChild(<span class="reserved">this</span>.labelContainer.firstChild);
    }
    <span class="reserved">while</span>(<span class="reserved">this</span>.graphicsContainer.hasChildNodes()) {
        <span class="reserved">this</span>.graphicsContainer.removeChild(<span class="reserved">this</span>.graphicsContainer.firstChild);
    }
    <span class="reserved">while</span>(<span class="reserved">this</span>.numbersContainer.hasChildNodes()) {
        <span class="reserved">this</span>.numbersContainer.removeChild(<span class="reserved">this</span>.numbersContainer.firstChild);
    }
    <span class="comment">// create all divisions</span>
    var aMarker, aBarPiece, numbersBox, xOffset;
    var alignmentOffset = {
        left: 0,
        center: (-1 * <span class="reserved">this</span>.divisions * <span class="reserved">this</span>.subdivisions * subdivisionPixelLength / 2),
        right: (-1 * <span class="reserved">this</span>.divisions * <span class="reserved">this</span>.subdivisions * subdivisionPixelLength)
    }
    var xPosition = 0 + alignmentOffset[<span class="reserved">this</span>.align];
    var markerMeasure = 0;
    <span class="reserved">for</span>(var divisionIndex = 0; divisionIndex &lt; <span class="reserved">this</span>.divisions; ++divisionIndex) {
        <span class="comment">// set xPosition and markerMeasure to start of division</span>
        xPosition = divisionIndex * <span class="reserved">this</span>.subdivisions * subdivisionPixelLength;
        xPosition += alignmentOffset[<span class="reserved">this</span>.align];
        markerMeasure = (divisionIndex == 0) ? 0 : ((divisionIndex * <span class="reserved">this</span>.subdivisions) * subdivisionDisplayLength).toFixed(numDec);
        <span class="comment">// add major marker</span>
        aMarker = document.createElement(<span class="literal">'div'</span>);
        aMarker.className = <span class="literal">'sbMarkerMajor'</span>;
        aMarker.style.position = <span class="literal">'absolute'</span>;
        aMarker.style.overflow = <span class="literal">'hidden'</span>;
        aMarker.style.left = Math.round(xPosition - xOffsetMarkerMajor) + <span class="literal">'px'</span>;
        aMarker.appendChild(document.createTextNode(<span class="literal">' '</span>));
        <span class="reserved">this</span>.graphicsContainer.appendChild(aMarker);
        <span class="comment">// add initial measure</span>
        <span class="reserved">if</span>(!<span class="reserved">this</span>.singleLine) {
            numbersBox = document.createElement(<span class="literal">'div'</span>);
            numbersBox.className = <span class="literal">'sbNumbersBox'</span>;
            numbersBox.style.position = <span class="literal">'absolute'</span>;
            numbersBox.style.overflow = <span class="literal">'hidden'</span>;
            numbersBox.style.textAlign = <span class="literal">'center'</span>;
            <span class="reserved">if</span>(<span class="reserved">this</span>.showMinorMeasures) {
                numbersBox.style.width = Math.round(subdivisionPixelLength * 2) + <span class="literal">'px'</span>;
                numbersBox.style.left = Math.round(xPosition - subdivisionPixelLength) + <span class="literal">'px'</span>;
            }
            <span class="reserved">else</span> {
                numbersBox.style.width = Math.round(<span class="reserved">this</span>.subdivisions * subdivisionPixelLength * 2) + <span class="literal">'px'</span>;
                numbersBox.style.left = Math.round(xPosition - (<span class="reserved">this</span>.subdivisions * subdivisionPixelLength)) + <span class="literal">'px'</span>;
            }
            numbersBox.appendChild(document.createTextNode(markerMeasure));
            <span class="reserved">this</span>.numbersContainer.appendChild(numbersBox);
        }
        <span class="comment">// create all subdivisions</span>
        <span class="reserved">for</span>(var subdivisionIndex = 0; subdivisionIndex &lt; <span class="reserved">this</span>.subdivisions; ++subdivisionIndex) {
            aBarPiece = document.createElement(<span class="literal">'div'</span>);
            aBarPiece.style.position = <span class="literal">'absolute'</span>;
            aBarPiece.style.overflow = <span class="literal">'hidden'</span>;
            aBarPiece.style.width = Math.round(subdivisionPixelLength) + <span class="literal">'px'</span>;
            <span class="reserved">if</span>((subdivisionIndex % 2) == 0) {
                aBarPiece.className = <span class="literal">'sbBar'</span>;
                aBarPiece.style.left = Math.round(xPosition - xOffsetBar) + <span class="literal">'px'</span>;
            }
            <span class="reserved">else</span> {
                aBarPiece.className = <span class="literal">'sbBarAlt'</span>;
                aBarPiece.style.left = Math.round(xPosition - xOffsetBarAlt) + <span class="literal">'px'</span>;
            }
            aBarPiece.appendChild(document.createTextNode(<span class="literal">' '</span>));
            <span class="reserved">this</span>.graphicsContainer.appendChild(aBarPiece);
            <span class="comment">// add minor marker if not the last subdivision</span>
            <span class="reserved">if</span>(subdivisionIndex &lt; (<span class="reserved">this</span>.subdivisions - 1)) {
                <span class="comment">// set xPosition and markerMeasure to end of subdivision</span>
                xPosition = ((divisionIndex * <span class="reserved">this</span>.subdivisions) + (subdivisionIndex + 1)) * subdivisionPixelLength;
                xPosition += alignmentOffset[<span class="reserved">this</span>.align];
                markerMeasure = (divisionIndex * <span class="reserved">this</span>.subdivisions + subdivisionIndex + 1) * subdivisionDisplayLength;
                aMarker = document.createElement(<span class="literal">'div'</span>);
                aMarker.className = <span class="literal">'sbMarkerMinor'</span>;
                aMarker.style.position = <span class="literal">'absolute'</span>;
                aMarker.style.overflow = <span class="literal">'hidden'</span>;
                aMarker.style.left = Math.round(xPosition - xOffsetMarkerMinor) + <span class="literal">'px'</span>;
                aMarker.appendChild(document.createTextNode(<span class="literal">' '</span>));
                <span class="reserved">this</span>.graphicsContainer.appendChild(aMarker);
                <span class="reserved">if</span>(<span class="reserved">this</span>.showMinorMeasures &amp;&amp; !<span class="reserved">this</span>.singleLine) {
                    <span class="comment">// add corresponding measure</span>
                    numbersBox = document.createElement(<span class="literal">'div'</span>);
                    numbersBox.className = <span class="literal">'sbNumbersBox'</span>;
                    numbersBox.style.position = <span class="literal">'absolute'</span>;
                    numbersBox.style.overflow = <span class="literal">'hidden'</span>;
                    numbersBox.style.textAlign = <span class="literal">'center'</span>;
                    numbersBox.style.width = Math.round(subdivisionPixelLength * 2) + <span class="literal">'px'</span>;
                    numbersBox.style.left = Math.round(xPosition - subdivisionPixelLength) + <span class="literal">'px'</span>;
                    numbersBox.appendChild(document.createTextNode(markerMeasure));
                    <span class="reserved">this</span>.numbersContainer.appendChild(numbersBox);
                }
            }
        }
    }
    <span class="comment">// set xPosition and markerMeasure to end of divisions</span>
    xPosition = (<span class="reserved">this</span>.divisions * <span class="reserved">this</span>.subdivisions) * subdivisionPixelLength;
    xPosition += alignmentOffset[<span class="reserved">this</span>.align];
    markerMeasure = ((<span class="reserved">this</span>.divisions * <span class="reserved">this</span>.subdivisions) * subdivisionDisplayLength).toFixed(numDec);
    <span class="comment">// add the final major marker</span>
    aMarker = document.createElement(<span class="literal">'div'</span>);
    aMarker.className = <span class="literal">'sbMarkerMajor'</span>;
    aMarker.style.position = <span class="literal">'absolute'</span>;
    aMarker.style.overflow = <span class="literal">'hidden'</span>;
    aMarker.style.left = Math.round(xPosition - xOffsetMarkerMajor) + <span class="literal">'px'</span>;
    aMarker.appendChild(document.createTextNode(<span class="literal">' '</span>));
    <span class="reserved">this</span>.graphicsContainer.appendChild(aMarker);
    <span class="comment">// add final measure</span>
    <span class="reserved">if</span>(!<span class="reserved">this</span>.singleLine) {
        numbersBox = document.createElement(<span class="literal">'div'</span>);
        numbersBox.className = <span class="literal">'sbNumbersBox'</span>;
        numbersBox.style.position = <span class="literal">'absolute'</span>;
        numbersBox.style.overflow = <span class="literal">'hidden'</span>;
        numbersBox.style.textAlign = <span class="literal">'center'</span>;
        <span class="reserved">if</span>(<span class="reserved">this</span>.showMinorMeasures) {
            numbersBox.style.width = Math.round(subdivisionPixelLength * 2) + <span class="literal">'px'</span>;
            numbersBox.style.left = Math.round(xPosition - subdivisionPixelLength) + <span class="literal">'px'</span>;
        }
        <span class="reserved">else</span> {
            numbersBox.style.width = Math.round(<span class="reserved">this</span>.subdivisions * subdivisionPixelLength * 2) + <span class="literal">'px'</span>;
            numbersBox.style.left = Math.round(xPosition - (<span class="reserved">this</span>.subdivisions * subdivisionPixelLength)) + <span class="literal">'px'</span>;
        }
        numbersBox.appendChild(document.createTextNode(markerMeasure));
        <span class="reserved">this</span>.numbersContainer.appendChild(numbersBox);
    }
    <span class="comment">// add content to the label container</span>
    var labelBox = document.createElement(<span class="literal">'div'</span>);
    labelBox.style.position = <span class="literal">'absolute'</span>;
    var labelText;
    <span class="reserved">if</span>(<span class="reserved">this</span>.singleLine) {
        labelText = markerMeasure;
        labelBox.className = <span class="literal">'sbLabelBoxSingleLine'</span>;
        labelBox.style.top = <span class="literal">'-0.6em'</span>;
        labelBox.style.left = (xPosition + 10) + <span class="literal">'px'</span>;
    }
    <span class="reserved">else</span> {
        labelText = <span class="literal">''</span>;
        labelBox.className = <span class="literal">'sbLabelBox'</span>;
        labelBox.style.textAlign = <span class="literal">'center'</span>;
        labelBox.style.width = Math.round(<span class="reserved">this</span>.divisions * <span class="reserved">this</span>.subdivisions * subdivisionPixelLength) + <span class="literal">'px'</span>
        labelBox.style.left = Math.round(alignmentOffset[<span class="reserved">this</span>.align]) + <span class="literal">'px'</span>;
        labelBox.style.overflow = <span class="literal">'hidden'</span>;
    }
    <span class="reserved">if</span>(<span class="reserved">this</span>.abbreviateLabel) {
        labelText += <span class="literal">' '</span> + displayUnitsAbbr;
    }
    <span class="reserved">else</span> {
        labelText += <span class="literal">' '</span> + displayUnits;
    }
    labelBox.appendChild(document.createTextNode(labelText));
    <span class="reserved">this</span>.labelContainer.appendChild(labelBox);
    <span class="comment">// support for browsers without the Document.styleSheets property (Opera)</span>
    <span class="reserved">if</span>(!document.styleSheets) {
        <span class="comment">// override custom css with default</span>
        var defaultStyle = document.createElement(<span class="literal">'style'</span>);
        defaultStyle.type = <span class="literal">'text/css'</span>;
        var styleText = <span class="literal">'.sbBar {top: 0px; background: #666666; height: 1px; border: 0;}'</span>;
        styleText += <span class="literal">'.sbBarAlt {top: 0px; background: #666666; height: 1px; border: 0;}'</span>;
        styleText += <span class="literal">'.sbMarkerMajor {height: 7px; width: 1px; background: #666666; border: 0;}'</span>;
        styleText += <span class="literal">'.sbMarkerMinor {height: 5px; width: 1px; background: #666666; border: 0;}'</span>;
        styleText += <span class="literal">'.sbLabelBox {top: -16px;}'</span>;
        styleText += <span class="literal">'.sbNumbersBox {top: 7px;}'</span>;
        defaultStyle.appendChild(document.createTextNode(styleText));
        document.getElementsByTagName(<span class="literal">'head'</span>).item(0).appendChild(defaultStyle);
    }
    <span class="comment">// append the child containers to the parent container</span>
    <span class="reserved">this</span>.container.appendChild(<span class="reserved">this</span>.graphicsContainer);
    <span class="reserved">this</span>.container.appendChild(<span class="reserved">this</span>.labelContainer);
    <span class="reserved">this</span>.container.appendChild(<span class="reserved">this</span>.numbersContainer);
}
ScaleBar.<span class="reserved">prototype</span>.place = <span class="reserved">function</span>(elementId) {
    <span class="reserved">if</span>(elementId == null) {
        document.body.appendChild(<span class="reserved">this</span>.container);
    }
    <span class="reserved">else</span> {
        var anElement = document.getElementById(elementId);
        <span class="reserved">if</span>(anElement != null) {
            anElement.appendChild(<span class="reserved">this</span>.container);
        }
    }
    <span class="reserved">this</span>.update();
}
</pre>
	<hr>



<!-- ========== START OF NAVBAR ========== -->
<a name="navbar_top"><!-- --></a>
<table border="0" width="100%" cellpadding="1" cellspacing="0">
<tr>
<td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1">
<a name="navbar_top_firstrow"><!-- --></a>
<table border="0" cellpadding="0" cellspacing="3">
  <tr align="center" valign="top">
  
  
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a>&nbsp;</td>
  <td bgcolor="#FFFFFF" class="NavBarCell1Rev">	&nbsp;<font class="NavBarFont1Rev"><b>File</b></font>&nbsp;</td>
  

  <td bgcolor="#FFFFFF" class="NavBarCell1"> <font class="NavBarFont1">Class</font>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a>&nbsp;</td>
  </tr>
</table>
</td>
<td bgcolor="#EEEEFF" align="right" valign="top"><em>
<b>ka-Map</b></em>
</td>
</tr>

<tr>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
&nbsp;PREV&nbsp;
&nbsp;NEXT</font></td>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
  <a href="index.html" target="_top"><b>FRAMES</b></a>  &nbsp;
&nbsp;<a href="overview-summary.html" target="_top"><b>NO FRAMES</b></a>
&nbsp;&nbsp;
<script>
  <!--
  if(window==top) {
    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
  }
  //-->
</script>
<noscript>
<a href="allclasses-noframe.html" target=""><b>All Classes</b></a>
</noscript>
</font></td>
</tr>
</table>
<!-- =========== END OF NAVBAR =========== -->

<hr>
<font size="-1">

</font>
<div class="jsdoc_ctime">Documentation generated by <a href="http://jsdoc.sourceforge.net/" target="_parent">JSDoc</a> on Wed Mar 15 10:50:59 2006</div>
</body>
</html>

About Koders | Resources | Downloads | Support | Black Duck | Submit Project | Terms of Service | DMCA | Privacy Policy | Site Map| Contact Us