PMA.UI Documentation by Pathomation

view/controls/prevZoom.js

  1. import { Control } from 'ol/control';
  2. // import { createOlViewer } from '../viewportHelpers';
  3. export
  4. /**
  5. * Displays an interface that allows the user to return to previous zoom
  6. * @alias PrevZoom
  7. * @memberof PMA.UI.View.Controls
  8. * @param {object} opt_options Options to initialize the previous zoom control
  9. * @param {string} [opt_options.tipLabel] Label for previous zoom button
  10. * @param {ol.interaction.DragZoom} opt_options.dragZoom The dragzoom interaction of this map
  11. */
  12. class PrevZoom extends Control {
  13. constructor(opt_options) {
  14. var options = opt_options || {};
  15. var dragZoom = options.dragZoom;
  16. var handleClick = function (e) {
  17. e.preventDefault();
  18. e.stopPropagation();
  19. if ((" " + element.className + " ").indexOf(' disabled ') > -1) {
  20. return;
  21. }
  22. else {
  23. element.className += " disabled";
  24. }
  25. this.getMap().getView().setResolution(prevResolution);
  26. };
  27. var tipLabel = (options.tipLabel) ? options.tipLabel : 'Previous view';
  28. var label = (options.label) ? options.label : '\u2190';
  29. let label_ = document.createElement('span');
  30. label_.innerHTML = label;
  31. var button = document.createElement('button');
  32. button.type = 'button';
  33. button.title = tipLabel;
  34. button.appendChild(label_);
  35. var prevResolution = 1;
  36. var element = document.createElement('div');
  37. element.className = 'ol-prevZoom ol-control ol-unselectable disabled';
  38. element.appendChild(button);
  39. super({
  40. element: element,
  41. target: options.target
  42. });
  43. dragZoom.on('boxstart', (function () {
  44. if ((" " + element.className + " ").indexOf(' disabled ') > -1) {
  45. element.className = element.className.replace(/disabled/g, '');
  46. }
  47. prevResolution = this.getMap().getView().getResolution();
  48. }).bind(this));
  49. button.addEventListener('click', handleClick.bind(this), false);
  50. button.addEventListener('touchstart', handleClick.bind(this), false);
  51. }
  52. /**
  53. * Sets the OpenLayers map this control handles. This is automatically called by OpenLayers
  54. * @param {ol.Map} map
  55. */
  56. setMap(map) {
  57. super.setMap(map);
  58. }
  59. }