(function webpackUniversalModuleDefinition(root, factory) {
	if(typeof exports === 'object' && typeof module === 'object')
		module.exports = factory(require("vue"), require("@kq_npm/client_common_vue/init.js"), require("@kq_npm/client_common_vue/_types/global-event"), require("@kq_npm/client_common_vue/configprovider/useGlobalConfig.js"));
	else if(typeof define === 'function' && define.amd)
		define("@kq_npm/client_leaflet_vue", ["vue", "@kq_npm/client_common_vue/init.js", "@kq_npm/client_common_vue/_types/global-event", "@kq_npm/client_common_vue/configprovider/useGlobalConfig.js"], factory);
	else if(typeof exports === 'object')
		exports["@kq_npm/client_leaflet_vue"] = factory(require("vue"), require("@kq_npm/client_common_vue/init.js"), require("@kq_npm/client_common_vue/_types/global-event"), require("@kq_npm/client_common_vue/configprovider/useGlobalConfig.js"));
	else
		root["@kq_npm/client_leaflet_vue"] = factory(root["Vue"], root["@kq_npm/client_common_vue/init.js"], root["@kq_npm/client_common_vue/_types/global-event"], root["@kq_npm/client_common_vue/configprovider/useGlobalConfig.js"]);
})(this, function(__WEBPACK_EXTERNAL_MODULE__154__, __WEBPACK_EXTERNAL_MODULE__455__, __WEBPACK_EXTERNAL_MODULE__3353__, __WEBPACK_EXTERNAL_MODULE__5711__) {
return /******/ (function() { // webpackBootstrap
/******/ 	"use strict";
/******/ 	var __webpack_modules__ = ({

/***/ 154:
/***/ (function(module) {

module.exports = __WEBPACK_EXTERNAL_MODULE__154__;

/***/ }),

/***/ 403:
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

/* harmony import */ var element_plus_dist_index_full_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(6363);
/* harmony import */ var element_plus_dist_index_full_js__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(element_plus_dist_index_full_js__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var _init__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(455);
/* harmony import */ var _init__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_init__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var _common_KqGIS__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(8353);
/*
 * Copyright (C) 2019 KQ GEO Technologies Co., Ltd.
 * All rights reserved.
 */




element_plus_dist_index_full_js__WEBPACK_IMPORTED_MODULE_0__.ElLoading.install = (Vue, opts) => {
  _init__WEBPACK_IMPORTED_MODULE_1___default()(Vue, opts);  
  Vue.component("KqLoading", element_plus_dist_index_full_js__WEBPACK_IMPORTED_MODULE_0__.ElLoading);
  Vue.directive("loading", element_plus_dist_index_full_js__WEBPACK_IMPORTED_MODULE_0__.ElLoading.directive);
};

/* harmony default export */ __webpack_exports__.A = (element_plus_dist_index_full_js__WEBPACK_IMPORTED_MODULE_0__.ElLoading);

_common_KqGIS__WEBPACK_IMPORTED_MODULE_2__/* .kq_npm_client_common_vue */ .y.KqLoading = element_plus_dist_index_full_js__WEBPACK_IMPORTED_MODULE_0__.ElLoading;

/***/ }),

/***/ 455:
/***/ (function(module) {

module.exports = __WEBPACK_EXTERNAL_MODULE__455__;

/***/ }),

/***/ 1092:
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

/* harmony import */ var element_plus_dist_index_full_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(6363);
/* harmony import */ var element_plus_dist_index_full_js__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(element_plus_dist_index_full_js__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var _common_KqGIS__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(8353);
/* harmony import */ var _init__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(455);
/* harmony import */ var _init__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_init__WEBPACK_IMPORTED_MODULE_2__);
/*
 * Copyright (C) 2019 KQ GEO Technologies Co., Ltd.
 * All rights reserved.
 */





element_plus_dist_index_full_js__WEBPACK_IMPORTED_MODULE_0__.ElMessage.install = (Vue, opts) => {
  _init__WEBPACK_IMPORTED_MODULE_2___default()(Vue, opts);
  Vue.component("KqMessage", element_plus_dist_index_full_js__WEBPACK_IMPORTED_MODULE_0__.ElMessage);
};

/* harmony default export */ __webpack_exports__.A = (element_plus_dist_index_full_js__WEBPACK_IMPORTED_MODULE_0__.ElMessage);

_common_KqGIS__WEBPACK_IMPORTED_MODULE_1__/* .kq_npm_client_common_vue */ .y.KqMessage = element_plus_dist_index_full_js__WEBPACK_IMPORTED_MODULE_0__.ElMessage;


/***/ }),

/***/ 3353:
/***/ (function(module) {

module.exports = __WEBPACK_EXTERNAL_MODULE__3353__;

/***/ }),

/***/ 5698:
/***/ (function(module) {

module.exports = require("@kq_npm/client_icons_vue");

/***/ }),

/***/ 5711:
/***/ (function(module) {

module.exports = __WEBPACK_EXTERNAL_MODULE__5711__;

/***/ }),

/***/ 6363:
/***/ (function(module) {

module.exports = require("element-plus/dist/index.full.js");

/***/ }),

/***/ 8353:
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   y: function() { return /* binding */ kq_npm_client_common_vue; }
/* harmony export */ });
/* unused harmony export kq_npm_client_leaflet_vue */
let kq_npm_client_common_vue = (window.kq_npm_client_common_vue = window.kq_npm_client_common_vue || {});

__webpack_require__.g.kq_npm_client_common_vue = kq_npm_client_common_vue;

let kq_npm_client_leaflet_vue = (window.kq_npm_client_leaflet_vue = window.kq_npm_client_leaflet_vue || {});

__webpack_require__.g.kq_npm_client_leaflet_vue = kq_npm_client_leaflet_vue;


/***/ })

