c80_map 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.travis.yml +3 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +51 -0
- data/Rakefile +1 -0
- data/app/admin/c80_map/settings.rb +32 -0
- data/app/assets/javascripts/buttons/admin_buttons/button_back_to_map.js +48 -0
- data/app/assets/javascripts/buttons/admin_buttons/button_cancel_create.js +21 -0
- data/app/assets/javascripts/buttons/admin_buttons/button_complete_create.js +22 -0
- data/app/assets/javascripts/buttons/admin_buttons/button_edit.js +80 -0
- data/app/assets/javascripts/buttons/admin_buttons/button_new.js +46 -0
- data/app/assets/javascripts/buttons/admin_buttons/button_save.js +83 -0
- data/app/assets/javascripts/buttons/zoom_buttons.js +61 -0
- data/app/assets/javascripts/c80_map.js.coffee +11 -0
- data/app/assets/javascripts/events/app_event.js +15 -0
- data/app/assets/javascripts/map_objects/area.js +221 -0
- data/app/assets/javascripts/map_objects/building.js +309 -0
- data/app/assets/javascripts/map_objects/dot.js +14 -0
- data/app/assets/javascripts/src/main.js +992 -0
- data/app/assets/javascripts/src/state_controller.js +220 -0
- data/app/assets/javascripts/src/utils.js +127 -0
- data/app/assets/javascripts/svg_elements/helper.js +36 -0
- data/app/assets/javascripts/svg_elements/polygon.js +192 -0
- data/app/assets/javascripts/view/save_preloader.js +30 -0
- data/app/assets/stylesheets/c80_map.scss +2 -0
- data/app/assets/stylesheets/map.scss +1435 -0
- data/app/assets/stylesheets/view/save_preloader.scss +206 -0
- data/app/controllers/c80_map/application_controller.rb +6 -0
- data/app/controllers/c80_map/map_ajax_controller.rb +54 -0
- data/app/helpers/c80_map/application_helper.rb +33 -0
- data/app/models/c80_map/area.rb +5 -0
- data/app/models/c80_map/building.rb +73 -0
- data/app/models/c80_map/setting.rb +30 -0
- data/app/uploaders/c80_map/map_image_uploader.rb +31 -0
- data/app/views/c80_map/_map_row.html.erb +15 -0
- data/app/views/c80_map/_map_row_index.html.erb +39 -0
- data/app/views/c80_map/shared/_save_preloader.html.erb +3 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/c80_map.gemspec +25 -0
- data/config/routes.rb +3 -0
- data/db/migrate/20160617130000_create_c80_map_settings.rb +8 -0
- data/db/migrate/20160620040202_create_c80_map_areas.rb +9 -0
- data/db/migrate/20160620040204_create_c80_map_buildings.rb +8 -0
- data/db/seeds/801_fill_map_settings.rb +6 -0
- data/lib/c80_map/engine.rb +23 -0
- data/lib/c80_map/version.rb +3 -0
- data/lib/c80_map.rb +8 -0
- metadata +136 -0
@@ -0,0 +1,220 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
function StateController() {
|
4
|
+
|
5
|
+
var _map = null;
|
6
|
+
var _this = this;
|
7
|
+
|
8
|
+
_this.left_side = $("#left_side");
|
9
|
+
_this.right_side = $("#right_side");
|
10
|
+
_this.new_button = $('.mapplic-new-button');
|
11
|
+
_this.mzoom_buttons = $('.mzoom_buttons');
|
12
|
+
_this.map_creating = $('#map_creating');
|
13
|
+
_this.map_editing = $('#map_editing');
|
14
|
+
_this.main_map = $('.main_map');
|
15
|
+
_this.svg_overlay = $('#svg_overlay');
|
16
|
+
_this.building_info = $('.building_info');
|
17
|
+
_this.area_order_button = $('.area_order_button');
|
18
|
+
_this.masked = $('#masked');
|
19
|
+
|
20
|
+
_this.setMode = function (mode) {
|
21
|
+
|
22
|
+
// Должен быть учёт, из какого состояния пришли в состояние рисования, и возвращаться в него
|
23
|
+
// * При рисовании, находясь внутри здания, возвращаться в 'edit_building'
|
24
|
+
// * При рисовании, находясь внутри площади, возвращаться в 'edit_area'
|
25
|
+
// За исключением ситуации, когда начали редактировать, находясь на карте
|
26
|
+
if (mode == 'editing' && _map.prev_mode != 'viewing') {
|
27
|
+
mode = _map.prev_mode;
|
28
|
+
}
|
29
|
+
|
30
|
+
clog('<StateController.setMode> mode = ' + mode);
|
31
|
+
|
32
|
+
_map.prev_mode = _map.mode;
|
33
|
+
_map.mode = mode;
|
34
|
+
|
35
|
+
// этот код коррелирует с [x9cs7]. Возможно, нужен рефакторинг.
|
36
|
+
_map.container.removeClass("viewing");
|
37
|
+
_map.container.removeClass("editing");
|
38
|
+
_map.container.removeClass("creating");
|
39
|
+
_map.container.removeClass("view_building");
|
40
|
+
_map.container.removeClass("edit_building");
|
41
|
+
_map.container.removeClass("view_area");
|
42
|
+
_map.container.removeClass("edit_area");
|
43
|
+
_map.container.addClass(mode);
|
44
|
+
|
45
|
+
_this.checkMode();
|
46
|
+
};
|
47
|
+
|
48
|
+
_this.checkMode = function () {
|
49
|
+
|
50
|
+
if (_this.new_button.length == 0) _this.new_button = $('.mapplic-new-button');
|
51
|
+
if (_this.right_side.length == 0) _this.right_side = $('#right_side');
|
52
|
+
if (_this.left_side.length == 0) _this.left_side = $('#left_side');
|
53
|
+
if (_this.mzoom_buttons.length == 0) _this.mzoom_buttons = $('.mzoom_buttons');
|
54
|
+
if (_this.map_creating.length == 0) _this.map_creating = $('#map_creating');
|
55
|
+
if (_this.map_editing.length == 0) _this.map_editing = $('#map_editing');
|
56
|
+
if (_this.main_map.length == 0) _this.main_map = $('.main_map');
|
57
|
+
if (_this.svg_overlay.length == 0) _this.svg_overlay = $('#svg_overlay');
|
58
|
+
if (_this.building_info.length == 0) _this.building_info = $('.building_info');
|
59
|
+
if (_this.area_order_button.length == 0) _this.area_order_button = $('.area_order_button');
|
60
|
+
if (_this.masked.length == 0) _this.masked = $("#masked");
|
61
|
+
|
62
|
+
switch (_map.mode) {
|
63
|
+
|
64
|
+
// перешли в состояние
|
65
|
+
// редактирования карты
|
66
|
+
case "editing":
|
67
|
+
|
68
|
+
// спрячем надписи "цена за метр" и адрес с телефоном
|
69
|
+
_this.left_side.css("top", -300);
|
70
|
+
_this.right_side.css("top", -300);
|
71
|
+
|
72
|
+
// покажем кнопку "добавить фигуру"
|
73
|
+
_this.new_button.css('opacity', '1');
|
74
|
+
_this.new_button.removeClass('mapplic-disabled');
|
75
|
+
_map.new_button_klass.resetState();
|
76
|
+
|
77
|
+
// спрячем статусную область
|
78
|
+
_this.map_creating.css('display', 'none');
|
79
|
+
_this.map_editing.css('display', 'block');
|
80
|
+
|
81
|
+
// покажем кнопки, присущие этому режиму
|
82
|
+
_this.mzoom_buttons.css('opacity', '1');
|
83
|
+
|
84
|
+
_this.main_map.css('opacity', '1');
|
85
|
+
|
86
|
+
_map.save_button_klass.show();
|
87
|
+
_map.save_button_klass.check_and_enable();
|
88
|
+
|
89
|
+
break;
|
90
|
+
|
91
|
+
// перешли в состояние
|
92
|
+
// просмотра карты, все здания с крышами
|
93
|
+
case "viewing":
|
94
|
+
//clog("_this.left_side.data('init') = " + _this.left_side.data('init'));
|
95
|
+
|
96
|
+
// покажем надписи "цена за метр" и адрес с телефоном
|
97
|
+
if (_this.left_side.data('init') == undefined) {
|
98
|
+
_this.left_side.data('init', _this.left_side.css("top"));
|
99
|
+
}
|
100
|
+
if (_this.right_side.data('init') == undefined) {
|
101
|
+
_this.right_side.data('init', _this.right_side.css("top"));
|
102
|
+
}
|
103
|
+
_this.left_side.css("top", _this.left_side.data('init'));
|
104
|
+
_this.right_side.css("top", _this.right_side.data('init'));
|
105
|
+
|
106
|
+
_this.new_button.css('opacity', '0');
|
107
|
+
_this.new_button.addClass('mapplic-disabled');
|
108
|
+
_this.mzoom_buttons.css('opacity', '1');
|
109
|
+
|
110
|
+
_this.map_creating.css('display', 'none');
|
111
|
+
_this.map_editing.css('display', 'none');
|
112
|
+
|
113
|
+
_this.main_map.css('opacity', '1');
|
114
|
+
_this.svg_overlay.css('display', 'none');
|
115
|
+
|
116
|
+
if (_this.building_info.data("init") == undefined) {
|
117
|
+
_this.building_info.data('init', _this.building_info.css("top"));
|
118
|
+
}
|
119
|
+
_this.building_info.css("top", -300);
|
120
|
+
_this.building_info.css("display", "block");
|
121
|
+
|
122
|
+
_map.back_to_map_button_klass.hide();
|
123
|
+
_this.masked.addClass('hiddn');
|
124
|
+
|
125
|
+
_this.area_order_button.css('display', 'none');
|
126
|
+
|
127
|
+
// актуально, когда входим в это состояние
|
128
|
+
// из здания\площади, нажав кнопку "обратно на карту"
|
129
|
+
_map.edit_button_klass.setState('viewing', true); // [a1x7]
|
130
|
+
|
131
|
+
if (_map.save_button_klass) {
|
132
|
+
_map.save_button_klass.hide();
|
133
|
+
}
|
134
|
+
|
135
|
+
break;
|
136
|
+
|
137
|
+
// перешли в состояние рисования полигона
|
138
|
+
case "creating":
|
139
|
+
//_this.mzoom_buttons.css('opacity', '0');
|
140
|
+
_this.map_creating.css('display', 'block');
|
141
|
+
_this.map_editing.css('display', 'none');
|
142
|
+
|
143
|
+
_this.main_map.css('opacity', '1');
|
144
|
+
|
145
|
+
break;
|
146
|
+
|
147
|
+
// вошли в здание
|
148
|
+
case "view_building":
|
149
|
+
// спрячем надписи "цена за метр" и адрес с телефоном
|
150
|
+
_this.left_side.css("top", -300);
|
151
|
+
_this.right_side.css("top", -300);
|
152
|
+
|
153
|
+
//_this.main_map.css('opacity','0.7');
|
154
|
+
_this.svg_overlay.css('display', 'block');
|
155
|
+
|
156
|
+
_this.building_info.css("top", _this.building_info.data("init"));
|
157
|
+
_map.back_to_map_button_klass.show();
|
158
|
+
_this.masked.addClass('hiddn');
|
159
|
+
|
160
|
+
_this.area_order_button.css('display', 'none');
|
161
|
+
_map.edit_button_klass.setState('view_building', true); // [a1x7]
|
162
|
+
_map.current_building.resetOverlayZindex();
|
163
|
+
_map.save_button_klass.hide();
|
164
|
+
|
165
|
+
break;
|
166
|
+
|
167
|
+
// вошли в площадь
|
168
|
+
case "view_area":
|
169
|
+
_map.back_to_map_button_klass.show();
|
170
|
+
_this.masked.removeClass('hiddn');
|
171
|
+
var t = _this.building_info.height() + _this.building_info.offset().top;
|
172
|
+
var tt = _this.building_info.css("left");
|
173
|
+
var tq = (_this.building_info.width() + 40) + "px";
|
174
|
+
_this.area_order_button.css("top", t + "px");
|
175
|
+
// _this.area_order_button.css("bottom","400px");
|
176
|
+
_this.area_order_button.css("left", tt);
|
177
|
+
_this.area_order_button.css("width", tq);
|
178
|
+
_this.area_order_button.css('display', 'block');
|
179
|
+
_map.edit_button_klass.setState('view_area', true); // [a1x7]
|
180
|
+
break;
|
181
|
+
|
182
|
+
// редактируем, находясь в здании
|
183
|
+
case "edit_building":
|
184
|
+
_map.back_to_map_button_klass.hide();
|
185
|
+
|
186
|
+
// т.к. этот слой используется испключительно в помощь при рисовании обводки площадей
|
187
|
+
// и перехватывает клики при dnd, то тут он нам не нужен
|
188
|
+
_this.svg_overlay.css('display', 'none');
|
189
|
+
|
190
|
+
// заодно поменяем z-index слоёв с колоннами и слоя с svg
|
191
|
+
// полигонами площадей, чтобы можно было добраться мышкой
|
192
|
+
// до этих полигонов и редактировать их
|
193
|
+
_map.current_building.changeOverlayZindex();
|
194
|
+
|
195
|
+
// покажем кнопку "добавить фигуру"
|
196
|
+
_this.new_button.css('opacity', '1');
|
197
|
+
_this.new_button.removeClass('mapplic-disabled');
|
198
|
+
_map.new_button_klass.resetState();
|
199
|
+
|
200
|
+
// спрячем инфу о здании
|
201
|
+
_this.building_info.css("top", -300);
|
202
|
+
|
203
|
+
// спрячем статус строку "вы создаёте полигон"
|
204
|
+
_this.map_creating.css('display', 'none');
|
205
|
+
|
206
|
+
// покажем, возможно спрятанные, zoom кнопки
|
207
|
+
_this.mzoom_buttons.css('opacity', '1');
|
208
|
+
|
209
|
+
_map.save_button_klass.show();
|
210
|
+
_map.save_button_klass.check_and_enable();
|
211
|
+
|
212
|
+
break;
|
213
|
+
}
|
214
|
+
};
|
215
|
+
|
216
|
+
_this.init = function (link_to_map) {
|
217
|
+
_map = link_to_map;
|
218
|
+
}
|
219
|
+
|
220
|
+
}
|
@@ -0,0 +1,127 @@
|
|
1
|
+
|
2
|
+
var utils = {
|
3
|
+
|
4
|
+
offsetX: function (node) {
|
5
|
+
var box = node.getBoundingClientRect(),
|
6
|
+
scroll = window.pageXOffset;
|
7
|
+
|
8
|
+
return Math.round(box.left + scroll);
|
9
|
+
},
|
10
|
+
offsetY: function (node) {
|
11
|
+
var box = node.getBoundingClientRect(),
|
12
|
+
scroll = window.pageYOffset;
|
13
|
+
|
14
|
+
return Math.round(box.top + scroll);
|
15
|
+
},
|
16
|
+
|
17
|
+
trim: function (str) {
|
18
|
+
return str.replace(/^\s+|\s+$/g, '');
|
19
|
+
},
|
20
|
+
id: function (str) {
|
21
|
+
return document.getElementById(str);
|
22
|
+
},
|
23
|
+
hide: function (node) {
|
24
|
+
node.style.display = 'none';
|
25
|
+
|
26
|
+
return this;
|
27
|
+
},
|
28
|
+
show: function (node) {
|
29
|
+
node.style.display = 'block';
|
30
|
+
|
31
|
+
return this;
|
32
|
+
},
|
33
|
+
encode: function (str) {
|
34
|
+
return str.replace(/</g, '<').replace(/>/g, '>');
|
35
|
+
},
|
36
|
+
decode: function (str) {
|
37
|
+
return str.replace(/</g, '<').replace(/>/g, '>');
|
38
|
+
},
|
39
|
+
foreach: function (arr, func) {
|
40
|
+
for (var i = 0, count = arr.length; i < count; i++) {
|
41
|
+
func(arr[i], i);
|
42
|
+
}
|
43
|
+
},
|
44
|
+
foreachReverse: function (arr, func) {
|
45
|
+
for (var i = arr.length - 1; i >= 0; i--) {
|
46
|
+
func(arr[i], i);
|
47
|
+
}
|
48
|
+
},
|
49
|
+
debug: (function () {
|
50
|
+
var output = document.getElementById('debug');
|
51
|
+
return function () {
|
52
|
+
output.innerHTML = [].join.call(arguments, ' ');
|
53
|
+
}
|
54
|
+
})(),
|
55
|
+
stopEvent: function (e) {
|
56
|
+
e.stopPropagation();
|
57
|
+
e.preventDefault();
|
58
|
+
|
59
|
+
return this;
|
60
|
+
},
|
61
|
+
addClass: function (node, str) {
|
62
|
+
// node.className.baseVal for SVG-elements
|
63
|
+
// or
|
64
|
+
// node.className for HTML-elements
|
65
|
+
var is_svg = node.className.baseVal !== undefined ? true : false,
|
66
|
+
arr = is_svg ? node.className.baseVal.split(' ') : node.className.split(' '),
|
67
|
+
isset = false;
|
68
|
+
|
69
|
+
utils.foreach(arr, function (x) {
|
70
|
+
if (x === str) {
|
71
|
+
isset = true;
|
72
|
+
}
|
73
|
+
});
|
74
|
+
|
75
|
+
if (!isset) {
|
76
|
+
arr.push(str);
|
77
|
+
is_svg ? node.className.baseVal = arr.join(' ') : node.className = arr.join(' ');
|
78
|
+
}
|
79
|
+
|
80
|
+
return this;
|
81
|
+
},
|
82
|
+
removeClass: function (node, str) {
|
83
|
+
var is_svg = node.className.baseVal !== undefined ? true : false,
|
84
|
+
arr = is_svg ? node.className.baseVal.split(' ') : node.className.split(' '),
|
85
|
+
isset = false;
|
86
|
+
|
87
|
+
utils.foreach(arr, function (x, i) {
|
88
|
+
if (x === str) {
|
89
|
+
isset = true;
|
90
|
+
arr.splice(i--, 1);
|
91
|
+
}
|
92
|
+
});
|
93
|
+
|
94
|
+
if (isset) {
|
95
|
+
is_svg ? node.className.baseVal = arr.join(' ') : node.className = arr.join(' ');
|
96
|
+
}
|
97
|
+
|
98
|
+
return this;
|
99
|
+
},
|
100
|
+
hasClass: function (node, str) {
|
101
|
+
var is_svg = node.className.baseVal !== undefined ? true : false,
|
102
|
+
arr = is_svg ? node.className.baseVal.split(' ') : node.className.split(' '),
|
103
|
+
isset = false;
|
104
|
+
|
105
|
+
utils.foreach(arr, function (x) {
|
106
|
+
if (x === str) {
|
107
|
+
isset = true;
|
108
|
+
}
|
109
|
+
});
|
110
|
+
|
111
|
+
return isset;
|
112
|
+
},
|
113
|
+
extend: function (obj, options) {
|
114
|
+
var target = {};
|
115
|
+
|
116
|
+
for (var name in obj) {
|
117
|
+
if (obj.hasOwnProperty(name)) {
|
118
|
+
target[name] = options[name] ? options[name] : obj[name];
|
119
|
+
}
|
120
|
+
}
|
121
|
+
|
122
|
+
return target;
|
123
|
+
},
|
124
|
+
supportFileReader: (function () {
|
125
|
+
return (typeof FileReader !== 'undefined');
|
126
|
+
})()
|
127
|
+
};
|
@@ -0,0 +1,36 @@
|
|
1
|
+
|
2
|
+
/* Helper constructor */
|
3
|
+
function Helper(node, x, y) {
|
4
|
+
this.helper = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
|
5
|
+
this.helper.setAttribute('class', 'helper');
|
6
|
+
this.helper.setAttribute('height', 5);
|
7
|
+
this.helper.setAttribute('width', 5);
|
8
|
+
this.helper.setAttribute('x', x - 3);
|
9
|
+
this.helper.setAttribute('y', y - 3);
|
10
|
+
node.appendChild(this.helper);
|
11
|
+
}
|
12
|
+
|
13
|
+
Helper.prototype.setCoords = function (x, y) {
|
14
|
+
this.helper.setAttribute('x', x - 3);
|
15
|
+
this.helper.setAttribute('y', y - 3);
|
16
|
+
|
17
|
+
return this;
|
18
|
+
};
|
19
|
+
|
20
|
+
Helper.prototype.setAction = function (action) {
|
21
|
+
this.helper.action = action;
|
22
|
+
|
23
|
+
return this;
|
24
|
+
};
|
25
|
+
|
26
|
+
Helper.prototype.setCursor = function (cursor) {
|
27
|
+
utils.addClass(this.helper, cursor);
|
28
|
+
|
29
|
+
return this;
|
30
|
+
};
|
31
|
+
|
32
|
+
Helper.prototype.setId = function (id) {
|
33
|
+
this.helper.n = id;
|
34
|
+
|
35
|
+
return this;
|
36
|
+
};
|
@@ -0,0 +1,192 @@
|
|
1
|
+
/* Polygon constructor */
|
2
|
+
var Polygon = function (x, y, is_overlay, self) {
|
3
|
+
|
4
|
+
this._map = self;
|
5
|
+
this._map.is_draw = true;
|
6
|
+
|
7
|
+
this.params = [x, y]; //array of coordinates of polygon points
|
8
|
+
|
9
|
+
this.g = document.createElementNS('http://www.w3.org/2000/svg', 'g');
|
10
|
+
this.polygon = document.createElementNS('http://www.w3.org/2000/svg', 'polyline');
|
11
|
+
this._map.addNodeToSvg(this.g, is_overlay);
|
12
|
+
this.g.appendChild(this.polygon);
|
13
|
+
|
14
|
+
this.g.obj = this;
|
15
|
+
/* Link to parent object */
|
16
|
+
|
17
|
+
this.helpers = [ //array of all helpers-rectangles
|
18
|
+
new Helper(this.g, this.params[0], this.params[1])
|
19
|
+
];
|
20
|
+
|
21
|
+
this.helpers[0].setAction('pointMove').setCursor('pointer').setId(0);
|
22
|
+
|
23
|
+
this.selected_point = -1;
|
24
|
+
|
25
|
+
this.select().redraw();
|
26
|
+
|
27
|
+
// app.addObject(this); //add this object to array of all objects
|
28
|
+
};
|
29
|
+
|
30
|
+
Polygon.prototype.setCoords = function (params) {
|
31
|
+
//console.log(params);
|
32
|
+
var coords_values = params.join(' ');
|
33
|
+
this.polygon.setAttribute('points', coords_values);
|
34
|
+
utils.foreach(this.helpers, function (x, i) {
|
35
|
+
x.setCoords(params[2 * i], params[2 * i + 1]);
|
36
|
+
});
|
37
|
+
|
38
|
+
return this;
|
39
|
+
};
|
40
|
+
|
41
|
+
Polygon.prototype.setParams = function (arr) {
|
42
|
+
this.params = Array.prototype.slice.call(arr);
|
43
|
+
|
44
|
+
return this;
|
45
|
+
};
|
46
|
+
|
47
|
+
Polygon.prototype.addPoint = function (x, y) {
|
48
|
+
var helper = new Helper(this.g, x, y);
|
49
|
+
helper.setAction('pointMove').setCursor('pointer').setId(this.helpers.length);
|
50
|
+
this.helpers.push(helper);
|
51
|
+
this.params.push(x, y);
|
52
|
+
this.redraw();
|
53
|
+
|
54
|
+
return this;
|
55
|
+
};
|
56
|
+
|
57
|
+
Polygon.prototype.redraw = function () {
|
58
|
+
this.setCoords(this.params);
|
59
|
+
|
60
|
+
return this;
|
61
|
+
};
|
62
|
+
|
63
|
+
Polygon.prototype.right_angle = function (x, y) {
|
64
|
+
var old_x = this.params[this.params.length - 2],
|
65
|
+
old_y = this.params[this.params.length - 1],
|
66
|
+
dx = x - old_x,
|
67
|
+
dy = -(y - old_y),
|
68
|
+
tan = dy / dx; //tangens
|
69
|
+
|
70
|
+
if (dx > 0 && dy > 0) {
|
71
|
+
if (tan > 2.414) {
|
72
|
+
x = old_x;
|
73
|
+
} else if (tan < 0.414) {
|
74
|
+
y = old_y;
|
75
|
+
} else {
|
76
|
+
Math.abs(dx) > Math.abs(dy) ? x = old_x + dy : y = old_y - dx;
|
77
|
+
}
|
78
|
+
} else if (dx < 0 && dy > 0) {
|
79
|
+
if (tan < -2.414) {
|
80
|
+
x = old_x;
|
81
|
+
} else if (tan > -0.414) {
|
82
|
+
y = old_y;
|
83
|
+
} else {
|
84
|
+
Math.abs(dx) > Math.abs(dy) ? x = old_x - dy : y = old_y + dx;
|
85
|
+
}
|
86
|
+
} else if (dx < 0 && dy < 0) {
|
87
|
+
if (tan > 2.414) {
|
88
|
+
x = old_x;
|
89
|
+
} else if (tan < 0.414) {
|
90
|
+
y = old_y;
|
91
|
+
} else {
|
92
|
+
Math.abs(dx) > Math.abs(dy) ? x = old_x + dy : y = old_y - dx;
|
93
|
+
}
|
94
|
+
} else if (dx > 0 && dy < 0) {
|
95
|
+
if (tan < -2.414) {
|
96
|
+
x = old_x;
|
97
|
+
} else if (tan > -0.414) {
|
98
|
+
y = old_y;
|
99
|
+
} else {
|
100
|
+
Math.abs(dx) > Math.abs(dy) ? x = old_x - dy : y = old_y + dx;
|
101
|
+
}
|
102
|
+
}
|
103
|
+
|
104
|
+
return {
|
105
|
+
x: x,
|
106
|
+
y: y
|
107
|
+
};
|
108
|
+
};
|
109
|
+
|
110
|
+
Polygon.prototype.dynamicDraw = function (x, y, right_angle) {
|
111
|
+
var temp_params = [].concat(this.params);
|
112
|
+
|
113
|
+
if (right_angle) {
|
114
|
+
var right_coords = this.right_angle(x, y);
|
115
|
+
x = right_coords.x;
|
116
|
+
y = right_coords.y;
|
117
|
+
}
|
118
|
+
|
119
|
+
temp_params.push(x, y);
|
120
|
+
|
121
|
+
this.setCoords(temp_params);
|
122
|
+
|
123
|
+
return temp_params;
|
124
|
+
};
|
125
|
+
|
126
|
+
Polygon.prototype.move = function (x, y) { //offset x and y
|
127
|
+
var temp_params = Object.create(this.params);
|
128
|
+
|
129
|
+
for (var i = 0, count = this.params.length; i < count; i++) {
|
130
|
+
//i % 2 ? this.params[i] += y : this.params[i] += x;
|
131
|
+
if (i % 2) {
|
132
|
+
this.params[i] = Number(this.params[i]) + y;
|
133
|
+
} else {
|
134
|
+
this.params[i] = Number(this.params[i]) + x;
|
135
|
+
}
|
136
|
+
}
|
137
|
+
|
138
|
+
return temp_params;
|
139
|
+
};
|
140
|
+
|
141
|
+
Polygon.prototype.pointMove = function (x, y) { //offset x and y
|
142
|
+
this.params[2 * this.selected_point] += x;
|
143
|
+
this.params[2 * this.selected_point + 1] += y;
|
144
|
+
|
145
|
+
return this.params;
|
146
|
+
};
|
147
|
+
|
148
|
+
Polygon.prototype.dynamicEdit = function (temp_params) {
|
149
|
+
this.setCoords(temp_params);
|
150
|
+
|
151
|
+
return temp_params;
|
152
|
+
};
|
153
|
+
|
154
|
+
Polygon.prototype.remove = function () {
|
155
|
+
this._map.removeNodeFromSvg(this.g);
|
156
|
+
};
|
157
|
+
|
158
|
+
Polygon.prototype.select = function () {
|
159
|
+
utils.addClass(this.polygon, 'selected');
|
160
|
+
|
161
|
+
return this;
|
162
|
+
};
|
163
|
+
|
164
|
+
Polygon.prototype.deselect = function () {
|
165
|
+
utils.removeClass(this.polygon, 'selected');
|
166
|
+
|
167
|
+
return this;
|
168
|
+
};
|
169
|
+
|
170
|
+
Polygon.createFromSaved = function (params, is_overlay, self) {
|
171
|
+
//console.log("<Polygon.createFromSaved>");
|
172
|
+
console.log("<Polygon.createFromSaved> is_overlay = " + is_overlay);
|
173
|
+
|
174
|
+
var coords = params.coords,
|
175
|
+
area = new Polygon(coords[0], coords[1], is_overlay, self);
|
176
|
+
|
177
|
+
for (var i = 2, c = coords.length; i < c; i += 2) {
|
178
|
+
area.addPoint(coords[i], coords[i + 1]);
|
179
|
+
}
|
180
|
+
|
181
|
+
area.polyline = area.polygon;
|
182
|
+
area.polygon = document.createElementNS('http://www.w3.org/2000/svg', 'polygon');
|
183
|
+
area.g.replaceChild(area.polygon, area.polyline);
|
184
|
+
area.setCoords(area.params).deselect();
|
185
|
+
delete(area.polyline);
|
186
|
+
|
187
|
+
self.is_draw = false;
|
188
|
+
self.drawing_poligon = null;
|
189
|
+
|
190
|
+
return area;
|
191
|
+
|
192
|
+
};
|
@@ -0,0 +1,30 @@
|
|
1
|
+
function SavePreloader() {
|
2
|
+
|
3
|
+
var _this = this;
|
4
|
+
var $el;
|
5
|
+
|
6
|
+
_this.init = function () {
|
7
|
+
$el = $("#savePreloader");
|
8
|
+
};
|
9
|
+
|
10
|
+
_this.show = function () {
|
11
|
+
$el.css("display","block");
|
12
|
+
$el.addClass('shown');
|
13
|
+
};
|
14
|
+
|
15
|
+
_this.hide = function () {
|
16
|
+
$el.removeClass('shown');
|
17
|
+
setTimeout(function () {
|
18
|
+
$el.css("display","none");
|
19
|
+
},500);
|
20
|
+
};
|
21
|
+
|
22
|
+
_this.toggle = function () {
|
23
|
+
if ($el.hasClass('shown')) {
|
24
|
+
_this.hide();
|
25
|
+
} else {
|
26
|
+
_this.show();
|
27
|
+
}
|
28
|
+
};
|
29
|
+
|
30
|
+
}
|