1 | <!DOCTYPE html>
|
---|
2 | <html>
|
---|
3 | <head>
|
---|
4 | <title>Drawing Tools</title>
|
---|
5 | <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
|
---|
6 | <meta charset="utf-8">
|
---|
7 | <style>
|
---|
8 | /* Always set the map height explicitly to define the size of the div
|
---|
9 | * element that contains the map. */
|
---|
10 | #map {
|
---|
11 | height: 83%;
|
---|
12 | width: 90;
|
---|
13 | float: bottom;
|
---|
14 | clear: both;
|
---|
15 | }
|
---|
16 | /* Optional: Makes the sample page fill the window. */
|
---|
17 | html, body {
|
---|
18 | height: 100%;
|
---|
19 | width: 99%;
|
---|
20 | margin: 0;
|
---|
21 | padding: 0;
|
---|
22 |
|
---|
23 | }
|
---|
24 |
|
---|
25 | #DeleteButtons{
|
---|
26 | display: inline-block;
|
---|
27 | float: left;
|
---|
28 | padding-left: 10px;
|
---|
29 | padding-top: 5px;
|
---|
30 | width: 100%
|
---|
31 |
|
---|
32 | }
|
---|
33 |
|
---|
34 | #LineThickness{
|
---|
35 | display: inline-block;
|
---|
36 | float: left;
|
---|
37 | padding-left: 10px;
|
---|
38 | padding-top: 5px;
|
---|
39 |
|
---|
40 | }
|
---|
41 |
|
---|
42 | #ColourOpacity{
|
---|
43 | display: inline-block;
|
---|
44 | float: left;
|
---|
45 | padding-left: 10px;
|
---|
46 | padding-top: 5px;
|
---|
47 |
|
---|
48 | }
|
---|
49 |
|
---|
50 | #buttons3{
|
---|
51 | display: inline-block;
|
---|
52 | float: left;
|
---|
53 | padding-left: 10px;
|
---|
54 | padding-top: 5px;
|
---|
55 |
|
---|
56 | }
|
---|
57 |
|
---|
58 | #FillColour {
|
---|
59 | display: inline-block;
|
---|
60 | float: left;
|
---|
61 | padding-left: 10px;
|
---|
62 | padding-top: 5px;
|
---|
63 | }
|
---|
64 |
|
---|
65 | #color-palette1 {
|
---|
66 | clear: both;
|
---|
67 | }
|
---|
68 |
|
---|
69 | .color-buttons1 {
|
---|
70 | width: 14px;
|
---|
71 | height: 14px;
|
---|
72 | font-size: 0;
|
---|
73 | margin: 2px;
|
---|
74 | float: left;
|
---|
75 | cursor: pointer;
|
---|
76 | }
|
---|
77 |
|
---|
78 |
|
---|
79 | </style>
|
---|
80 | </head>
|
---|
81 | <body>
|
---|
82 | <div id = "DeleteButtons">
|
---|
83 | <button onclick="removeLine()" accesskey="z">Delete Last</button>
|
---|
84 | <button onclick="deleteAllShape()" accesskey="c">Clear All</button>
|
---|
85 | <button onclick="deleteSelectedShape()" accesskey="b">Delete Selected</button>
|
---|
86 | <button onclick="polygonGetPath()" accesskey="n">Get Path</button>
|
---|
87 | <button onclick="undoMovement()" accesskey="n">Undo</button>
|
---|
88 | <button onclick="redoMovement()" accesskey="n">Redo</button>
|
---|
89 |
|
---|
90 | </div>
|
---|
91 |
|
---|
92 | <div id = "LineThickness">
|
---|
93 | <p>Line thickness: <input type="range" min="20" max="100" value="1" class="slider" id="thicknessRange"> </p>
|
---|
94 | <p>Value: <span id="thicknessRangeVal"></span></p>
|
---|
95 | </div>
|
---|
96 |
|
---|
97 | <div id = "ColourOpacity">
|
---|
98 | <p>Colour opacity: <input type="range" min="10" max="100" value="40" class="slider" id="colourOpacity"> </p>
|
---|
99 | <p>Value: <span id="opacityRangeVal"></span></p>
|
---|
100 | </div>
|
---|
101 |
|
---|
102 |
|
---|
103 |
|
---|
104 | <div id="FillColour">
|
---|
105 | <p> Fill Colour:</p> <div id="color-palette1"></div>
|
---|
106 | </div>
|
---|
107 |
|
---|
108 |
|
---|
109 |
|
---|
110 | <div id="map"></div>
|
---|
111 |
|
---|
112 | <script>
|
---|
113 | var debug = false;
|
---|
114 |
|
---|
115 | var redoPressed = false;
|
---|
116 | var undoPressed = false;
|
---|
117 | var shiftKeyPressed = false;
|
---|
118 | var mousedDownFired = false;
|
---|
119 | var prevVertex = {lat:"" ,lng:""};
|
---|
120 | var nextVertex = {lat:"" ,lng:""};
|
---|
121 | var prevShape = [];
|
---|
122 | var nextShape = [];
|
---|
123 | var prevLog = [];
|
---|
124 | var nextLog = [];
|
---|
125 | var dragged = 0;
|
---|
126 | var colors = ['#1E90FF', '#FF1493', '#4B0082', '#32CD32', '#FF8C00', '#000000'];
|
---|
127 | var selectedColor;
|
---|
128 | var colorButtons = {};
|
---|
129 | var thicknessValue = 1;
|
---|
130 | var opacityValue = 0.4;
|
---|
131 | var polyOptions = {
|
---|
132 | fillColor: '#CA4A2F',
|
---|
133 | strokeWeight: thicknessValue,
|
---|
134 | fillOpacity: opacityValue,
|
---|
135 | editable: true,
|
---|
136 | draggable: true,
|
---|
137 | geodesic : false,
|
---|
138 | };
|
---|
139 |
|
---|
140 |
|
---|
141 | var overlays = [];
|
---|
142 | var drawingManager;
|
---|
143 | var selectedShape;
|
---|
144 | var selectedShapes = [];
|
---|
145 |
|
---|
146 |
|
---|
147 |
|
---|
148 | //Update thickness
|
---|
149 | var thicknessSlider = document.getElementById("thicknessRange");
|
---|
150 | var thicknessSliderOutput = document.getElementById("thicknessRangeVal");
|
---|
151 | thicknessSliderOutput.innerHTML = thicknessSlider.value/20;
|
---|
152 |
|
---|
153 | thicknessSlider.oninput = function() {
|
---|
154 | thicknessSliderOutput.innerHTML = this.value/20;
|
---|
155 | thicknessValue = this.value/20;
|
---|
156 | polyOptions.strokeWeight = thicknessValue;
|
---|
157 | setSelectedThickness(thicknessValue);
|
---|
158 | }
|
---|
159 |
|
---|
160 | //Update opacity
|
---|
161 | var opacitySlider = document.getElementById("colourOpacity");
|
---|
162 | var opacitySliderOutput = document.getElementById("opacityRangeVal");
|
---|
163 | opacitySliderOutput.innerHTML = "% " + Math.round(opacitySlider.value);
|
---|
164 |
|
---|
165 | opacitySlider.oninput = function() {
|
---|
166 | opacityValue = this.value/100;
|
---|
167 | polyOptions.fillOpacity = opacityValue;
|
---|
168 | opacitySliderOutput = opacityValue;
|
---|
169 | opacityRangeVal.innerHTML = "% " + Math.round( opacitySliderOutput * 100);
|
---|
170 | setSelectedOpacity(opacityValue);
|
---|
171 | }
|
---|
172 |
|
---|
173 |
|
---|
174 | ////////////////////////////////////////////////////////////////////////////////////////
|
---|
175 | function makeColorButton (color) {
|
---|
176 | var button = document.createElement('span');
|
---|
177 | button.className = 'color-buttons1';
|
---|
178 | button.style.backgroundColor = color;
|
---|
179 | google.maps.event.addDomListener(button, 'click', function () {
|
---|
180 | selectColor(color);
|
---|
181 | setSelectedShapeColor(color);
|
---|
182 | });
|
---|
183 | return button;
|
---|
184 | }
|
---|
185 | function buildColorPalette () {
|
---|
186 | var colorPalette = document.getElementById('color-palette1');
|
---|
187 | for (var i = 0; i < colors.length; ++i) {
|
---|
188 | var currColor = colors[i];
|
---|
189 | var colorButton = makeColorButton(currColor);
|
---|
190 | colorPalette.appendChild(colorButton);
|
---|
191 | colorButtons[currColor] = colorButton;
|
---|
192 | }
|
---|
193 | selectColor(colors[0]);
|
---|
194 | };
|
---|
195 | function selectColor (color) {
|
---|
196 | selectedColor = color;
|
---|
197 | for (var i = 0; i < colors.length; ++i) {
|
---|
198 | var currColor = colors[i];
|
---|
199 | colorButtons[currColor].style.border = currColor == color ? '2px solid #789' : '2px solid #fff';
|
---|
200 | }
|
---|
201 |
|
---|
202 | // Retrieves the current options from the drawing manager and replaces the
|
---|
203 | // stroke or fill color as appropriate.
|
---|
204 | var polylineOptions = drawingManager.get('polylineOptions');
|
---|
205 | polylineOptions.strokeColor = color;
|
---|
206 | drawingManager.set('polylineOptions', polylineOptions);
|
---|
207 |
|
---|
208 | var rectangleOptions = drawingManager.get('rectangleOptions');
|
---|
209 | rectangleOptions.fillColor = color;
|
---|
210 | drawingManager.set('rectangleOptions', rectangleOptions);
|
---|
211 |
|
---|
212 | var circleOptions = drawingManager.get('circleOptions');
|
---|
213 | circleOptions.fillColor = color;
|
---|
214 | drawingManager.set('circleOptions', circleOptions);
|
---|
215 |
|
---|
216 | var polygonOptions = drawingManager.get('polygonOptions');
|
---|
217 | polygonOptions.fillColor = color;
|
---|
218 | drawingManager.set('polygonOptions', polygonOptions);
|
---|
219 | }
|
---|
220 |
|
---|
221 |
|
---|
222 |
|
---|
223 |
|
---|
224 | function initMap() {
|
---|
225 |
|
---|
226 | var map = new google.maps.Map(document.getElementById('map'), {
|
---|
227 | center: {lat: -34.397, lng: 150.644},
|
---|
228 | zoom: 2,
|
---|
229 | //mapTypeId: 'map'
|
---|
230 |
|
---|
231 | });
|
---|
232 |
|
---|
233 |
|
---|
234 | drawingManager = new google.maps.drawing.DrawingManager({
|
---|
235 | drawingMode: google.maps.drawing.OverlayType.POLYGON,
|
---|
236 | drawingControl: true,
|
---|
237 | drawingControlOptions: {
|
---|
238 | position: google.maps.ControlPosition.TOP_CENTER,
|
---|
239 | drawingModes: ['marker', 'circle', 'polygon', 'polyline', 'rectangle']
|
---|
240 | },
|
---|
241 | markerOptions: { draggable: true},
|
---|
242 | circleOptions: polyOptions,
|
---|
243 | polylineOptions : polyOptions,
|
---|
244 | polygonOptions: polyOptions,
|
---|
245 | rectangleOptions: polyOptions,
|
---|
246 | });
|
---|
247 |
|
---|
248 | drawingManager.setMap(map);
|
---|
249 |
|
---|
250 |
|
---|
251 | //overlays.push(event.overlay); // store reference to added overlay
|
---|
252 | google.maps.event.addListener(drawingManager, 'overlaycomplete', function (e) {
|
---|
253 | overlays.push(e.overlay); // store reference to added overlay
|
---|
254 | var newShape = e.overlay;
|
---|
255 | newShape.type = e.type;
|
---|
256 |
|
---|
257 | if (e.type !== google.maps.drawing.OverlayType.MARKER) {
|
---|
258 |
|
---|
259 | // Switch back to non-drawing mode after drawing a shape.
|
---|
260 | //drawingManager.setDrawingMode(null);
|
---|
261 |
|
---|
262 | // Add an event listener that selects the newly-drawn shape when the user
|
---|
263 | // mouses down on it.
|
---|
264 | google.maps.event.addListener(newShape, 'click', function(e) {
|
---|
265 |
|
---|
266 | vertexAndPolyDel(e,newShape);
|
---|
267 | mousedDownFired = false;
|
---|
268 | return;
|
---|
269 |
|
---|
270 | });
|
---|
271 |
|
---|
272 | //Stores past event information
|
---|
273 | google.maps.event.addListener(newShape, 'dragstart', function() {
|
---|
274 | //console.log("Drag Start");
|
---|
275 | if (selectedShape){
|
---|
276 | var lati, lngi;
|
---|
277 | for(var i = 0; i < selectedShape.getPath().length; i++) {
|
---|
278 | lati = selectedShape.getPath().getAt(i).lat();
|
---|
279 | lngi = selectedShape.getPath().getAt(i).lng();
|
---|
280 | //console.log("Vertex number",i, "'s latitude is", lati, "and longitude is", lngi);
|
---|
281 | prevVertex = {lat: lati, lng:lngi};
|
---|
282 | prevShape.push(prevVertex);
|
---|
283 | }
|
---|
284 |
|
---|
285 | prevLog.push(prevShape);
|
---|
286 | prevShape = [];
|
---|
287 | nextLog = [];
|
---|
288 | //console.log("Prev Array Length",prevLog.length);
|
---|
289 | //console.log("Next Array Length",nextLog.length);
|
---|
290 | }
|
---|
291 | });
|
---|
292 |
|
---|
293 | //Store information after the event ends
|
---|
294 | google.maps.event.addListener(newShape, 'dragend', function() {
|
---|
295 | //console.log("Drag End");
|
---|
296 | if (selectedShape){
|
---|
297 | var lati, lngi;
|
---|
298 |
|
---|
299 | for(var i = 0; i < selectedShape.getPath().length; i++) {
|
---|
300 | lati = selectedShape.getPath().getAt(i).lat();
|
---|
301 | lngi = selectedShape.getPath().getAt(i).lng();
|
---|
302 | //console.log("Vertex number",i, "'s latitude is", lati, "and longitude is", lngi);
|
---|
303 | nextVertex = {lat: lati, lng:lngi};
|
---|
304 | nextShape.push(nextVertex);
|
---|
305 | }
|
---|
306 | nextLog.push(nextShape);
|
---|
307 | nextShape = [];
|
---|
308 | //console.log("Prev Array Length",prevLog.length);
|
---|
309 | //console.log("Next Array Length",nextLog.length);
|
---|
310 | }
|
---|
311 | });
|
---|
312 |
|
---|
313 |
|
---|
314 | //Add an event listener to select a shape if the mouse hovers over it
|
---|
315 | google.maps.event.addListener(newShape, 'mousedown', function(e) {
|
---|
316 | if(drawingManager.drawingMode == null) {
|
---|
317 | mousedDownFired =true;
|
---|
318 | // console.log("MOUSDOWN ", e);
|
---|
319 |
|
---|
320 | setSelection(newShape);
|
---|
321 | }
|
---|
322 | });
|
---|
323 | setSelection(newShape);
|
---|
324 | }
|
---|
325 | else {
|
---|
326 | //cLICK EVENT IF A MARKER IS CREATED
|
---|
327 | google.maps.event.addListener(newShape, 'click', function (e) {
|
---|
328 | setSelection(newShape);
|
---|
329 | });
|
---|
330 | setSelection(newShape);
|
---|
331 | }
|
---|
332 | });
|
---|
333 |
|
---|
334 | //Deletes a vertex if clicked on it
|
---|
335 | function vertexAndPolyDel(e,newShape) {
|
---|
336 | var vertex = e.vertex;
|
---|
337 | if (e.vertex !== undefined) {
|
---|
338 | if (newShape.type === google.maps.drawing.OverlayType.POLYGON) {
|
---|
339 | var path = newShape.getPaths().getAt(e.path);
|
---|
340 | path.removeAt(e.vertex);
|
---|
341 | if (path.length < 3) {
|
---|
342 | newShape.setMap(null);
|
---|
343 | }
|
---|
344 | }
|
---|
345 | if (newShape.type === google.maps.drawing.OverlayType.POLYLINE) {
|
---|
346 | var path = newShape.getPath();
|
---|
347 | path.removeAt(e.vertex);
|
---|
348 | if (path.length < 2) {
|
---|
349 | newShape.setMap(null);
|
---|
350 | }
|
---|
351 | }
|
---|
352 | }
|
---|
353 |
|
---|
354 | //if(mousedDownFired == false)
|
---|
355 | //{
|
---|
356 | //setSelection(newShape, vertex);
|
---|
357 | //mousedDownFired = false;
|
---|
358 | //return;
|
---|
359 | //}
|
---|
360 | }
|
---|
361 |
|
---|
362 | function clearSelection () {
|
---|
363 | if (selectedShape) {
|
---|
364 | if (selectedShape.type !== 'marker') {
|
---|
365 | selectedShape.setEditable(false);
|
---|
366 | if(shiftKeyPressed == false){
|
---|
367 | for (var i=0; i < selectedShapes.length; i++) {
|
---|
368 | selectedShapes[i].setEditable(false);
|
---|
369 | }
|
---|
370 | selectedShapes = [];
|
---|
371 | }
|
---|
372 | }
|
---|
373 |
|
---|
374 | selectedShape = null;
|
---|
375 | }
|
---|
376 | }
|
---|
377 | var i = 0;
|
---|
378 | function setSelection (shape, e) {
|
---|
379 | if (debug) {
|
---|
380 | console.log("setSelection() selectedShapes, len = " + selectedShapes.length);
|
---|
381 | }
|
---|
382 |
|
---|
383 | if (shape.type !== 'marker') {
|
---|
384 | if(shiftKeyPressed == false) {
|
---|
385 | if(e == undefined) {
|
---|
386 | clearSelection();
|
---|
387 | shape.setEditable(true);
|
---|
388 | }
|
---|
389 |
|
---|
390 | }
|
---|
391 |
|
---|
392 | //var shapeAlreadySelected = selectedShapes.includes(shape);
|
---|
393 |
|
---|
394 | if (selectedShapes.includes(shape)){
|
---|
395 | shape.setEditable(false);
|
---|
396 | selectedShapes.splice(shape, 1)
|
---|
397 | }
|
---|
398 |
|
---|
399 | else {
|
---|
400 | shape.setEditable(true);
|
---|
401 | selectedShapes.push(shape);
|
---|
402 | }
|
---|
403 |
|
---|
404 |
|
---|
405 | //console.log(selectedShapes.length);
|
---|
406 |
|
---|
407 | //Send the values to be updated
|
---|
408 | var thi = shape.strokeWeight;
|
---|
409 | var opa = shape.fillOpacity;
|
---|
410 | var fCol = shape.fillColor;
|
---|
411 | var sCol = shape.strokeColor;
|
---|
412 | updateMenuValues(thi, opa, fCol, sCol);
|
---|
413 |
|
---|
414 | }
|
---|
415 | else if (shape.type == 'marker') {
|
---|
416 | clearSelection();
|
---|
417 | }
|
---|
418 |
|
---|
419 | selectedShape = shape;
|
---|
420 | }
|
---|
421 |
|
---|
422 |
|
---|
423 | //Clears selection if clicked on the map when shift is not presseed
|
---|
424 | google.maps.event.addListener(map, 'click', function() {
|
---|
425 | if (shiftKeyPressed == false) {
|
---|
426 | clearSelection();
|
---|
427 | }
|
---|
428 | });
|
---|
429 |
|
---|
430 |
|
---|
431 |
|
---|
432 |
|
---|
433 | //Setting drawing tool option
|
---|
434 | document.addEventListener('keydown', function() {
|
---|
435 | //if (event.code == 'KeyX' && (event.ctrlKey || event.metaKey))
|
---|
436 | if (event.code == 'Digit0' || event.code == 'Numpad0' || event.code == 'Backquote') {
|
---|
437 | //clearSelection();
|
---|
438 | drawingManager.setDrawingMode(null);
|
---|
439 | } else if (event.code == 'Digit1') {
|
---|
440 | drawingManager.setDrawingMode('marker');
|
---|
441 | } else if (event.code == 'Digit2') {
|
---|
442 | drawingManager.setDrawingMode('circle');
|
---|
443 | } else if (event.code == 'Digit3') {
|
---|
444 | drawingManager.setDrawingMode('polygon');
|
---|
445 | } else if (event.code == 'Digit4') {
|
---|
446 | drawingManager.setDrawingMode('polyline');
|
---|
447 | } else if (event.code == 'Digit5' ) {
|
---|
448 | drawingManager.setDrawingMode('rectangle');
|
---|
449 | }
|
---|
450 | // console.log(event.code);
|
---|
451 | });
|
---|
452 |
|
---|
453 | //Sets shift as pressed
|
---|
454 | document.addEventListener('keydown', function() {
|
---|
455 | if (event.code == 'ShiftLeft' || event.code == 'ShiftRight')
|
---|
456 | {
|
---|
457 | shiftKeyPressed = true;
|
---|
458 |
|
---|
459 | }
|
---|
460 |
|
---|
461 | });
|
---|
462 |
|
---|
463 | //Sets shift as unpressed
|
---|
464 | document.addEventListener('keyup', function() {
|
---|
465 | if (event.code == 'ShiftLeft' || event.code == 'ShiftRight')
|
---|
466 | {
|
---|
467 | shiftKeyPressed = false;
|
---|
468 | }
|
---|
469 |
|
---|
470 | });
|
---|
471 |
|
---|
472 |
|
---|
473 | buildColorPalette();
|
---|
474 | }
|
---|
475 | //Set selected thickness
|
---|
476 | function setSelectedThickness(sWeight) {
|
---|
477 | if (selectedShape){
|
---|
478 | selectedShape.set('strokeWeight', sWeight)
|
---|
479 | }
|
---|
480 | if(selectedShapes !== 0) {
|
---|
481 | for (var i=0; i < selectedShapes.length; i++) {
|
---|
482 | selectedShapes[i].set('strokeWeight', sWeight);
|
---|
483 | }
|
---|
484 | }
|
---|
485 | }
|
---|
486 |
|
---|
487 | //Set selected opacity
|
---|
488 | function setSelectedOpacity(fOpacity) {
|
---|
489 | if (selectedShape) {
|
---|
490 | selectedShape.set('fillOpacity', fOpacity)
|
---|
491 | }
|
---|
492 | if(selectedShapes !== 0) {
|
---|
493 | for (var i=0; i < selectedShapes.length; i++) {
|
---|
494 | selectedShapes[i].set('fillOpacity', fOpacity);
|
---|
495 | }
|
---|
496 | }
|
---|
497 | }
|
---|
498 |
|
---|
499 |
|
---|
500 |
|
---|
501 | //set selected fill colour
|
---|
502 | function setSelectedShapeColor (color) {
|
---|
503 | if (selectedShape) {
|
---|
504 | if (selectedShape.type == google.maps.drawing.OverlayType.POLYLINE) {
|
---|
505 | selectedShape.set('strokeColor', color);
|
---|
506 | } else {
|
---|
507 | selectedShape.set('fillColor', color);
|
---|
508 | selectedShape.set('strokeColor', color);
|
---|
509 | }
|
---|
510 | }
|
---|
511 | if(selectedShapes !== 0) {
|
---|
512 | for (var i=0; i < selectedShapes.length; i++) {
|
---|
513 | selectedShapes[i].set('fillColor', color);
|
---|
514 | selectedShapes[i].set('strokeColor', color);
|
---|
515 | }
|
---|
516 | }
|
---|
517 | }
|
---|
518 |
|
---|
519 |
|
---|
520 | function updateMenuValues(thi, opa, fCol, sCol){
|
---|
521 |
|
---|
522 | //Update thickness slider and value on the settings menu
|
---|
523 | var thicknessSliderOutput = document.getElementById("thicknessRangeVal");
|
---|
524 | thicknessSliderOutput.innerHTML = thi;
|
---|
525 | document.getElementById("thicknessRange").value = thi*20;
|
---|
526 |
|
---|
527 | //Update the opacity slider and value on the settings menu
|
---|
528 | var opacitySliderOutput = document.getElementById("opacityRangeVal");
|
---|
529 | opacitySliderOutput.innerHTML = "% " + opa*100;
|
---|
530 | document.getElementById("colourOpacity").value = opa*100;
|
---|
531 |
|
---|
532 |
|
---|
533 | if (drawingManager.drawingMode == null) {
|
---|
534 | selectColor(fCol);
|
---|
535 | }
|
---|
536 | }
|
---|
537 | function undoMovement() {
|
---|
538 |
|
---|
539 | var lastItem = prevLog[prevLog.length-1];
|
---|
540 | if (selectedShape){
|
---|
541 | if (prevLog.length !== 0){
|
---|
542 | nextLog.push(lastItem);
|
---|
543 |
|
---|
544 | if (redoPressed == false){
|
---|
545 | selectedShape.setPath(prevLog[prevLog.length-1]);
|
---|
546 | undoPressed = false;
|
---|
547 | console.log("Redo not pressed");
|
---|
548 | }
|
---|
549 | else {
|
---|
550 | selectedShape.setPath(prevLog[prevLog.length-2]);
|
---|
551 | }
|
---|
552 |
|
---|
553 |
|
---|
554 | prevLog.pop();
|
---|
555 | undoPressed = true;
|
---|
556 |
|
---|
557 | //console.log("Undo Array Length",prevLog.length);
|
---|
558 | //console.log(JSON.stringify(prevLog));
|
---|
559 | //console.log(JSON.stringify(nextLog));
|
---|
560 | }
|
---|
561 | }
|
---|
562 | }
|
---|
563 |
|
---|
564 | function redoMovement() {
|
---|
565 | if (selectedShape){
|
---|
566 | if (nextLog.length > 1){
|
---|
567 | prevLog.push(nextLog[nextLog.length-1]);
|
---|
568 |
|
---|
569 | if (undoPressed == false){
|
---|
570 | selectedShape.setPath(nextLog[nextLog.length-1]);
|
---|
571 | undoPressed = false;
|
---|
572 | console.log("Undo not pressed");
|
---|
573 | }
|
---|
574 | else {
|
---|
575 | selectedShape.setPath(nextLog[nextLog.length-2]);
|
---|
576 | }
|
---|
577 | nextLog.pop();
|
---|
578 | redoPressed = true;
|
---|
579 |
|
---|
580 | //console.log("Redo Array Length",nextLog.length);
|
---|
581 | //console.log(JSON.stringify(prevLog));
|
---|
582 | //console.log(JSON.stringify(nextLog));
|
---|
583 | }
|
---|
584 | }
|
---|
585 | }
|
---|
586 |
|
---|
587 | function polygonGetPath() {
|
---|
588 | if (selectedShape){
|
---|
589 | var lati, lngi;
|
---|
590 |
|
---|
591 |
|
---|
592 | for(var i = 0; i < selectedShape.getPath().length; i++) {
|
---|
593 | lati = selectedShape.getPath().getAt(i).lat();
|
---|
594 | lngi = selectedShape.getPath().getAt(i).lng();
|
---|
595 | console.log("Vertex number",i, "'s latitude is", lati, "and longitude is", lngi);
|
---|
596 |
|
---|
597 | }
|
---|
598 | }
|
---|
599 |
|
---|
600 | }
|
---|
601 |
|
---|
602 | function deleteSelectedShape () {
|
---|
603 | for (var i=0; i < selectedShapes.length; i++){
|
---|
604 | selectedShapes[i].setMap(null);
|
---|
605 | }
|
---|
606 | selectedShapes = [];
|
---|
607 | }
|
---|
608 |
|
---|
609 | function removeLine() {
|
---|
610 | var lastOverlay = overlays.pop();
|
---|
611 | if (lastOverlay) lastOverlay.setMap(null);
|
---|
612 | }
|
---|
613 |
|
---|
614 | function deleteAllShape() {
|
---|
615 | for (var i=0; i < overlays.length; i++) {
|
---|
616 | overlays[i].setMap(null);
|
---|
617 |
|
---|
618 | }
|
---|
619 | overlays = [];
|
---|
620 | }
|
---|
621 |
|
---|
622 | </script>
|
---|
623 | <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBzunGwIF2OwsfrOkIC_8bhh0OPGZXo52Y&libraries=drawing&callback=initMap" async defer></script>
|
---|
624 | <script src="shortcuts.js"></script>
|
---|
625 | </body>
|
---|
626 | </html> |
---|