/******/ 	});
/************************************************************************/
/******/ 	// The module cache
/******/ 	var __webpack_module_cache__ = {};
/******/ 	
/******/ 	// The require function
/******/ 	function __webpack_require__(moduleId) {
/******/ 		// Check if module is in cache
/******/ 		var cachedModule = __webpack_module_cache__[moduleId];
/******/ 		if (cachedModule !== undefined) {
/******/ 			return cachedModule.exports;
/******/ 		}
/******/ 		// Create a new module (and put it into the cache)
/******/ 		var module = __webpack_module_cache__[moduleId] = {
/******/ 			// no module.id needed
/******/ 			// no module.loaded needed
/******/ 			exports: {}
/******/ 		};
/******/ 	
/******/ 		// Execute the module function
/******/ 		__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
/******/ 	
/******/ 		// Return the exports of the module
/******/ 		return module.exports;
/******/ 	}
/******/ 	
/************************************************************************/
/******/ 	/* webpack/runtime/compat get default export */
/******/ 	!function() {
/******/ 		// getDefaultExport function for compatibility with non-harmony modules
/******/ 		__webpack_require__.n = function(module) {
/******/ 			var getter = module && module.__esModule ?
/******/ 				function() { return module['default']; } :
/******/ 				function() { return module; };
/******/ 			__webpack_require__.d(getter, { a: getter });
/******/ 			return getter;
/******/ 		};
/******/ 	}();
/******/ 	
/******/ 	/* webpack/runtime/define property getters */
/******/ 	!function() {
/******/ 		// define getter functions for harmony exports
/******/ 		__webpack_require__.d = function(exports, definition) {
/******/ 			for(var key in definition) {
/******/ 				if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
/******/ 					Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/ 				}
/******/ 			}
/******/ 		};
/******/ 	}();
/******/ 	
/******/ 	/* webpack/runtime/global */
/******/ 	!function() {
/******/ 		__webpack_require__.g = (function() {
/******/ 			if (typeof globalThis === 'object') return globalThis;
/******/ 			try {
/******/ 				return this || new Function('return this')();
/******/ 			} catch (e) {
/******/ 				if (typeof window === 'object') return window;
/******/ 			}
/******/ 		})();
/******/ 	}();
/******/ 	
/******/ 	/* webpack/runtime/hasOwnProperty shorthand */
/******/ 	!function() {
/******/ 		__webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
/******/ 	}();
/******/ 	
/******/ 	/* webpack/runtime/make namespace object */
/******/ 	!function() {
/******/ 		// define __esModule on exports
/******/ 		__webpack_require__.r = function(exports) {
/******/ 			if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ 				Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ 			}
/******/ 			Object.defineProperty(exports, '__esModule', { value: true });
/******/ 		};
/******/ 	}();
/******/ 	
/************************************************************************/
var __webpack_exports__ = {};
// ESM COMPAT FLAG
__webpack_require__.r(__webpack_exports__);

// EXPORTS
__webpack_require__.d(__webpack_exports__, {
  "default": function() { return /* reexport */ Screenshot; }
});

// EXTERNAL MODULE: external {"root":"Vue","commonjs":"vue","commonjs2":"vue","amd":"vue"}
var external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_ = __webpack_require__(154);
// EXTERNAL MODULE: ./src/common/_ui/loading/index.js
var _ui_loading = __webpack_require__(403);
;// external "html2canvas"
var external_html2canvas_namespaceObject = require("html2canvas");
var external_html2canvas_default = /*#__PURE__*/__webpack_require__.n(external_html2canvas_namespaceObject);
// EXTERNAL MODULE: external "@kq_npm/client_common_vue/_types/global-event"
var global_event_ = __webpack_require__(3353);
var global_event_default = /*#__PURE__*/__webpack_require__.n(global_event_);
// EXTERNAL MODULE: external "@kq_npm/client_icons_vue"
var client_icons_vue_ = __webpack_require__(5698);
// EXTERNAL MODULE: ./src/common/_ui/message/index.js
var message = __webpack_require__(1092);
// EXTERNAL MODULE: external "@kq_npm/client_common_vue/configprovider/useGlobalConfig.js"
var useGlobalConfig_js_ = __webpack_require__(5711);
;// ./node_modules/vue-loader/dist/index.js??ruleSet[0].use[0]!./src/leaflet/screenshot/Screenshot.vue?vue&type=script&setup=true&lang=js


