8
|
1 define([
|
|
2 "dojo/_base/declare",
|
|
3 "implab/safe",
|
|
4 "./MeasureToolBase",
|
|
5 "implab/text/format",
|
|
6 "dojo/i18n!./format/nls/units",
|
|
7 "ol" ],
|
|
8
|
|
9 function(declare, safe, MeasureToolBase, format, units, ol) {
|
|
10 return declare([ MeasureToolBase ], {
|
|
11
|
|
12 isGeodesic : true,
|
|
13
|
|
14 units : 'metric',
|
|
15
|
|
16 constructor : function(opts) {
|
|
17 if (opts)
|
|
18 safe.mixin(this,opts,["isGeodesic", "units"]);
|
|
19 },
|
|
20
|
|
21 _createDraw : function(source) {
|
|
22 return new ol.interaction.Draw(
|
|
23 {
|
|
24 source : source,
|
|
25 type : "LineString",
|
|
26 style : this.drawStyle
|
|
27 });
|
|
28 },
|
|
29
|
|
30 _formatTooltip : function(sketch, proj) {
|
|
31 var length = 0;
|
|
32 if (this.isGeodesic) {
|
|
33 var points = sketch.getGeometry().getCoordinates();
|
|
34 var t = ol.proj.getTransform(proj, "EPSG:4326");
|
|
35 for (var i = 0; i < points.length - 1; i++) {
|
|
36 length += this.wgs84Sphere.haversineDistance(
|
|
37 t(points[i]),
|
|
38 t(points[i + 1]));
|
|
39 }
|
|
40 } else {
|
|
41 length = sketch.getGeometry().getLength();
|
|
42 }
|
|
43
|
|
44 var mpu, unitName;
|
|
45 switch (this.units) {
|
|
46 case "nautical":
|
|
47 mpu = 1852;
|
|
48 unitName = units.nmiles;
|
|
49 break;
|
|
50 default:
|
|
51 mpu = 1000;
|
|
52 unitName = units.kilometers;
|
|
53 }
|
|
54
|
|
55 if (length >= mpu) {
|
|
56 return format("{0:#.0#}{1}", length / mpu, unitName);
|
|
57 } else {
|
|
58 return format("{0:#0.0#}{1}", length, units.meters);
|
|
59 }
|
|
60 }
|
|
61
|
|
62 });
|
|
63 }); |