source: main/trunk/greenstone3/web/interfaces/default/js/map-scripts-editor.js@ 32850

Last change on this file since 32850 was 32850, checked in by ak19, 5 years ago
  1. Zeddy introduces suppressUndo and cleaned up lots of CloneShape sectionst that were commented out. 2. Zeddy and Dr Bainbridge solved the issue whereby shapes loaded from archives_metadata were not selectable and needed a deleteAllShapes followed by Undo to make them selectable. These steps are no longer needed now, as it's solved more efficiently.
File size: 23.9 KB
Line 
1
2
3function MapEditor(id) {
4 this.id = id;
5 this.shiftKeyPressed = false;
6 this.beingDragged = false;
7 this.allowDeselect = true;
8 this.colors = ['#1E90FF', '#FF1493', '#4B0082', '#32CD32', '#FF8C00', '#000000'];
9 this.selectedColor;
10 this.colorButtons = {};
11 this.thicknessValue = 1;
12 this.opacityValue = 0.4;
13 this.overlays = [];
14 this.selectedShapes = [];
15 this.listenersArray = [];
16 this.mapsArray = [];
17 this.drawingManager;
18 this.selectedShape;
19 this.savedOverlays = null;
20 this.map = null;
21 this.counter = 0;
22 this.branchNum = 1;
23 this.mouseState = "up";
24 this.thicknessRangeListener = this.thicknessValue; // ????
25 this.resizable = false;
26 this.dontResize = false;
27 this.shapeOptions = {
28 suppressUndo: true,
29 fillColor: '#CA4A2F',
30 strokeWeight: this.thicknessValue,
31 fillOpacity: this.opacityValue,
32 editable: true,
33 geodesic: false,
34 draggable: true
35 };
36 this.mapEditorHistory = new MapEditorHistory(this);
37}
38
39//draggable checkbox control
40MapEditor.prototype.initMapEditorControls = function () {
41 var that = this;
42
43 var draggableCB = document.getElementById("draggableCB-"+ this.id);
44 draggableCB.addEventListener('change', function () {
45 if (this.checked) {
46 for (var i = 0; i < that.overlays.length; i++) {
47 that.overlays[i].draggable = false;
48 that.shapeOptions.draggable = false;
49 }
50 } else {
51 for (var i = 0; i < that.overlays.length; i++) {
52 that.overlays[i].draggable = true;
53 that.shapeOptions.draggable = true;
54 }
55 }
56 });
57
58
59 //Update thickness
60 var thicknessSlider = document.getElementById("thicknessRange" + "-" + this.id);
61 var thicknessSliderOutput = document.getElementById("thicknessRangeVal" + "-" + this.id);
62 thicknessSliderOutput.innerHTML = ((thicknessSlider.value / 20) * 100) / 100;
63
64 thicknessSlider.oninput = function () {
65 that.shapeSpecsChangeMD();
66 thicknessSliderOutput.innerHTML = ((this.value / 20) * 100) / 100;
67 that.thicknessValue = this.value / 20;
68 that.shapeOptions.strokeWeight = that.thicknessValue;
69 that.setSelectedThickness(that.thicknessValue);
70
71 }
72 //Update opacity
73 var opacitySlider = document.getElementById("colourOpacity" + "-" + this.id);
74 var opacitySliderOutput = document.getElementById("opacityRangeVal" + "-" + this.id);
75 opacitySliderOutput.innerHTML = "% " + Math.round(opacitySlider.value);
76
77 opacitySlider.oninput = function () {
78 that.shapeSpecsChangeMD();
79 opacitySliderOutput.innerHTML = "% " + Math.round(this.value * 100) / 100;
80 that.opacityValue = this.value / 100;
81 that.shapeOptions.fillOpacity = that.opacityValue;
82 that.setSelectedOpacity(that.opacityValue);
83 }
84
85 document.getElementById("color-palette1" + "-" + this.id).addEventListener("mousedown", function() { that.shapeSpecsChangeMD() });
86 document.getElementById("thicknessRange" + "-" + this.id).addEventListener("mouseup", function () { that.shapeSpecsChangeMU() });
87 document.getElementById("colourOpacity" + "-" + this.id).addEventListener("mouseup", function() { that.shapeSpecsChangeMU() } );
88
89 document.onmousedown = function (ev) {
90 that.mouseState = "down";
91 // console.log('Down State you can now start dragging');
92 //do not write any code here in this function
93 }
94
95 document.onmouseup = function (ev) {
96 that.mouseState = "up";
97 // console.log('up state you cannot drag now because you are not holding your mouse')
98 //do not write any code here in this function
99 }
100
101
102 //prompts the user to save the changes before reloading/leaving the page
103 window.onbeforeunload = function (e) {
104 var currentOverlays = JSON.stringify(ShapesUtil.overlayToJSON(that.overlays));
105 var enableMessage = currentOverlays !== that.savedOverlays;
106 var message = "Changes are not saved. Are you sure you want to leave?";
107
108
109 // Comment out following section in entirety -- from "e = e || window.event" to end of "if(e)" -- if
110 // you don't want to see the popup about changes that haven't been saved yet
111 e = e || window.event;
112 // For IE and Firefox
113 if (e) {
114
115 if(enableMessage){
116 if(currentOverlays !== "[]") {
117 alert(message);
118 e.returnValue = message;
119
120 // For Safari
121 return message;
122 }
123 }
124 }
125
126 }
127}
128
129MapEditor.prototype.settingThePath = function () {
130 var that = this;
131 this.listenersArray = []
132 this.counter = 0;
133 this.branchNum = 1;
134
135 for (var i = 0; i < this.selectedShapes.length * 2; i++) {
136 for (var j = 1; j < 6; j++) {
137 var path = "//*[@id='map-" + this.id + "']/div/div/div[1]/div[3]/div/div[3]/div[" + this.branchNum + "]/div[" + j + "]/div";
138 this.listenersArray[this.counter] = this.getElementByXpath(path);
139 if (this.listenersArray[this.counter] !== (undefined || null)) {
140 this.listenersArray[this.counter].addEventListener("mousemove", function () {
141 that.resizable = true;
142 that.shapeResize();
143 });
144 this.listenersArray[this.counter].addEventListener("mouseout", function () {
145 if (this.mouseDown) {
146 that.resizable = true;
147 that.shapeResize();
148
149 }
150 });
151 }
152 this.counter++;
153 }
154 this.branchNum++;
155 }
156}
157
158MapEditor.prototype.shapeResize = function () {
159 if (this.mouseState == "down") {
160 if (this.selectedShapes.length > 0) {
161 if (this.resizable) {
162 if (this.dontResize == false) {
163 this.mapEditorHistory.historyOverlayPush();
164 }
165
166 }
167 }
168 }
169}
170
171MapEditor.prototype.shapeSpecsChangeMD = function () {
172 if (this.selectedShapes.length > 0) {
173 this.mapEditorHistory.historyOverlayPush();
174 }
175}
176
177MapEditor.prototype.shapeSpecsChangeMU = function () {
178 if (this.selectedShapes.length > 0) {
179 this.mapEditorHistory.presentOverlayPush();
180 }
181}
182
183MapEditor.prototype.makeColorButton = function (color) {
184 var that = this;
185
186 var button = document.createElement('span');
187 button.className = 'color-buttons1';
188 button.style.backgroundColor = color;
189 google.maps.event.addDomListener(button, 'click', function () {
190 that.selectColor(color);
191 that.setSelectedShapeColor(color);
192 that.shapeSpecsChangeMU();
193 });
194 return button;
195}
196
197MapEditor.prototype.buildColorPalette = function () {
198 var colorPalette = document.getElementById("color-palette1" + "-" + this.id);
199 for (var i = 0; i < this.colors.length; ++i) {
200 var currColor = this.colors[i];
201 var colorButton = this.makeColorButton(currColor);
202 colorPalette.appendChild(colorButton);
203 this.colorButtons[currColor] = colorButton;
204 }
205 this.selectColor(this.colors[0]);
206};
207
208MapEditor.prototype.selectColor = function (color) {
209 this.selectedColor = color;
210 for (var i = 0; i < this.colors.length; ++i) {
211 var currColor = this.colors[i];
212 this.colorButtons[currColor].style.border = currColor == color ? '2px solid #789' : '2px solid #fff';
213 }
214
215 // Retrieves the current options from the drawing manager and replaces the
216 // stroke or fill color as appropriate.
217 var polylineOptions = this.drawingManager.get('polylineOptions');
218 polylineOptions.strokeColor = color;
219 this.drawingManager.set('polylineOptions', polylineOptions);
220
221 var rectangleOptions = this.drawingManager.get('rectangleOptions');
222 rectangleOptions.fillColor = color;
223 this.drawingManager.set('rectangleOptions', rectangleOptions);
224
225 var circleOptions = this.drawingManager.get('circleOptions');
226 circleOptions.fillColor = color;
227 this.drawingManager.set('circleOptions', circleOptions);
228
229 var polygonOptions = this.drawingManager.get('polygonOptions');
230 polygonOptions.fillColor = color;
231 this.drawingManager.set('polygonOptions', polygonOptions);
232}
233
234MapEditor.prototype.initMapEditor = function () {
235 var that = this;
236
237 this.map = new google.maps.Map(document.getElementById("map-" + this.id), {
238 center: {
239 lat: -37.7891,
240 lng: 175.3180
241 },
242 zoom: 14,
243 mapId: this.id,
244 });
245 this.mapsArray.push(this.map);
246 // Add a style-selector control to the map.
247 var styleControl = document.getElementById('style-selector-control' + "-" + this.id);
248 this.map.controls[google.maps.ControlPosition.TOP_RIGHT].push(styleControl);
249
250 // Set the map's style to the initial value of the selector.
251 var styleSelector = document.getElementById('style-selector' + "-" + this.id);
252 //console.log(styleSelector);
253 //map = google.maps.Map(document.getElementById('map' +"-"+ this.id));
254 this.map.setOptions({
255 styles: styles[styleSelector.value]
256
257 });
258
259 // Apply new JSON when the user selects a different style.
260 styleSelector.addEventListener('change', function () {
261 that.map.setOptions({
262 styles: styles[styleSelector.value]
263 });
264 });
265
266 this.drawingManager = new google.maps.drawing.DrawingManager({
267 drawingMode: google.maps.drawing.OverlayType.RECTANGLE,
268 drawingControl: true,
269 drawingControlOptions: {
270 position: google.maps.ControlPosition.TOP_CENTER,
271 drawingModes: ['marker', 'circle', 'polygon', 'polyline', 'rectangle']
272 },
273 markerOptions: {
274 draggable: true
275 },
276 circleOptions: this.shapeOptions,
277 polylineOptions: this.shapeOptions,
278 polygonOptions: this.shapeOptions,
279 rectangleOptions: this.shapeOptions,
280 });
281
282 this.drawingManager.setMap(this.map);
283
284 google.maps.event.addListener(this.drawingManager, "drawingmode_changed", function () {
285 if (that.shiftKeyPressed != true && that.drawingManager.drawingMode !== null) {
286 that.deselectAll();
287 }
288 that.settingThePath();
289
290 })
291
292 // store reference to added overlay
293 google.maps.event.addListener(this.drawingManager, 'overlaycomplete', function (e) {
294
295 that.allowDeselect = true;
296 that.mapEditorHistory.historyOverlayPush();
297 that.overlays.push(e.overlay); // store reference to added overlay
298 var newShape = e.overlay;
299 newShape.type = e.type;
300 that.mapEditorHistory.presentOverlayPush();
301
302 if (e.type !== google.maps.drawing.OverlayType.MARKER) {
303 that.addShapeListeners(newShape, e);
304 that.setSelection(newShape, e);
305 } else {
306 that.addMarkerListeners(newShape, e);
307 that.setSelection(newShape, e);
308 }
309 });
310
311 //Clears selection if clicked on the map when shift is not presseed
312 google.maps.event.addListener(this.map, 'click', function (e) {
313 var c = document.body.childNodes;
314 if (e.target && e.target.matches("a.classA")) {
315 console.log("Anchor element clicked!");
316 }
317 if (that.shiftKeyPressed == false) {
318 that.clearSelection();
319 that.selectedShape = null;
320 }
321 });
322
323 google.maps.event.addListener(this.map, 'mousedown', function (e) {
324 that.dontResize = true;
325 });
326
327 google.maps.event.addListener(this.map, 'mouseup', function (e) {
328 that.dontResize = false;
329 });
330
331 //Keyboard shortcuts
332 var mapAndControls = document.getElementById("map-and-controls-" + this.id);
333
334 //Sets shift as unpressed
335 mapAndControls.addEventListener('keyup', function (event) {
336 if (event.keyCode == '16') {
337 that.shiftKeyPressed = false;
338 }
339 });
340
341 mapAndControls.addEventListener('keydown', function (event) {
342
343 // https://stackoverflow.com/questions/2220196/how-to-decode-character-pressed-from-jquerys-keydowns-event-handler
344 var keyCode = String.fromCharCode(event.which);
345// console.log("Key pressed: " + keyCode);
346
347 //Sets shift as pressed
348 if (event.keyCode == '16') {
349 that.shiftKeyPressed = true;
350 }
351 else if (keyCode == 'Y' && (event.ctrlKey || event.metaKey)) {
352 that.mapEditorHistory.redo();
353 }
354 else if (keyCode == 'Z' && (event.ctrlKey || event.metaKey) ) {
355 if (that.shiftKeyPressed == false) {
356 that.mapEditorHistory.undo();
357 }
358 }
359 else if (keyCode == 'A' && (event.ctrlKey || event.metaKey)) {
360 event.preventDefault();
361 that.drawingManager.setDrawingMode(null);
362 that.selectAll();
363 }
364 else if (keyCode == 'D' && (event.ctrlKey || event.metaKey)) {
365 event.preventDefault();
366 that.deselectAll();
367 }
368 else if (keyCode == '0' || keyCode == 'À' || (keyCode == 'G'&& (event.ctrlKey || event.metaKey))) {
369 event.preventDefault();
370 that.drawingManager.setDrawingMode(null);
371 } else if (keyCode == '1') {
372 that.drawingManager.setDrawingMode('marker');
373 } else if (keyCode == '2') {
374 that.drawingManager.setDrawingMode('circle');
375 } else if (keyCode == '3') {
376 that.drawingManager.setDrawingMode('polygon');
377 } else if (keyCode == '4') {
378 that.drawingManager.setDrawingMode('polyline');
379 } else if (keyCode == '5') {
380 that.drawingManager.setDrawingMode('rectangle');
381 }
382 //else if (keyCode == 'S') {
383 // that.saveToArchives();
384 //}
385 else if (keyCode == 'Q') { // for debugging information, press Q (easy to hit key)
386 that.printHistory();
387 }
388 else if (keyCode == '.') {
389 that.deleteSelectedShapes();
390 }
391// console.log(keyCode);
392 });
393
394
395 this.buildColorPalette();
396
397
398
399
400 var collection = gs.cgiParams.c;
401 var site_name = gs.xsltParams.site_name;
402 var nodeID = this.id; // documentID, hopefully contains section ID too
403 var metaname = gps_metadata_name;
404
405 // collection, site, documentID, metadataName, metadataPosition, responseFunction
406 gs.functions.getArchivesMetadata(collection, site_name, nodeID, metaname, 0, function(responseText){
407 // responseText is of type GSMetadata
408
409 // called when data has been retrieved from archives
410 var JSONString = responseText.getValue();
411 if(JSONString !== "")
412 {
413 that.LOAD(JSONString, nodeID);
414 that.savedOverlays = JSONString;
415 }
416 }
417 ); // TODO: responseFunction in setMeta call
418}
419
420//Deletes a vertex if clicked on it
421MapEditor.prototype.vertexAndPolyDel = function (e, newShape) {
422 var vertex = e.vertex;
423 if (e.vertex !== undefined) {
424 if (newShape.type === google.maps.drawing.OverlayType.POLYGON) {
425 var path = newShape.getPaths().getAt(e.path);
426 path.removeAt(e.vertex);
427 if (path.length < 3) {
428 newShape.setMap(null);
429 }
430 }
431 if (newShape.type === google.maps.drawing.OverlayType.POLYLINE) {
432 var path = newShape.getPath();
433 path.removeAt(e.vertex);
434 if (path.length < 2) {
435 newShape.setMap(null);
436 }
437 }
438 }
439}
440
441MapEditor.prototype.addMarkerListeners = function (newShape, e) {
442 var that = this;
443 //cLICK EVENT IF A MARKER IS CREATED
444 google.maps.event.addListener(newShape, 'click', function (e) {
445 if(that.shiftKeyPressed){
446
447 } else {
448 that.mapEditorHistory.historyOverlayPush();
449 newShape.setMap(null);
450 that.mapEditorHistory.presentOverlayPush();
451 }
452
453 });
454
455 google.maps.event.addListener(newShape, 'dragstart', function (e) {
456 that.beingDragged = true;
457 that.mapEditorHistory.historyOverlayPush();
458
459 });
460
461 google.maps.event.addListener(newShape, 'dragend', function () {
462 that.beingDragged = false;
463 that.mapEditorHistory.presentOverlayPush();
464 that.allowDeselect = false;
465 });
466}
467
468MapEditor.prototype.addShapeListeners = function (newShape, e) {
469 var that = this;
470 // Add an event listener that selects the newly-drawn shape when the user
471 // mouses down on it.
472 google.maps.event.addListener(newShape, 'click', function (e) {
473 that.vertexAndPolyDel(e, newShape);
474 });
475
476 google.maps.event.addListener(newShape, 'dragstart', function (e) {
477 that.allowDeselect = false;
478 that.mapEditorHistory.historyOverlayPush();
479 });
480
481 google.maps.event.addListener(newShape, 'dragend', function () {
482 that.beingDragged = false;
483 that.mapEditorHistory.presentOverlayPush();
484 that.settingThePath();
485
486 that.allowDeselect = false;
487 that.setSelection(newShape, e);
488 });
489
490 //Store information after the event ends
491 google.maps.event.addListener(newShape, 'bounds_changed', function (e) {
492 if (that.beingDragged == false) {
493 that.mapEditorHistory.presentOverlayPush();
494 }
495 });
496
497 //Add an event listener to select a shape if the mouse hovers over it
498 google.maps.event.addListener(newShape, 'mousedown', function (e) {
499 if (e.target && e.target.matches("a.classA")) {
500 console.log("Anchor element clicked!");
501 }
502 if (e.vertex !== undefined || e.edge !== undefined) {
503 that.mapEditorHistory.historyOverlayPush()
504 }
505 if (that.drawingManager.drawingMode == null) {
506 that.setSelection(newShape, e);
507 }
508 });
509
510 google.maps.event.addListener(newShape, 'mouseup', function (e) {
511 if (e.vertex !== undefined || e.edge !== undefined) {
512 that.mapEditorHistory.presentOverlayPush()
513 } else {
514 //that.setSelection(newShape, e);
515 }
516
517 });
518}
519MapEditor.prototype.clearSelection = function () {
520 if (this.selectedShape) {
521 if (this.shiftKeyPressed == false) {
522 for (var i = 0; i < this.selectedShapes.length; i++) {
523 if(this.selectedShapes[i].type !== 'marker') {
524 this.selectedShapes[i].setEditable(false);
525 }
526 }
527 this.selectedShapes = [];
528 }
529 this.selectedShape = null;
530 }
531}
532
533//Set selection for the selected overlay
534MapEditor.prototype.setSelection = function (shape, e) {
535 //var that = this;
536 if (shape.type !== 'marker') {
537 if (this.shiftKeyPressed == false) {
538 if (e !== null) {
539 if (e.vertex == undefined) {
540 if (e.edge == undefined) {
541 this.clearSelection();
542 shape.setEditable(true);
543 }
544 }
545 }
546 }
547 if (this.selectedShapes.includes(shape)) {
548 if (e !== null) {
549 if (e.vertex == undefined) {
550 if (e.edge == undefined) {
551 this.allowDeselect = true;
552 this.removeFromSelectedShapes(shape);
553 }
554 }
555 }
556 } else {
557 this.allowDeselect = false;
558 shape.setEditable(true);
559 this.selectedShapes.push(shape);
560 }
561
562 //Send the values to be updated
563 var thi = shape.strokeWeight;
564 var opa = shape.fillOpacity;
565 var fCol = shape.fillColor;
566 var sCol = shape.strokeColor;
567 this.updateMenuValues(thi, opa, fCol, sCol);
568
569 } else if (shape.type == 'marker') {
570 this.allowDeselect = false;
571 this.selectedShapes.push(shape);
572 }
573 this.selectedShape = shape;
574 this.settingThePath();
575}
576
577MapEditor.prototype.removeFromSelectedShapes = function (shape) {
578 if (this.selectedShapes.includes(shape)) {
579 if (this.allowDeselect) {
580 const index = this.selectedShapes.indexOf(shape);
581 this.selectedShapes.splice(index, 1);
582 shape.setEditable(false);
583 }
584 this.allowDeselect = true;
585 }
586}
587
588//Set selected thickness
589MapEditor.prototype.setSelectedThickness = function (sWeight) {
590 if (this.selectedShapes.length > 0) {
591 for (var i = 0; i < this.selectedShapes.length; i++) {
592 this.selectedShapes[i].set('strokeWeight', sWeight);
593 }
594 }
595}
596
597//Set selected opacity
598MapEditor.prototype.setSelectedOpacity = function (fOpacity) {
599
600 if (this.selectedShapes.length > 0) {
601 for (var i = 0; i < this.selectedShapes.length; i++) {
602 this.selectedShapes[i].set('fillOpacity', fOpacity);
603 }
604 }
605}
606
607//set selected fill colour
608MapEditor.prototype.setSelectedShapeColor = function (color) {
609 if (this.selectedShapes.length > 0) {
610 for (var i = 0; i < this.selectedShapes.length; i++) {
611 this.selectedShapes[i].set('fillColor', color);
612 this.selectedShapes[i].set('strokeColor', color);
613 }
614 }
615}
616
617MapEditor.prototype.getElementByXpath = function (path) {
618 return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
619}
620
621MapEditor.prototype.updateMenuValues = function (thi, opa, fCol, sCol) {
622 //Update thickness slider and value on the settings menu
623 var thicknessSliderOutput = document.getElementById("thicknessRangeVal" + "-" + this.id);
624 thicknessSliderOutput.innerHTML = thi;
625 document.getElementById("thicknessRange" + "-" + this.id).value = Math.round((thi * 20) * 100) / 100;
626
627 //Update the opacity slider and value on the settings menu
628 var opacitySliderOutput = document.getElementById("opacityRangeVal" + "-" + this.id);
629 opacitySliderOutput.innerHTML = "% " + Math.round(opa * 100) * 100 / 100;
630 document.getElementById("colourOpacity" + "-" + this.id).value = (opa * 100) * 100 / 100;
631
632 if (this.drawingManager.drawingMode == null) {
633 this.selectColor(fCol);
634 }
635}
636MapEditor.prototype.selectAll = function () {
637 this.shiftKeyPressed = true;
638 var e = new Object();
639 e.vertex = undefined;
640 this.selectedShapes = [];
641 for (var i = 0; i < this.overlays.length; i++) {
642 this.setSelection(this.overlays[i], e);
643 }
644 this.shiftKeyPressed = false;
645}
646MapEditor.prototype.deselectAll = function () {
647 for (var i = 0; i < this.selectedShapes.length; i++) {
648 if (this.selectedShapes[i].type !== google.maps.drawing.OverlayType.MARKER) {
649 this.selectedShapes[i].setEditable(false);
650 }
651
652 }
653 this.selectedShapes = [];
654}
655
656// event handler for s being pressed *when map editor has the focus*
657// For saving and rebuilding, see map_scripts
658MapEditor.prototype.saveToArchives = function () {
659 var that = this;
660 console.log("Save pressed");
661
662 var json_overlays = JSON.stringify(ShapesUtil.overlayToJSON(this.overlays));
663 that.savedOverlays = json_overlays; // save the old version to compare with future changes
664 var collection = gs.cgiParams.c;
665 var site_name = gs.xsltParams.site_name;
666 var nodeID = this.id; // documentID, hopefully contains section ID too
667 var metaname = "GPS.mapOverlay";
668
669 // collection, site, documentID, metadataName, metadataPosition, metadataValue, prevMetadataValue, metamode, responseFunction
670 gs.functions.setArchivesMetadata(collection, site_name, nodeID, metaname, 0, json_overlays, null, "override", function(){
671 console.log("SAVED");
672 }
673 );
674
675 /*gs.functions.getArchivesMetadata(collection, site_name, nodeID, metaname, 0, function(responseText){
676 var JSONString = responseText.getValue();
677 that.savedOverlays = JSONString;
678 }
679 );*/
680
681
682}
683
684// TODO: When finished testing, can remove this debug function that just prints to console
685MapEditor.prototype.printHistory = function () {
686 console.log("prev", this.mapEditorHistory.prevOverlays);
687 console.log("present ", this.mapEditorHistory.presentOverlays);
688 console.log("undone ", this.mapEditorHistory.undoneOverlays);
689 console.log("@@@@ allShapes: ", this.overlays);
690 console.log("@@@@ selectedShapes: ", this.selectedShapes);
691}
692
693// to be called after reading back in stored JSON from archives meta
694MapEditor.prototype.LOAD = function (json_str, nodeID) {
695 this.mapEditorHistory.historyOverlayPush();
696
697
698 // This seems to convert the map_store object into an array and forces array index access, instead of convenient property access using nodeID
699 //Object.values(gsmap_store)[0]; // Always gets top level section's map-editor, not what we want.
700
701 // Get the map editor for the nodeID, as we're asked to load that editor
702 var map_editor = gsmap_store["map-"+nodeID];
703
704 var new_overlays = ShapesUtil.JSONToOverlays(json_str);
705 for (var i=0; i<map_editor.overlays.length; i++) {
706 map_editor.overlays[i].setMap(null);
707 }
708
709 map_editor.overlays = new_overlays;
710
711 for (var i=0; i<map_editor.overlays.length; i++) {
712 var shape = map_editor.overlays[i];
713 if (ShapesUtil.overlayItemIsShape(shape)) {
714 map_editor.addShapeListeners(shape, null); // don't have an overlay event!
715 } else {
716 map_editor.addMarkerListeners(shape, null); // don't have an overlay event!
717 }
718 shape.setMap(map_editor.map);
719 }
720
721 this.mapEditorHistory.presentOverlayPush();
722}
723
724MapEditor.prototype.deleteSelectedShapes = function () {
725 if(this.selectedShapes.length !== 0) {
726 this.mapEditorHistory.historyOverlayPush();
727 for (var i = 0; i < this.selectedShapes.length; i++) {
728 this.selectedShapes[i].setMap(null);
729
730 if (this.overlays.includes(this.selectedShapes[i])) {
731 const index = this.overlays.indexOf(this.selectedShapes[i]);
732 this.overlays.splice(index, 1);
733// this.selectedShapes[i].setEditable(false);
734 }
735 }
736 this.selectedShapes = [];
737 this.mapEditorHistory.presentOverlayPush();
738 }
739}
740
741MapEditor.prototype.draggableState = function () {
742
743 var draggableCB = document.querySelector("input[name=draggableCB]");
744 draggableCB.addEventListener('change', function () {
745 if (this.checked) {
746 this.overlays.draggable = false;
747 } else {
748 this.overlays.draggable = false;
749 }
750 });
751}
752
753MapEditor.prototype.deleteAllShapes = function () {
754 if(this.overlays.length !== 0) {
755 //console.log("deleteAllShape() this.id = " + this.id);
756 this.mapEditorHistory.historyOverlayPush();
757 for (var i = 0; i < this.overlays.length; i++) {
758 this.overlays[i].setMap(null);
759 }
760 this.overlays = [];
761 this.mapEditorHistory.presentOverlayPush();
762 }
763}
Note: See TracBrowser for help on using the repository browser.