const _hoisted_1 = { class: "kq2d-screenshot" }
const _hoisted_2 = ["href"]
const _hoisted_3 = { style: {"text-align":"center"} }

;







// 国际化

const __default__ = {
  name: "Kq2dScreenshot"
};

/* harmony default export */ var Screenshotvue_type_script_setup_true_lang_js = (/*@__PURE__*/Object.assign(__default__, {
  props: {
  mapTarget: String,
  // 截图设置框初始位置
  position: {
    type: [String, Object],
    default: { top: 16, left: 16 }
  },
  // 组件初始化截图的宽度，默认值为mapView宽度的三分之一
  width: {
    type: Number
  },
  // 组件初始化截图的高度, 默认值为mapView高度的三分之一
  height: {
    type: Number
  },
  // 加载回调函数，如果该参数有值，则执行回调函数，如果为空，则执行默认逻辑
  upload: {
    type: Function,
    default: null
  }
},
  emits: ["close"],
  setup(__props, { expose: __expose, emit: __emit }) {

const { t, lang, locale } = (0,useGlobalConfig_js_.useLocale)();

const props = __props;
// 当前地图实例
let mapTarget = global_event_default().getCurrentMapTarget();

if (!mapTarget) {
  mapTarget = props.mapTarget;
}

// 表单labels
let labels = (0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.reactive)({
  x: locale.value.leaflet.width,
  y: locale.value.leaflet.height,
  xmax: document.documentElement.clientWidth || document.body.clientWidth,
  xmin: 0,
  ymax: document.documentElement.clientHeight || document.body.clientHeight,
  ymin: 0
});
// 宽高输入框值
let width_height = (0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.reactive)({
  x: null,
  y: null
});
// 表单校验
let rules = (0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.reactive)({
  x: [
    { required: true, message: t("leaflet.iptWidthTip"), trigger: "blur" }
    // { min: labels.xmin, max: labels.xmax, message: t('leaflet.iptWidthTip2'), trigger: "blur" }
  ],
  y: [
    { required: true, message: t('leaflet.iptHeightTip'), trigger: "blur" }
    // { min: labels.ymin, max: labels.ymax, message: t('leaflet.iptHeightTip2'), trigger: "blur" }
  ]
});
// 表单容器
let ruleFormRef = (0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.ref)(null);
// 控制组件显隐的变量
let showScreenshot = (0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.ref)(false);
// 控制宽高输入框basewindow的显隐
let showSetting = (0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.ref)(false);
// 下载截图的路径
let downloadImgSrc = (0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.ref)("");
// 截图容器Ref
let screenBodyRef = (0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.ref)(null);
// 地图图片容器
let mapImgRef = (0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.ref)(null);
// 下载容器
let downloadDomRef = (0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.ref)(null);
let dataURL = null;
let screenCanves = null;
let context = null;
let saveDiv = null;
// 操作类型
let actionType = "draw";
// 是否按下鼠标
let isDown = false;
// 起始点
let startPoint = [];
// 截图宽度大小
let widthImg = 0;
// 截图高度大小
let heightImg = 0;
// 截图左起始位置
let marginLeft = 0;
// 截图上起始位置
let marginTop = 0;
// 左上点
let leftTopPoint = [];
// 右下点
let rightBottom = [];
// 按下鼠标原始的左上点
let leftTopPointDown = [];
// 按下鼠标原始的右下点
let rightBottomDown = [];
let loading = null;

let emit = __emit;

/**
 * @description 输入宽度时触发
 * @param val - 宽度值
 */
function onChangeWidth(val) {
  setTimeout(() => {
    rightBottom[0] = rightBottom[0] + (val - widthImg);
    drawRect(leftTopPoint, rightBottom);
  }, 300);
}

/**
 * @description 输入高度时触发
 * @param val - 高度值
 */
function onChangeHeight(val) {
  setTimeout(() => {
    rightBottom[1] = rightBottom[1] + (val - heightImg);
    drawRect(leftTopPoint, rightBottom);
  }, 300);
}

/**
 * @description 鼠标按下事件
 */
function onMouseDown(e) {
  if (e.button === 2) {
    context.clearRect(0, 0, screenCanves.width, screenCanves.height);
    widthImg = screenCanves.width;
    heightImg = screenCanves.height;
    leftTopPoint = [];
    rightBottom = [];
    marginLeft = 0;
    marginTop = 0;
  } else {
    isDown = true;
    leftTopPointDown = leftTopPoint;
    rightBottomDown = rightBottom;
    startPoint = [e.offsetX, e.offsetY];
  }
}

/**
 * @description 鼠标弹起事件
 */
function onMouseUp(e) {
  isDown = false;
}

/**
 * @description 鼠标移动事件
 */
function onMouseMove(e) {
  let stopPoint = [e.offsetX, e.offsetY];
  if (!isDown) {
    actionType = getActionType(stopPoint);
    return;
  } else {
    countRectPoints(actionType, stopPoint);
  }
}

/**
 * @description 鼠标右键事件
 */
function contextMenu(e) {
  e.stopPropagation();
  return false;
}

/**
 * @description 计算左上、右下两个点
 * @param {string} actionType - 类型
 * @param {Array.<number>} stopPoint - 停止时的左边点
 */
function countRectPoints(actionType, stopPoint) {
  let x = stopPoint[0] - startPoint[0];
  let y = stopPoint[1] - startPoint[1];
  switch (actionType) {
    case "leftTop":
      leftTopPoint = [leftTopPointDown[0] + x, leftTopPointDown[1] + y];
      rightBottom = rightBottomDown;
      break;
    case "rightTop":
      leftTopPoint = [leftTopPointDown[0], leftTopPointDown[1] + y];
      rightBottom = [rightBottomDown[0] + x, rightBottomDown[1]];
      break;
    case "rightBottom":
      leftTopPoint = leftTopPointDown;
      rightBottom = [rightBottomDown[0] + x, rightBottomDown[1] + y];
      break;
    case "leftBottom":
      leftTopPoint = [leftTopPointDown[0] + x, leftTopPointDown[1]];
      rightBottom = [rightBottomDown[0], rightBottomDown[1] + y];
      break;
    case "left":
      leftTopPoint = [leftTopPointDown[0] + x, leftTopPointDown[1]];
      rightBottom = rightBottomDown;
      break;
    case "top":
      leftTopPoint = [leftTopPointDown[0], leftTopPointDown[1] + y];
      rightBottom = rightBottomDown;
      break;
    case "right":
      leftTopPoint = leftTopPointDown;
      rightBottom = [rightBottomDown[0] + x, rightBottomDown[1]];
      break;
    case "bottom":
      leftTopPoint = leftTopPointDown;
      rightBottom = [rightBottomDown[0], rightBottomDown[1] + y];
      break;
    case "move":
      leftTopPoint = [leftTopPointDown[0] + x, leftTopPointDown[1] + y];
      rightBottom = [rightBottomDown[0] + x, rightBottomDown[1] + y];
      break;
    case "draw":
      leftTopPoint = startPoint;
      rightBottom = stopPoint;
      break;
  }
  let minx = leftTopPoint[0] > rightBottom[0] ? rightBottom[0] : leftTopPoint[0];
  let miny = leftTopPoint[1] > rightBottom[1] ? rightBottom[1] : leftTopPoint[1];
  let maxx = leftTopPoint[0] > rightBottom[0] ? leftTopPoint[0] : rightBottom[0];
  let maxy = leftTopPoint[1] > rightBottom[1] ? leftTopPoint[1] : rightBottom[1];
  leftTopPoint = [minx, miny];
  rightBottom = [maxx, maxy];
  drawRect(leftTopPoint, rightBottom, true);
}

/**
 * @description 操作类型
 * @param {Array.<number>} point - 坐标点
 */
function getActionType(point) {
  let tolerance = 5;
  let leftTop_leftTopPoint = [leftTopPoint[0] - tolerance, leftTopPoint[1] - tolerance];
  let leftTop_rightBottom = [leftTopPoint[0] + 5, leftTopPoint[1] + tolerance];
  if (
    point[0] >= leftTop_leftTopPoint[0] &&
    point[0] <= leftTop_rightBottom[0] &&
    point[1] >= leftTop_leftTopPoint[1] &&
    point[1] <= leftTop_rightBottom[1]
  ) {
    screenCanves.style.cursor = "nw-resize";
    return "leftTop";
  }
  let rightTop_leftTopPoint = [rightBottom[0] - tolerance, leftTopPoint[1] - tolerance];
  let rightTop_rightBottom = [rightBottom[0] + tolerance, leftTopPoint[1] + tolerance];
  if (
    point[0] >= rightTop_leftTopPoint[0] &&
    point[0] <= rightTop_rightBottom[0] &&
    point[1] >= rightTop_leftTopPoint[1] &&
    point[1] <= rightTop_rightBottom[1]
  ) {
    screenCanves.style.cursor = "ne-resize";
    return "rightTop";
  }
  let rightBottom_leftTopPoint = [rightBottom[0] - tolerance, rightBottom[1] - tolerance];
  let rightBottom_rightBottom = [rightBottom[0] + tolerance, rightBottom[1] + tolerance];
  if (
    point[0] >= rightBottom_leftTopPoint[0] &&
    point[0] <= rightBottom_rightBottom[0] &&
    point[1] >= rightBottom_leftTopPoint[1] &&
    point[1] <= rightBottom_rightBottom[1]
  ) {
    screenCanves.style.cursor = "nw-resize";
    return "rightBottom";
  }
  let leftBottom_leftTopPoint = [leftTopPoint[0] - tolerance, rightBottom[1] - tolerance];
  let leftBottom_rightBottom = [leftTopPoint[0] + tolerance, rightBottom[1] + tolerance];
  if (
    point[0] >= leftBottom_leftTopPoint[0] &&
    point[0] <= leftBottom_rightBottom[0] &&
    point[1] >= leftBottom_leftTopPoint[1] &&
    point[1] <= leftBottom_rightBottom[1]
  ) {
    screenCanves.style.cursor = "ne-resize";
    return "leftBottom";
  }
  let left_leftTopPoint = [leftTopPoint[0] - tolerance, leftTopPoint[1] + tolerance];
  let left_rightBottom = [leftTopPoint[0] + tolerance, rightBottom[1] - tolerance];
  if (
    point[0] >= left_leftTopPoint[0] &&
    point[0] <= left_rightBottom[0] &&
    point[1] >= left_leftTopPoint[1] &&
    point[1] <= left_rightBottom[1]
  ) {
    screenCanves.style.cursor = "e-resize";
    return "left";
  }
  let top_leftTopPoint = [leftTopPoint[0] + tolerance, leftTopPoint[1] - tolerance];
  let top_rightBottom = [rightBottom[0] - tolerance, leftTopPoint[1] + tolerance];
  if (
    point[0] >= top_leftTopPoint[0] &&
    point[0] <= top_rightBottom[0] &&
    point[1] >= top_leftTopPoint[1] &&
    point[1] <= top_rightBottom[1]
  ) {
    screenCanves.style.cursor = "n-resize";
    return "top";
  }
  let right_leftTopPoint = [rightBottom[0] - tolerance, leftTopPoint[1] + tolerance];
  let right_rightBottom = [rightBottom[0] + tolerance, rightBottom[1] - tolerance];
  if (
    point[0] >= right_leftTopPoint[0] &&
    point[0] <= right_rightBottom[0] &&
    point[1] >= right_leftTopPoint[1] &&
    point[1] <= right_rightBottom[1]
  ) {
    screenCanves.style.cursor = "e-resize";
    return "right";
  }
  let bottom_leftTopPoint = [leftTopPoint[0] + tolerance, rightBottom[1] - tolerance];
  let bottom_rightBottom = [rightBottom[0] - tolerance, rightBottom[1] + tolerance];
  if (
    point[0] >= bottom_leftTopPoint[0] &&
    point[0] <= bottom_rightBottom[0] &&
    point[1] >= bottom_leftTopPoint[1] &&
    point[1] <= bottom_rightBottom[1]
  ) {
    screenCanves.style.cursor = "n-resize";
    return "bottom";
  }
  if (
    point[0] >= leftTopPoint[0] + tolerance &&
    point[0] <= rightBottom[0] - tolerance &&
    point[1] >= leftTopPoint[1] + tolerance &&
    point[1] <= rightBottom[1] - tolerance
  ) {
    screenCanves.style.cursor = "move";
    return "move";
  } else {
    screenCanves.style.cursor = "crosshair";
    return "draw";
  }
}
/**
 * @description 绘制遮罩
 * @param {Boolean} [syncSetting=false] - 是否同步设置框的宽高, 拖动截图框时触发，修改basewindow弹窗中的值不触发
 * @param {Boolean} [isInit = false] - 是否为初始化
 */
function drawRect(leftTopPoint, rightBottom, syncSetting = false, isInit = false) {
  const { width, height } = props;
  context.clearRect(0, 0, screenCanves.width, screenCanves.height);
  let rectPoints = [];
  if (isInit) {
    if (width) {
      rightBottom[0] = leftTopPoint[0] + width;
    }
    if (height) {
      rightBottom[1] = leftTopPoint[1] + height;
    }
  }
  rectPoints.push([leftTopPoint[0], rightBottom[1]]);
  rectPoints.push([rightBottom[0], rightBottom[1]]);
  rectPoints.push([rightBottom[0], leftTopPoint[1]]);
  rectPoints.push([leftTopPoint[0], leftTopPoint[1]]);
  rectPoints.push([leftTopPoint[0], rightBottom[1]]);

  // 绘制遮罩
  context.beginPath();
  context.lineTo(0, 0);
  context.lineTo(screenCanves.width, 0);
  context.lineTo(screenCanves.width, screenCanves.height);
  context.lineTo(0, screenCanves.height);
  context.lineTo(0, 0);
  for (let p = 0; p < rectPoints.length; p++) {
    context.lineTo(rectPoints[p][0], rectPoints[p][1]);
  }
  context.fillStyle = "rgba(0, 0, 0, 0.4)"; //内部使用浅灰色
  context.fill();
  context.closePath();

  // 绘制内矩形边框
  context.beginPath();
  context.strokeStyle = "#3388ff";
  context.lineWidth = 1;
  for (let p = 0; p < rectPoints.length; p++) {
    context.lineTo(rectPoints[p][0], rectPoints[p][1]);
  }
  context.stroke();
  context.closePath();

  // 绘制内矩形操作点
  rectPoints.push([(leftTopPoint[0] + rightBottom[0]) / 2, leftTopPoint[1]]);
  rectPoints.push([rightBottom[0], (leftTopPoint[1] + rightBottom[1]) / 2]);
  rectPoints.push([(leftTopPoint[0] + rightBottom[0]) / 2, rightBottom[1]]);
  rectPoints.push([leftTopPoint[0], (leftTopPoint[1] + rightBottom[1]) / 2]);
  for (let p = 0; p < rectPoints.length; p++) {
    context.beginPath();
    context.arc(rectPoints[p][0], rectPoints[p][1], 4, 0, Math.PI * 2, true);
    context.fillStyle = "#3388ff";
    context.fill();
    context.closePath();
  }
  widthImg = rightBottom[0] - leftTopPoint[0];
  heightImg = rightBottom[1] - leftTopPoint[1];
  marginLeft = -leftTopPoint[0];
  marginTop = -leftTopPoint[1];
  if (syncSetting) {
    width_height.x = widthImg;
    width_height.y = heightImg;
  }
}

let _transform = {
  transform: null,
  viewBox: null
};

// 逻辑类
let viewModel = null;

/**
 * @description 转换方法，解决svg截图时偏移问题
 */
function transformation(type) {
  try {
    let leaflet_overlay_pane = document
      .getElementById(mapTarget)
      .querySelector(".leaflet-pane")
      .getElementsByTagName("svg");
    for (let i = 0, item; (item = leaflet_overlay_pane[i++]); ) {
      if (type === 1) {
        _transform["transform"] = item.style.transform;
        _transform["viewBox"] = item.getAttribute("viewBox");
        item.removeAttribute("viewBox");
        item.style.transform = null;
      } else {
        item.style.transform = _transform["transform"];
        item.setAttribute("viewBox", _transform["viewBox"]);
      }
    }
  } catch (e) {}
}

/**
 * @description img url 转base64
 * @param {string} url - 图片url地址
 * @param {Object} image - 原img dom元素
 * @param {string} outputFormat - 输出格式
 */
function convertImgToBase64(url, image, outputFormat) {
  return new Promise((resolve, reject) => {
    var canvas = document.createElement("canvas");
    var ctx = canvas.getContext("2d");
    var img = new Image();
    img.crossOrigin = "Anonymous";
    img.onload = function () {
      canvas.height = img.height;
      canvas.width = img.width;
      ctx.drawImage(img, 0, 0);
      var dataURL = canvas.toDataURL(outputFormat || "image/png");
      image.setAttribute("src", dataURL);
      canvas = null;
      resolve("success");
    };
    img.onerror = function () {
      resolve("failed");
    };
    img.src = url;
  });
}

/**
 * @description 开始截图操作
 */
function start() {
  loading = _ui_loading/* default */.A.service({
    lock: true,
    text: "加载中...",
    background: "rgba(0, 0, 0, 0.5)",
    // target: document.getElementById(mapTarget)
    // target: document.querySelector(".kq-mapview")
    target: document.body
  });
  transformation(1);
  // 重置截图框最大范围
  labels.xmax = document.getElementById(mapTarget).clientWidth;
  labels.ymax = document.getElementById(mapTarget).clientHeight;
  showScreenshot.value = true;
  let mapEl = document.getElementById(mapTarget);
  screenCanves = document.createElement("canvas");
  screenCanves.id = "screenCanves";
  screenCanves.style.position = "absolute";
  screenCanves.style.top = "0px";
  screenCanves.style.left = "0px";
  screenCanves.style.zIndex = "998";
  screenCanves.width = mapEl.clientWidth;
  screenCanves.height = mapEl.clientHeight;
  context = screenCanves.getContext("2d");
  screenCanves.oncontextmenu = function () {
    return false;
  };
  screenBodyRef.value.appendChild(screenCanves);
  saveDiv = document.createElement("div");
  let headDom = document.getElementsByTagName("head");
  headDom[0].setAttribute("data-html2canvas", "true");
  let imgs = document.querySelectorAll(".leaflet-tile");
  let promiseList = [];
  imgs.forEach((item, index, array) => {
    if (item.tagName.toLowerCase() === "img") {
      array[index].setAttribute("crossorigin", "anonymous");
      // array[index].setAttribute("_src", item.getAttribute("src"));
      promiseList.push(convertImgToBase64(item.getAttribute("src"), array[index]));
    }
  });
  Promise.all(promiseList.map(promise => promise.catch(error => ({ error })))).then(results => {
    setTimeout(() => {
      external_html2canvas_default()(mapEl, {
        logging: true, // 启用日志记录以进行调试 (发现加上对去白边有帮助)
        allowTaint: true, // 否允许跨源图像污染画布
        // foreignObjectRendering: true,
        backgroundColor: null, // 解决生成的图片有白边
        useCORS: true, // 如果截图的内容里有图片,解决文件跨域问题
        // removeContainer: false,
        ignoreElements: e => {
          if (
            e.contains(mapEl) ||
            mapEl.contains(e) ||
            e.tagName === "STYLE" ||
            e.tagName === "LINK" ||
            e.getAttribute("data-html2canvas") != null
          ) {
            return false;
          }
          return true;
        }
      }).then(canvas => {
        try {
          (0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.nextTick)(() => {
            dataURL = canvas.toDataURL("image/png");
            mapImgRef.value.src = dataURL;
            mapImgRef.value.style.width = screenCanves.width + "px";
            mapImgRef.value.style.height = screenCanves.height + "px";
            mapImgRef.value.style.objectFit = "cover";
            mapImgRef.value.style.objectPosition = "left";
            saveDiv.style.width = screenCanves.width + "px";
            saveDiv.style.height = screenCanves.height + "px";
            saveDiv.style.backgroundImage = "url(" + dataURL + ")";
            saveDiv.style.backgroundRepeat = "no-repeat";
            // saveDiv.style.backgroundSize = screenCanves.width + "px " + screenCanves.height + "px";
            saveDiv.style.backgroundSize = "auto " + screenCanves.height + "px";
            saveDiv.style.position = "absolute";
            saveDiv.style.top = "0px";
            saveDiv.style.right = "0px";
            saveDiv.style.zIndex = "0";
            leftTopPoint = [Math.round(screenCanves.width * 0.33), Math.round(screenCanves.height * 0.33)];
            rightBottom = [Math.round(screenCanves.width * 0.66), Math.round(screenCanves.height * 0.66)];
            // 默认绘制3/1大小
            drawRect(leftTopPoint, rightBottom, true, true);
            loading.close();
            showSetting.value = true;
            // 恢复瓦片src属性
            // imgs.forEach((item, index, array) => {
            //   if (item.tagName.toLowerCase() === "img") {
            //     array[index].setAttribute("src", item.getAttribute("_src"));
            //   }
            // });
          });
        } catch (error) {
          console.log(error);
          (0,message/* default */.A)({ message: error, type: "warning", duration: 2000 });
          loading.close();
        }
      });
    }, 500);
  });
}

/**
 * @description 关闭
 */
function onClose() {
  try {
    transformation(0);
    showScreenshot.value = false;
    showSetting.value = false;
    downloadImgSrc.value = null;
    loading && loading.close();
    let _screenCanves = document.getElementById(screenCanves.id);
    _screenCanves && _screenCanves.remove();
    mapImgRef.value.removeAttribute("src");
    mapImgRef.value.removeAttribute("style");
    emit("close");
  } catch (e) {}
}

/**
 * @description 保存
 */
function onDown(formEl) {
  if (!formEl || !formEl.$refs.child) return;
  formEl.$refs.child.validate(valid => {
    if (valid) {
      loading = _ui_loading/* default */.A.service({
        lock: true,
        text: "正在保存...",
        background: "rgba(0, 0, 0, 0.5)",
        target: document.getElementById(mapTarget),
        customClass: "kq2d-screenshot-loading-class"
      });
      saveDiv.style.width = widthImg + "px";
      saveDiv.style.height = heightImg + "px";
      saveDiv.style.backgroundPosition = marginLeft + "px " + marginTop + "px";
      console.log(`${widthImg}|||${heightImg}, ${marginLeft}|||${marginTop}`);

      document.getElementById(mapTarget).appendChild(saveDiv);
      external_html2canvas_default()(saveDiv, {
        // logging: true, // 启用日志记录以进行调试 (发现加上对去白边有帮助)
        // allowTaint: true, // 否允许跨源图像污染画布
        backgroundColor: null // 解决生成的图片有白边
        // useCORS: true // 如果截图的内容里有图片,解决文件跨域问题
      }).then(canvas => {
        dataURL = canvas.toDataURL("image/png");
        (0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.nextTick)(() => {
          document.getElementById(mapTarget).removeChild(saveDiv);
          if (props.upload) {
            props.upload(dataURL);
          } else {
            downloadImgSrc.value = dataURL; // window.URL.createObjectURL(data);
            if (window.navigator.msSaveBlob) {
              // let blobObject = new Blob([data]);
              let blobObject = new Blob([dataURL]);
              window.navigator.msSaveBlob(blobObject, "截图.png");
            } else {
              (0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.nextTick)(() => {
                downloadDomRef.value.click();
              });
            }
          }
          loading.close();
        });
      });
    }
  });
}

(0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.onMounted)(() => {});

(0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.onBeforeUnmount)(() => {
  onClose();
});

__expose({
  start,
  close: onClose
});

return (_ctx, _cache) => {
  const _component_kq_input_number = (0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.resolveComponent)("kq-input-number")
  const _component_kq_form_item = (0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.resolveComponent)("kq-form-item")
  const _component_kq_form = (0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.resolveComponent)("kq-form")
  const _component_kq_button = (0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.resolveComponent)("kq-button")
  const _component_kq_base_window = (0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.resolveComponent)("kq-base-window")

  return (0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.withDirectives)(((0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.openBlock)(), (0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.createElementBlock)("section", _hoisted_1, [
    (0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.createElementVNode)("div", {
      ref_key: "screenBodyRef",
      ref: screenBodyRef,
      class: "screen-body",
      onMousedown: _cache[0] || (_cache[0] = $event => (onMouseDown($event))),
      onMouseup: _cache[1] || (_cache[1] = $event => (onMouseUp($event))),
      onMousemove: _cache[2] || (_cache[2] = $event => (onMouseMove($event)))
    }, [
      (0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.createElementVNode)("img", {
        ref_key: "mapImgRef",
        ref: mapImgRef,
        crossorigin: "anonymous"
      }, null, 512 /* NEED_PATCH */)
    ], 544 /* NEED_HYDRATION, NEED_PATCH */),
    (0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.createElementVNode)("a", {
      href: (0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.unref)(downloadImgSrc),
      download: "截图.png",
      ref_key: "downloadDomRef",
      ref: downloadDomRef,
      style: {}
    }, null, 8 /* PROPS */, _hoisted_2),
    (0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.createVNode)(_component_kq_base_window, {
      modelValue: (0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.unref)(showSetting),
      "onUpdate:modelValue": _cache[7] || (_cache[7] = $event => ((0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.isRef)(showSetting) ? (showSetting).value = $event : showSetting = $event)),
      titleIcon: (0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.unref)(client_icons_vue_.IconPlaneClip),
      single: false,
      showClose: false,
      fixed: "absolute",
      position: __props.position,
      title: (0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.unref)(t)('leaflet.screenshotTitle'),
      escClosable: false,
      padding: [16, 16, 16, 12],
      width: "204",
      id: "kq2d-screenshot-setting"
    }, {
      default: (0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.withCtx)(() => [
        (0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.createVNode)(_component_kq_form, {
          model: (0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.unref)(width_height),
          "label-width": "54px",
          rules: (0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.unref)(rules),
          ref_key: "ruleFormRef",
          ref: ruleFormRef
        }, {
          default: (0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.withCtx)(() => [
            (0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.createVNode)(_component_kq_form_item, {
              label: (0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.unref)(labels).x,
              prop: "x",
              style: {"margin-bottom":"8px"}
            }, {
              default: (0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.withCtx)(() => [
                (0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.createVNode)(_component_kq_input_number, {
                  modelValue: (0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.unref)(width_height).x,
                  "onUpdate:modelValue": _cache[3] || (_cache[3] = $event => (((0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.unref)(width_height).x) = $event)),
                  max: (0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.unref)(labels).xmax,
                  min: (0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.unref)(labels).xmin,
                  onInput: onChangeWidth
                }, null, 8 /* PROPS */, ["modelValue", "max", "min"])
              ]),
              _: 1 /* STABLE */
            }, 8 /* PROPS */, ["label"]),
            (0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.createVNode)(_component_kq_form_item, {
              label: (0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.unref)(labels).y,
              prop: "y",
              style: {"margin-bottom":"16px"}
            }, {
              default: (0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.withCtx)(() => [
                (0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.createVNode)(_component_kq_input_number, {
                  modelValue: (0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.unref)(width_height).y,
                  "onUpdate:modelValue": _cache[4] || (_cache[4] = $event => (((0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.unref)(width_height).y) = $event)),
                  max: (0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.unref)(labels).ymax,
                  min: (0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.unref)(labels).ymin,
                  onInput: onChangeHeight
                }, null, 8 /* PROPS */, ["modelValue", "max", "min"])
              ]),
              _: 1 /* STABLE */
            }, 8 /* PROPS */, ["label"])
          ]),
          _: 1 /* STABLE */
        }, 8 /* PROPS */, ["model", "rules"]),
        (0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.createElementVNode)("div", _hoisted_3, [
          (0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.createVNode)(_component_kq_button, {
            onClick: _cache[5] || (_cache[5] = $event => (onDown((0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.unref)(ruleFormRef)))),
            type: "primary"
          }, {
            default: (0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.withCtx)(() => [
              (0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.createTextVNode)((0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.toDisplayString)((0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.unref)(t)("leaflet.save")), 1 /* TEXT */)
            ]),
            _: 1 /* STABLE */
          }),
          (0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.createVNode)(_component_kq_button, {
            onClick: _cache[6] || (_cache[6] = $event => (onClose())),
            type: "danger"
          }, {
            default: (0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.withCtx)(() => [
              (0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.createTextVNode)((0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.toDisplayString)((0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.unref)(t)("leaflet.close")), 1 /* TEXT */)
            ]),
            _: 1 /* STABLE */
          })
        ])
      ]),
      _: 1 /* STABLE */
    }, 8 /* PROPS */, ["modelValue", "titleIcon", "position", "title"])
  ], 512 /* NEED_PATCH */)), [
    [external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.vShow, (0,external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_.unref)(showScreenshot)]
  ])
}
}

}));
;// ./src/leaflet/screenshot/Screenshot.vue?vue&type=script&setup=true&lang=js
 
;// ./src/leaflet/screenshot/Screenshot.vue



const __exports__ = Screenshotvue_type_script_setup_true_lang_js;

/* harmony default export */ var Screenshot = (__exports__);
// EXTERNAL MODULE: external "@kq_npm/client_common_vue/init.js"
var init_js_ = __webpack_require__(455);
var init_js_default = /*#__PURE__*/__webpack_require__.n(init_js_);
;// ./src/leaflet/screenshot/index.js
/*
 * Copyright (C) 2019 KQ GEO Technologies Co., Ltd.
 * All rights reserved.
 */



Screenshot.install = (Vue, opts) => {
  init_js_default()(Vue, opts);
  Vue.component(Screenshot.name, Screenshot);
};



/******/ 	return __webpack_exports__;
/******/ })()
;
});