comparison src/djol/SquareMeasureTool.js @ 8:f0035923ff3e

добавлена библиотека для работы с openlayers 3+
author cin
date Mon, 21 Aug 2017 17:47:00 +0300
parents
children
comparison
equal deleted inserted replaced
7:9c0943c68a90 8:f0035923ff3e
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 source : source,
24 type : "Polygon",
25 style : this.drawStyle
26 });
27 },
28
29 _formatTooltip : function(sketch, proj) {
30 var area;
31 if (this.isGeodesic) {
32 var geom = sketch.getGeometry().clone().transform(proj, 'EPSG:4326');
33 var coordinates = geom.getLinearRing(0).getCoordinates();
34 area = Math.abs(this.wgs84Sphere.geodesicArea(coordinates));
35 } else {
36 area = sketch.getGeometry().getArea();
37 }
38
39 var mpu, unitName;
40 switch (this.units) {
41 case "nautical":
42 mpu = 1852*1852;
43 unitName = units.nmiles2;
44 break;
45 default:
46 mpu = 1852*1852;
47 unitName = units.kilometers2;
48 }
49
50 if (area > mpu/10) {
51 return format(
52 "{0:#0.##} {1}",
53 area / mpu,
54 unitName);
55 } else {
56 return format("{0:#0.##} {1}", area, units.meters2);
57 }
58 }
59
60 });
61 });