1 |
|
---|
2 | function MapEditorHistory(mapEditor) {
|
---|
3 | this.prevOverlays = [];
|
---|
4 | this.presentOverlays = [];
|
---|
5 | this.undoneOverlays = [];
|
---|
6 | this.cycleCompvare = true;
|
---|
7 | this.mapEditor = mapEditor;
|
---|
8 | }
|
---|
9 |
|
---|
10 | MapEditorHistory.prototype.undo = function () {
|
---|
11 |
|
---|
12 | for (var i = 0; i < this.mapEditor.overlays.length; i++) {
|
---|
13 | this.mapEditor.overlays[i].setMap(null);
|
---|
14 | }
|
---|
15 | if (this.prevOverlays.length != 0) {
|
---|
16 | this.mapEditor.selectedShapes = [];
|
---|
17 | this.mapEditor.overlays = [];
|
---|
18 | this.undoneOverlaysPush();
|
---|
19 | var prev_overlay = this.prevOverlays.pop();
|
---|
20 | var draggableCB = document.querySelector("input[name=draggableCB]").checked = false;
|
---|
21 |
|
---|
22 |
|
---|
23 | if (prev_overlay.length > 0) {
|
---|
24 | for (var i = 0; i < prev_overlay.length; i++) {
|
---|
25 | this.mapEditor.overlays[i] = prev_overlay[i];
|
---|
26 | this.mapEditor.overlays[i].setMap(this.mapEditor.map);
|
---|
27 | this.mapEditor.overlays[i].draggable = true;
|
---|
28 | }
|
---|
29 | }
|
---|
30 | }
|
---|
31 | };
|
---|
32 |
|
---|
33 | MapEditorHistory.prototype.redo = function () {
|
---|
34 |
|
---|
35 | if (this.undoneOverlays.length != 0) {
|
---|
36 | var draggableCB = document.querySelector("input[name=draggableCB]").checked = false;
|
---|
37 | this.mapEditor.selectedShapes = [];
|
---|
38 | for (var i = 0; i < this.mapEditor.overlays.length; i++) {
|
---|
39 | this.mapEditor.overlays[i].setMap(null);
|
---|
40 | }
|
---|
41 |
|
---|
42 | this.mapEditor.overlays = [];
|
---|
43 | var lastEntry = this.undoneOverlays[this.undoneOverlays.length - 1];
|
---|
44 | for (var i = 0; i < lastEntry.length; i++) {
|
---|
45 | this.mapEditor.overlays[i] = lastEntry[i];
|
---|
46 | this.mapEditor.overlays[i].setMap(this.mapEditor.map);
|
---|
47 | this.mapEditor.overlays[i].draggable = true;
|
---|
48 | }
|
---|
49 |
|
---|
50 | var conditionPrevious = this.presentOverlays[0];
|
---|
51 | if (conditionPrevious !== undefined) {
|
---|
52 | if (conditionPrevious.length == 0) {
|
---|
53 | this.prevOverlays.push(this.presentOverlays[0]);
|
---|
54 | } else {
|
---|
55 | var overlays_copy = [];
|
---|
56 | for (var i = 0; i < this.presentOverlays[0].length; i++) {
|
---|
57 | var clone_shape = ShapesUtil.cloneShape(this.presentOverlays[0][i]);
|
---|
58 | if (ShapesUtil.overlayItemIsShape(clone_shape)) {
|
---|
59 | this.mapEditor.addShapeListeners(clone_shape, null);
|
---|
60 | } else {
|
---|
61 | this.mapEditor.addMarkerListeners(clone_shape, null);
|
---|
62 | }
|
---|
63 | overlays_copy[i] = clone_shape;
|
---|
64 | }
|
---|
65 | this.prevOverlays.push(overlays_copy);
|
---|
66 | }
|
---|
67 | }
|
---|
68 | this.presentOverlays = [];
|
---|
69 | this.presentOverlays.push(this.undoneOverlays[this.undoneOverlays.length - 1]);
|
---|
70 | this.undoneOverlays.pop();
|
---|
71 | }
|
---|
72 | }
|
---|
73 |
|
---|
74 | /*
|
---|
75 | MapEditorHistory.prototype.clonePath = function (path) {
|
---|
76 | var clone_path = [];
|
---|
77 |
|
---|
78 | for (var i = 0; i < path.length; i++) {
|
---|
79 | var lati = path.getAt(i).lat();
|
---|
80 | var lngi = path.getAt(i).lng();
|
---|
81 | clone_lat_lng = {
|
---|
82 | lat: lati,
|
---|
83 | lng: lngi
|
---|
84 | };
|
---|
85 | clone_path.push(clone_lat_lng);
|
---|
86 | }
|
---|
87 |
|
---|
88 | return clone_path;
|
---|
89 | }
|
---|
90 |
|
---|
91 | MapEditorHistory.prototype.clonePolyline = function (polyline) {
|
---|
92 | var geodesic = polyline.geodesic;
|
---|
93 | var strokeColor = polyline.strokeColor;
|
---|
94 | var strokeOpacity = polyline.strokeOpacity;
|
---|
95 | var strokeWeight = polyline.strokeWeight;
|
---|
96 | //var clone_path = clonePath(path);
|
---|
97 |
|
---|
98 | var clone_path = null;
|
---|
99 |
|
---|
100 | var JSONSave = typeof polyline.getPath !== "function";
|
---|
101 | //console.log(JSONSave)
|
---|
102 | if(JSONSave){
|
---|
103 | var path = polyline.latLngs.j[0].j;
|
---|
104 | clone_path = path;
|
---|
105 |
|
---|
106 | } else{
|
---|
107 | var path = polyline.getPath();
|
---|
108 | clone_path = this.clonePath(path);
|
---|
109 | }
|
---|
110 | var clone_polyline = new google.maps.Polyline({
|
---|
111 | geodesic: geodesic,
|
---|
112 | strokeColor: strokeColor,
|
---|
113 | strokeOpacity: strokeOpacity,
|
---|
114 | strokeWeight: strokeWeight,
|
---|
115 | path: clone_path,
|
---|
116 | draggable: true,
|
---|
117 | editable: false
|
---|
118 | });
|
---|
119 |
|
---|
120 | clone_polyline.type = google.maps.drawing.OverlayType.POLYLINE;
|
---|
121 |
|
---|
122 | return clone_polyline;
|
---|
123 | }
|
---|
124 |
|
---|
125 | MapEditorHistory.prototype.clonePolygon = function (polygon) {
|
---|
126 | var geodesic = polygon.geodesic;
|
---|
127 | var strokeColor = polygon.strokeColor;
|
---|
128 | var strokeOpacity = polygon.strokeOpacity;
|
---|
129 | var strokeWeight = polygon.strokeWeight;
|
---|
130 | var fillColor = polygon.fillColor;
|
---|
131 | var fillOpacity = polygon.fillOpacity;
|
---|
132 |
|
---|
133 | var clone_path = null;
|
---|
134 | var JSONSave = typeof polygon.getPath !== "function";
|
---|
135 | //console.log(JSONSave)
|
---|
136 | if(JSONSave){
|
---|
137 | var path = polygon.latLngs.j[0].j;
|
---|
138 | clone_path = path;
|
---|
139 |
|
---|
140 | } else{
|
---|
141 | var path = polygon.getPath();
|
---|
142 | clone_path = this.clonePath(path);
|
---|
143 | console.log(path);
|
---|
144 | }
|
---|
145 | var clone_polygon = new google.maps.Polygon({
|
---|
146 | geodesic: geodesic,
|
---|
147 | strokeColor: strokeColor,
|
---|
148 | strokeOpacity: strokeOpacity,
|
---|
149 | strokeWeight: strokeWeight,
|
---|
150 | fillColor: fillColor,
|
---|
151 | fillOpacity: fillOpacity,
|
---|
152 | path: clone_path,
|
---|
153 | draggable: true,
|
---|
154 | editable: false
|
---|
155 | });
|
---|
156 | clone_polygon.type = google.maps.drawing.OverlayType.POLYGON;
|
---|
157 | return clone_polygon;
|
---|
158 | }
|
---|
159 |
|
---|
160 | MapEditorHistory.prototype.cloneRectangle = function (rect) {
|
---|
161 | var strokeColor = rect.strokeColor;
|
---|
162 | var strokeOpacity = rect.strokeOpacity;
|
---|
163 | var strokeWeight = rect.strokeWeight;
|
---|
164 | var fillColor = rect.fillColor;
|
---|
165 | var fillOpacity = rect.fillOpacity;
|
---|
166 | //var bounds = rect.getBounds();
|
---|
167 | var type = rect.type;
|
---|
168 |
|
---|
169 | var bounds = null;
|
---|
170 |
|
---|
171 | var JSONSave = typeof rect.getBounds !== "function";
|
---|
172 |
|
---|
173 | if(JSONSave){
|
---|
174 | var north = rect.bounds.north;
|
---|
175 | var south = rect.bounds.south;
|
---|
176 | var east = rect.bounds.east;
|
---|
177 | var west = rect.bounds.west;
|
---|
178 | if (!isNaN(north) && !isNaN(south) && !isNaN(west) && !isNaN(east)) {
|
---|
179 | var NE = new google.maps.LatLng(north, east);
|
---|
180 | var SW = new google.maps.LatLng(south, west);
|
---|
181 | bounds = new google.maps.LatLngBounds(SW, NE);
|
---|
182 | }
|
---|
183 | } else {
|
---|
184 | bounds = rect.getBounds();
|
---|
185 | }
|
---|
186 | var clone_rect = new google.maps.Rectangle({
|
---|
187 | strokeColor: strokeColor,
|
---|
188 | strokeOpacity: strokeOpacity,
|
---|
189 | strokeWeight: strokeWeight,
|
---|
190 | fillColor: fillColor,
|
---|
191 | fillOpacity: fillOpacity,
|
---|
192 | bounds: bounds,
|
---|
193 | draggable: true,
|
---|
194 | editable: false,
|
---|
195 | type: type
|
---|
196 | });
|
---|
197 |
|
---|
198 | clone_rect.type = google.maps.drawing.OverlayType.RECTANGLE;
|
---|
199 | return clone_rect;
|
---|
200 | }
|
---|
201 |
|
---|
202 | MapEditorHistory.prototype.cloneCircle = function (circ) {
|
---|
203 | var strokeColor = circ.strokeColor;
|
---|
204 | var strokeOpacity = circ.strokeOpacity;
|
---|
205 | var strokeWeight = circ.strokeWeight;
|
---|
206 | var fillColor = circ.fillColor;
|
---|
207 | var fillOpacity = circ.fillOpacity;
|
---|
208 | var center = circ.center;
|
---|
209 | var radius = circ.radius;
|
---|
210 |
|
---|
211 | var clone_circ = new google.maps.Circle({
|
---|
212 | strokeColor: strokeColor,
|
---|
213 | strokeOpacity: strokeOpacity,
|
---|
214 | strokeWeight: strokeWeight,
|
---|
215 | fillColor: fillColor,
|
---|
216 | fillOpacity: fillOpacity,
|
---|
217 | center: center,
|
---|
218 | radius: radius,
|
---|
219 | draggable: true,
|
---|
220 | editable: false
|
---|
221 | });
|
---|
222 |
|
---|
223 | clone_circ.type = google.maps.drawing.OverlayType.CIRCLE;
|
---|
224 |
|
---|
225 | return clone_circ;
|
---|
226 | }
|
---|
227 |
|
---|
228 | MapEditorHistory.prototype.cloneMarker = function (marker) {
|
---|
229 | var anchorPoint = marker.anchorPoint;
|
---|
230 | var JSONSave = typeof marker.getPosition !== "function";
|
---|
231 | if(JSONSave){
|
---|
232 | var position = marker.position;
|
---|
233 | } else{
|
---|
234 | var position = marker.getPosition();
|
---|
235 | }
|
---|
236 | var clone_marker = new google.maps.Marker({
|
---|
237 | anchorPoint: anchorPoint,
|
---|
238 | position: position,
|
---|
239 | clickable: true,
|
---|
240 | draggable: true,
|
---|
241 | editable: false
|
---|
242 | })
|
---|
243 | clone_marker.type = google.maps.drawing.OverlayType.MARKER;
|
---|
244 |
|
---|
245 | return clone_marker;
|
---|
246 | }
|
---|
247 |
|
---|
248 | MapEditorHistory.prototype.cloneShape = function (shape) {
|
---|
249 | if (shape.type === google.maps.drawing.OverlayType.POLYLINE) {
|
---|
250 | var clone_polyline = this.clonePolyline(shape);
|
---|
251 | return clone_polyline;
|
---|
252 | } else if (shape.type === google.maps.drawing.OverlayType.POLYGON) {
|
---|
253 | var clone_polygon = this.clonePolygon(shape);
|
---|
254 | return clone_polygon;
|
---|
255 | } else if (shape.type === google.maps.drawing.OverlayType.RECTANGLE) {
|
---|
256 | var clone_rect = this.cloneRectangle(shape);
|
---|
257 | return clone_rect;
|
---|
258 |
|
---|
259 | } else if (shape.type === google.maps.drawing.OverlayType.CIRCLE) {
|
---|
260 | var clone_circ = this.cloneCircle(shape);
|
---|
261 | return clone_circ;
|
---|
262 |
|
---|
263 | } else {
|
---|
264 | var clone_marker = this.cloneMarker(shape);
|
---|
265 | return clone_marker;
|
---|
266 | }
|
---|
267 | }
|
---|
268 |
|
---|
269 | MapEditorHistory.prototype.overlayItemIsShape = function (overlay_item) {
|
---|
270 | var type = overlay_item.type;
|
---|
271 |
|
---|
272 | is_shape = (type === google.maps.drawing.OverlayType.POLYLINE)
|
---|
273 | || (type === google.maps.drawing.OverlayType.POLYGON)
|
---|
274 | || (type === google.maps.drawing.OverlayType.RECTANGLE)
|
---|
275 | || (type === google.maps.drawing.OverlayType.CIRCLE);
|
---|
276 |
|
---|
277 | return is_shape;
|
---|
278 | }
|
---|
279 |
|
---|
280 | */
|
---|
281 |
|
---|
282 | MapEditorHistory.prototype.historyOverlayPush = function () {
|
---|
283 |
|
---|
284 |
|
---|
285 | if (this.cycleCompvare) {
|
---|
286 |
|
---|
287 | var overlays_copy = [];
|
---|
288 | for (var i = 0; i < this.mapEditor.overlays.length; i++) {
|
---|
289 | var clone_shape = ShapesUtil.cloneShape(this.mapEditor.overlays[i]);
|
---|
290 | if (ShapesUtil.overlayItemIsShape(clone_shape)) {
|
---|
291 | this.mapEditor.addShapeListeners(clone_shape, null); // don't have an overlay event!
|
---|
292 | } else {
|
---|
293 | this.mapEditor.addMarkerListeners(clone_shape, null); // don't have an overlay event!
|
---|
294 | }
|
---|
295 | overlays_copy[i] = clone_shape;
|
---|
296 | }
|
---|
297 | this.undoneOverlays = [];
|
---|
298 | this.prevOverlays.push(overlays_copy);
|
---|
299 | }
|
---|
300 |
|
---|
301 | this.cycleCompvare = false;
|
---|
302 | }
|
---|
303 |
|
---|
304 | MapEditorHistory.prototype.presentOverlayPush = function () {
|
---|
305 | // console.log("presentOverlayPush");
|
---|
306 |
|
---|
307 | this.presentOverlays = [];
|
---|
308 | var overlays_copy = [];
|
---|
309 | for (var i = 0; i < this.mapEditor.overlays.length; i++) {
|
---|
310 | var clone_shape = ShapesUtil.cloneShape(this.mapEditor.overlays[i]);
|
---|
311 | if (ShapesUtil.overlayItemIsShape(clone_shape)) {
|
---|
312 | this.mapEditor.addShapeListeners(clone_shape, null); // don't have an overlay event!
|
---|
313 | } else {
|
---|
314 | this.mapEditor.addMarkerListeners(clone_shape, null); // don't have an overlay event!
|
---|
315 | }
|
---|
316 | overlays_copy[i] = clone_shape;
|
---|
317 | }
|
---|
318 | this.presentOverlays.push(overlays_copy);
|
---|
319 | this.cycleCompvare = true;
|
---|
320 |
|
---|
321 |
|
---|
322 | }
|
---|
323 |
|
---|
324 | MapEditorHistory.prototype.undoneOverlaysPush = function () {
|
---|
325 |
|
---|
326 | var conditionUndone = this.presentOverlays[this.presentOverlays.length - 1] !== undefined;
|
---|
327 |
|
---|
328 | if (conditionUndone) {
|
---|
329 | var overlays_copy = [];
|
---|
330 | for (var i = 0; i < this.presentOverlays[0].length; i++) {
|
---|
331 | var clone_shape = ShapesUtil.cloneShape(this.presentOverlays[0][i]);
|
---|
332 | if (ShapesUtil.overlayItemIsShape(clone_shape)) {
|
---|
333 | this.mapEditor.addShapeListeners(clone_shape, null); // don't have an overlay event!
|
---|
334 | } else {
|
---|
335 | this.mapEditor.addMarkerListeners(clone_shape, null); // don't have an overlay event!
|
---|
336 | }
|
---|
337 | overlays_copy[i] = clone_shape;
|
---|
338 | }
|
---|
339 | this.undoneOverlays.push(overlays_copy);
|
---|
340 | }
|
---|
341 |
|
---|
342 | var conditionPresent = this.prevOverlays[this.prevOverlays.length - 1] !== undefined;
|
---|
343 |
|
---|
344 | if (conditionPresent) {
|
---|
345 | this.presentOverlays = [];
|
---|
346 | var overlays_copy = [];
|
---|
347 | for (var i = 0; i < this.prevOverlays[this.prevOverlays.length - 1].length; i++) {
|
---|
348 | var clone_shape = cloneShape(this.prevOverlays[this.prevOverlays.length - 1][i]);
|
---|
349 | if (ShapesUtil.overlayItemIsShape(clone_shape)) {
|
---|
350 | this.mapEditor.addShapeListeners(clone_shape, null); // don't have an overlay event!
|
---|
351 | } else {
|
---|
352 | this.mapEditor.addMarkerListeners(clone_shape, null); // don't have an overlay event!
|
---|
353 | }
|
---|
354 | overlays_copy[i] = clone_shape;
|
---|
355 | }
|
---|
356 | this.presentOverlays.push(overlays_copy);
|
---|
357 | }
|
---|
358 | }
|
---|
359 |
|
---|
360 | MapEditorHistory.prototype.undoneOverlaysPush = function () {
|
---|
361 |
|
---|
362 | var conditionUndone = this.presentOverlays[this.presentOverlays.length - 1] !== undefined;
|
---|
363 |
|
---|
364 | if (conditionUndone) {
|
---|
365 | var overlays_copy = [];
|
---|
366 | for (var i = 0; i < this.presentOverlays[0].length; i++) {
|
---|
367 | var clone_shape = ShapesUtil.cloneShape(this.presentOverlays[0][i]);
|
---|
368 | if (ShapesUtil.overlayItemIsShape(clone_shape)) {
|
---|
369 | this.mapEditor.addShapeListeners(clone_shape, null); // don't have an overlay event!
|
---|
370 | } else {
|
---|
371 | this.mapEditor.addMarkerListeners(clone_shape, null); // don't have an overlay event!
|
---|
372 | }
|
---|
373 | overlays_copy[i] = clone_shape;
|
---|
374 | }
|
---|
375 | this.undoneOverlays.push(overlays_copy);
|
---|
376 | }
|
---|
377 |
|
---|
378 | var conditionPresent = this.prevOverlays[this.prevOverlays.length - 1] !== undefined;
|
---|
379 |
|
---|
380 | if (conditionPresent) {
|
---|
381 | this.presentOverlays = [];
|
---|
382 | var overlays_copy = [];
|
---|
383 | for (var i = 0; i < this.prevOverlays[this.prevOverlays.length - 1].length; i++) {
|
---|
384 | var clone_shape = ShapesUtil.cloneShape(this.prevOverlays[this.prevOverlays.length - 1][i]);
|
---|
385 | if (ShapesUtil.overlayItemIsShape(clone_shape)) {
|
---|
386 | this.mapEditor.addShapeListeners(clone_shape, null); // don't have an overlay event!
|
---|
387 | } else {
|
---|
388 | this.mapEditor.addMarkerListeners(clone_shape, null); // don't have an overlay event!
|
---|
389 | }
|
---|
390 | overlays_copy[i] = clone_shape;
|
---|
391 | }
|
---|
392 | this.presentOverlays.push(overlays_copy);
|
---|
393 | }
|
---|
394 | } |
---|