Mercurial > pub > ImplabJs
comparison src/djol/MeasureToolBase.js @ 34:27e8e9e38e07 default tip
Слияние
author | nickolay |
---|---|
date | Wed, 05 Jun 2019 20:44:15 +0300 |
parents | 8af8e840dd49 1dc2fd263b90 |
children |
comparison
equal
deleted
inserted
replaced
33:8af8e840dd49 | 34:27e8e9e38e07 |
---|---|
1 define([ | |
2 "dojo/_base/declare", | |
3 "implab/safe", | |
4 "ol", | |
5 "./listen", | |
6 "./_ToolBase", | |
7 "dojo/dom-construct", | |
8 "dojo/dom-class" | |
9 ], function (declare, safe, ol, listen, _ToolBase, dconstruct, dclass) { | |
10 return declare([_ToolBase], { | |
11 _draw: null, | |
12 | |
13 drawStyle: new ol.style.Style({ | |
14 fill: new ol.style.Fill({ | |
15 color: 'rgba(255, 255, 255, 0.2)' | |
16 }), | |
17 stroke: new ol.style.Stroke({ | |
18 color: 'rgba(230, 126, 34, 0.7)', | |
19 lineDash: [10, 10], | |
20 width: 2 | |
21 }), | |
22 image: new ol.style.Circle({ | |
23 radius: 5, | |
24 stroke: new ol.style.Stroke({ | |
25 color: 'rgba(0, 0, 0, 0.7)' | |
26 }), | |
27 fill: new ol.style.Fill({ | |
28 color: 'rgba(255, 255, 255, 0.2)' | |
29 }) | |
30 }) | |
31 }), | |
32 | |
33 vectorStyle: new ol.style.Style({ | |
34 fill: new ol.style.Fill({ | |
35 color: 'rgba(255, 255, 255, 0.2)' | |
36 }), | |
37 stroke: new ol.style.Stroke({ | |
38 color: '#ffcc33', | |
39 width: 2 | |
40 }), | |
41 image: new ol.style.Circle({ | |
42 radius: 7, | |
43 fill: new ol.style.Fill({ | |
44 color: '#ffcc33' | |
45 }) | |
46 }) | |
47 }), | |
48 | |
49 _map: null, | |
50 | |
51 _olMap: null, | |
52 | |
53 _measureTooltipElement: null, | |
54 /** | |
55 * Overlay to show the measurement. | |
56 * | |
57 * @type {ol.Overlay} | |
58 */ | |
59 _measureTooltip: null, | |
60 | |
61 _pointermoveKey: null, | |
62 | |
63 _sketch: null, | |
64 | |
65 _overlays: null, | |
66 | |
67 _vector: null, | |
68 | |
69 wgs84Sphere: new ol.Sphere(6378137), | |
70 | |
71 constructor: function (options) { | |
72 safe.argumentNotNull(options, "options"); | |
73 safe.argumentNotNull(options.map, "map"); | |
74 | |
75 this._map = options.map; | |
76 this._olMap = options.map.olMap; | |
77 this._overlays = []; | |
78 }, | |
79 | |
80 init: function () { | |
81 if (this._draw) | |
82 return; | |
83 | |
84 var source = new ol.source.Vector(); | |
85 | |
86 this._vector = new ol.layer.Vector({ | |
87 source: source, | |
88 style: this.vectorStyle | |
89 }); | |
90 this._map.addLayer(this._vector); | |
91 | |
92 this._draw = this._createDraw(source); | |
93 this._draw.on('drawstart', this._onDrawStart, this); | |
94 this._draw.on('drawend', this._onDrawEnd, this); | |
95 | |
96 }, | |
97 | |
98 onActivating: function () { | |
99 this.init(); | |
100 | |
101 this._pointermoveKey = listen(this._olMap, 'pointermove', safe.delegate(this, "_onPointerMove")); | |
102 this._olMap.addInteraction(this._draw); | |
103 | |
104 return this.inherited(arguments); | |
105 }, | |
106 | |
107 onDeactivating: function () { | |
108 // отключаем рисование и получение сообщений | |
109 if (this._pointermoveKey) | |
110 this._pointermoveKey.remove(); | |
111 this._olMap.removeInteraction(this._draw); | |
112 | |
113 // если был активен инструмент | |
114 if (this._sketch) { | |
115 // убиваем подсказку и сбрасываем текущее рисование | |
116 this._sketch = null; | |
117 this._measureTooltipElement = null; | |
118 this._olMap.removeOverlay(this._measureTooltip); | |
119 } | |
120 | |
121 return this.inherited(arguments); | |
122 }, | |
123 | |
124 clear: function () { | |
125 var me = this; | |
126 me.log("clear"); | |
127 if (me._vector) { | |
128 me._vector.getSource().clear(); | |
129 me._overlays.forEach(function (x) { | |
130 me._olMap.removeOverlay(x); | |
131 }); | |
132 } | |
133 }, | |
134 | |
135 _createMeasureTooltip: function () { | |
136 this._measureTooltipElement = dconstruct.create("div", { | |
137 "class": 'tooltip poisk-measure-tooltip' | |
138 }); | |
139 this._measureTooltip = new ol.Overlay({ | |
140 element: this._measureTooltipElement, | |
141 offset: [0, -15], | |
142 positioning: 'bottom-center' | |
143 }); | |
144 this._olMap.addOverlay(this._measureTooltip); | |
145 | |
146 }, | |
147 | |
148 _onDrawStart: function (evt) { | |
149 this._sketch = evt.feature; | |
150 this._createMeasureTooltip(); | |
151 }, | |
152 | |
153 _onDrawEnd: function (evt) { | |
154 | |
155 this._measureTooltip.setOffset([0, -7]); | |
156 | |
157 dclass.remove(this._measureTooltipElement, "tooltip"); | |
158 dclass.add(this._measureTooltipElement, "tooltip-static"); | |
159 | |
160 this._overlays.push(this._measureTooltip); | |
161 | |
162 this._sketch = null; | |
163 this._measureTooltip = null; | |
164 this._measureTooltipElement = null; | |
165 }, | |
166 | |
167 _onPointerMove: function (evt) { | |
168 if (this._sketch && !evt.dragging) { | |
169 this._measureTooltip.setPosition(evt.coordinate); | |
170 this._measureTooltipElement.innerHTML = this._formatTooltip( | |
171 this._sketch, | |
172 this._olMap.getView().getProjection()); | |
173 } | |
174 }, | |
175 | |
176 _formatTooltip: function (sketch, proj) { | |
177 | |
178 } | |
179 }); | |
180 | |
181 }); |