Mercurial > pub > ImplabJs
comparison src/djol/DistanceMeasureTool.js @ 10:8705103f074f
Слияние
author | cin |
---|---|
date | Mon, 21 Aug 2017 18:03:00 +0300 |
parents | f0035923ff3e |
children |
comparison
equal
deleted
inserted
replaced
9:37e9e6bbe87a | 10:8705103f074f |
---|---|
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 }); |