UNPKG

@zpc_npm/vue-iclient-common

Version:

KQGIS iClient for Vue.js

1,111 lines (958 loc) 36 kB
/******/ (function() { // webpackBootstrap /******/ "use strict"; /******/ // The require scope /******/ var __webpack_require__ = {}; /******/ /************************************************************************/ /******/ /* 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/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__, { "mapDrawUtils": function() { return /* binding */ mapDrawUtils; }, "mapLayerUtils": function() { return /* binding */ mapLayerUtils; }, "mapViewUtils": function() { return /* binding */ mapViewUtils; }, "utils": function() { return /* binding */ utils; } }); ;// CONCATENATED MODULE: external "@zpc_npm/vue-iclient-common/_types/global-event" var global_event_namespaceObject = require("@zpc_npm/vue-iclient-common/_types/global-event"); var global_event_default = /*#__PURE__*/__webpack_require__.n(global_event_namespaceObject); ;// CONCATENATED MODULE: external "@zpc_npm/vue-iclient-common/_utils/util" var util_namespaceObject = require("@zpc_npm/vue-iclient-common/_utils/util"); ;// CONCATENATED MODULE: ./src/common/_utils/gis-utils.js /** * Author: ZL * Date: 2022.8.15 * Description: 地图视图操作通用中转类 * 通用组件为适配不同地图框架的视图的操作, * 不同的视图状态mapType,不同的地图对象mapTarget做方法的参数来区分转发的对象 * 包括视图的操作方法绘图、获取图层数据、图层操作等 * 都在该对象做中转操作,不同的视图状态,调用对应视图的方法。通用组件和视图相关的操作调用这个中间类 * 该类暂时提供给通用组件使用,特定的组件直接用view的方法 */ /** * 通用方法 */ const utils = { /** * 注册map切换监听 * @param {function} fn */ bindChangeMapEvents(fn) { global_event_default().on("changeMapType", fn); }, /** * 移除map切换监听 * @param {function} fn */ offChangeMapEvents(fn) { global_event_default().off("changeMapType", fn); }, /** * 根据target获取webmap对象 * @param {string} mapTarget 地图的target * @param {function} callFun */ getWebMap(mapTarget, callFun) { global_event_default().getWebMapByMapTarget(mapTarget, callFun); }, /** * 根据target获取地图类型 * @param {string} mapTarget 地图的target * @returns {*|string} */ getMapTypeByMapTarget(mapTarget) { return global_event_default().getMapTypeByMapTarget(mapTarget); } }; /** * map相关、图层数据相关操作 */ const mapViewUtils = { /** * 给mapview绑定事件。 * 如果没有找到对应的view对象,说明view还不存在,就添加load-map事件监听。 * @param {string} type 事件类型 * @param {function} fn * @param {string} mapTarget 绑定地图的target */ bindViewEvents(type, fn, mapTarget) { // mapTarget为空时,获取当前操作的mapTarget if (!mapTarget || mapTarget === "") { mapTarget = global_event_default().getCurrentMapTarget(); } const mapInfo = global_event_default().getMapInfoByMapTarget(mapTarget); if (!mapInfo) { console.error("组件未找到绑定地图"); return; } let _webmap = mapInfo.webMap; if (_webmap) { /** * 如果是mounted,这个事件表示监听view初始化完成事件, * 这里能获取到view已经能获取到,表示事件已经过时,不会执行到,就不需要监听 */ if (type === "mounted" && _webmap.map) { return; } _webmap.on(type, fn); } // _webmap不存在时,就监听视图加载事件load-map、load-viewer,等待结束后再注册。 else { const mapType = global_event_default().getMapTypeByMapTarget(mapTarget); if (mapType === "leaflet") { global_event_default().once("load-map", e => { // 判断是否同一个地图对象的key if (e.eventMapTarget === mapTarget) { _webmap = global_event_default().getMapInfoByMapTarget(mapTarget).webMap; if (_webmap) { _webmap.on(type, fn); } } }); } else if (mapType === "cesium") { global_event_default().once("load-viewer", e => { if (e.eventMapTarget === mapTarget) { _webmap = global_event_default().getMapInfoByMapTarget(mapTarget).webMap; if (_webmap) { _webmap.on(type, fn); } } }); } } }, /** * 给mapview绑定事件。只执行一次 * @param {string} type * @param {function} fn * @param {string} mapTarget */ bindViewOnceEvents(type, fn, mapTarget) { if (!mapTarget || mapTarget === "") { mapTarget = global_event_default().getCurrentMapTarget(); } const mapInfo = global_event_default().getMapInfoByMapTarget(mapTarget); if (!mapInfo) { console.error("组件未找到绑定地图"); return; } let _webmap = mapInfo.webMap; if (_webmap) { // 如果是mounted,这个事件表示监听view初始化完成事件, // 这里能获取到view已经能获取到,表示事件已经过时,不会执行到,就不需要监听 if (type === "mounted" && _webmap.map) { return; } _webmap.once(type, fn); } else { const mapType = global_event_default().getMapTypeByMapTarget(mapTarget); if (mapType === "leaflet") { global_event_default().once("load-map", e => { // 判断是否同一个地图对象的key if (e.eventMapTarget === mapTarget) { _webmap = global_event_default().getMapInfoByMapTarget(mapTarget).webMap; if (_webmap) { _webmap.once(type, fn); } } }); } else if (mapType === "cesium") { global_event_default().once("load-viewer", e => { if (e.eventMapTarget === mapTarget) { _webmap = global_event_default().getMapInfoByMapTarget(mapTarget).webMap; if (_webmap) { _webmap.once(type, fn); } } }); } } }, /** * 移除监听 * @param {string} type * @param {function} fn * @param {string} mapTarget */ offViewEvents(type, fn, mapTarget) { if (!mapTarget || mapTarget === "") { mapTarget = global_event_default().getCurrentMapTarget(); } const mapInfo = global_event_default().getMapInfoByMapTarget(mapTarget); if (!mapInfo) { return; } let _webmap = mapInfo.webMap; if (_webmap) { _webmap.off(type, fn); } }, /** * 给map绑定事件 * 如果没有找到对应的view对象,说明view还不存在,就添加load-map事件监听 * @param {string} type * @param {function} fn * @param {string} mapTarget */ bindMapEvents(type, fn, mapTarget) { if (!mapTarget || mapTarget === "") { mapTarget = global_event_default().getCurrentMapTarget(); } const mapType = global_event_default().getMapTypeByMapTarget(mapTarget); let _webmap = global_event_default().getMapInfoByMapTarget(mapTarget).webMap; if (mapType === "leaflet") { if (_webmap) { // 如果是mounted,这个事件表示监听view初始化完成事件, // 这里能获取到view已经能获取到,表示事件已经过时,不会执行到,就不需要监听 if (type === "mounted" && _webmap.map) { return; } _webmap.map.on(type, fn); } else { global_event_default().once("load-map", e => { // 判断是否同一个地图对象的key if (e.eventMapTarget === mapTarget) { _webmap = global_event_default().getMapInfoByMapTarget(mapTarget).webMap; if (_webmap) { _webmap.map.on(type, fn); } } }); } } }, /** * 移除监听 * @param {string} type * @param {function} fn 监听函数,支持传空 * @param {string} mapTarget */ offMapEvents(type, fn, mapTarget) { if (!mapTarget || mapTarget === "") { mapTarget = global_event_default().getCurrentMapTarget(); } const mapType = global_event_default().getMapTypeByMapTarget(mapTarget); let _webmap = global_event_default().getMapInfoByMapTarget(mapTarget).webMap; if (mapType === "leaflet") { if (_webmap) { if (fn) { _webmap.map.off(type, fn); } else { _webmap.map.off(type); } } } }, /** * 地图定位到bounds * @param {string} mapTarget * @param {Object} rect84 四至的经纬度坐标 [minx, miny, maxx, maxy] */ fitBounds(mapTarget, currentSelectedNode) { if (!mapTarget || mapTarget === "") { mapTarget = global_event_default().getCurrentMapTarget(); } const mapType = global_event_default().getMapTypeByMapTarget(mapTarget); let _webmap = global_event_default().getMapInfoByMapTarget(mapTarget).webMap; if (mapType === "leaflet" && currentSelectedNode.rect84) { let rect84 = currentSelectedNode.rect84; let bounds84 = [[rect84[1], rect84[0]], [rect84[3], rect84[2]]]; _webmap.map.fitBounds(bounds84); } else if (mapType === "cesium") { _webmap._layerManager.flyToBounds(currentSelectedNode.guid); } }, /** * 获取视图中心 * @param {string} mapTarget * @returns 数组。 二维:经度(x)、纬度(y); 三维:经度(x)、纬度(y)、高度(z)、指向、视角、滚动 */ getViewPosition(mapTarget) { if (!mapTarget || mapTarget === "") { mapTarget = global_event_default().getCurrentMapTarget(); } const mapType = global_event_default().getMapTypeByMapTarget(mapTarget); let _webmap = global_event_default().getMapInfoByMapTarget(mapTarget).webMap; if (mapType === "leaflet") { let center = _webmap.map.getCenter(); let zoom = _webmap.map.getZoom(); return { position: [center.lng, center.lat], zoom: zoom }; } else if (mapType === "cesium") { return _webmap.getViewPosition(); } }, /** * 设置视图中心 * @param {string} mapTarget * @param {Object} view 视图数据对象 */ setViewPosition(mapTarget, view) { if (!mapTarget || mapTarget === "") { mapTarget = global_event_default().getCurrentMapTarget(); } const mapType = global_event_default().getMapTypeByMapTarget(mapTarget); let _webmap = global_event_default().getMapInfoByMapTarget(mapTarget).webMap; if (mapType === "leaflet") { _webmap.map.setView([view.position[1], view.position[0]], view.zoom); } else { _webmap.setViewPosition(view); } }, /** * 从绘图控制类中获取默认样式 * @param mapTarget * @returns {{fillColor: string, color: string, fillOpacity: number, weight: number, dashArray: string}|null} */ getDefaultStyle(mapTarget) { if (!mapTarget || mapTarget === "") { mapTarget = global_event_default().getCurrentMapTarget(); } const mapType = global_event_default().getMapTypeByMapTarget(mapTarget); let _webmap = global_event_default().getMapInfoByMapTarget(mapTarget).webMap; if (mapType === "leaflet") { return _webmap ? _webmap.mapDraw.getDefaultDrawStyle() : null; } else if (mapType === "cesium") { return _webmap ? _webmap._drawManager._defaultStyle : null; } }, /** * 地图刷新,重新加载图层。暂时只有featureedit使用 * @param mapTarget * @param guid 图层的guid,用于3d的重新加载图层 */ panByrefesh(mapTarget, guid) { if (!mapTarget || mapTarget === "") { mapTarget = global_event_default().getCurrentMapTarget(); } const mapType = global_event_default().getMapTypeByMapTarget(mapTarget); let _webmap = global_event_default().getMapInfoByMapTarget(mapTarget).webMap; if (mapType === "leaflet") { if (_webmap) { // leaflet偏移地图 来达成重新加载 _webmap.map.panBy([0, -1]); } } else if (mapType === "cesium") { if (_webmap) { // cesium执行reload方法 _webmap._layerManager.refreshLayerByGuid(guid); } } } }; /** * layer相关操作 */ const mapLayerUtils = { removeLayer(mapTarget, layer) { if (!mapTarget || mapTarget === "") { mapTarget = global_event_default().getCurrentMapTarget(); } const mapType = global_event_default().getMapTypeByMapTarget(mapTarget); let _webmap = global_event_default().getMapInfoByMapTarget(mapTarget).webMap; if (mapType === "leaflet") { if (_webmap) { if (_webmap.map.hasLayer(layer)) { _webmap.map.removeLayer(layer); } } } else { if (_webmap) { _webmap._drawManager.clearAll(); } } }, addTo(mapTarget, layer) { if (!mapTarget || mapTarget === "") { mapTarget = global_event_default().getCurrentMapTarget(); } const mapType = global_event_default().getMapTypeByMapTarget(mapTarget); let _webmap = global_event_default().getMapInfoByMapTarget(mapTarget).webMap; if (mapType === "leaflet") { if (_webmap) { layer.addTo(_webmap.map); } } }, /** * 设置多个图层的显示与隐藏 且控制树的勾选 * @param {string} mapTarget * @param {array} ids 图层的GUID数组 * @param {boolean} visible true, false * @param {Object} eventTarget 触发方法的对象。该方法有执行其他监听事件,为防止方法死循环,该参数会传给监听事件 * @fires event:resetLayerDatas */ setLayerVisibleStateByIds(mapTarget, ids, visible, eventTarget) { if (!mapTarget || mapTarget === "") { mapTarget = global_event_default().getCurrentMapTarget(); } const mapType = global_event_default().getMapTypeByMapTarget(mapTarget); let _webmap = global_event_default().getMapInfoByMapTarget(mapTarget).webMap; if (mapType === "leaflet") { if (_webmap) _webmap.setLayerVisibleStateByIds(ids, visible, eventTarget); } else if (mapType === "cesium") { if (_webmap) _webmap._layerManager.setLayerVisibleStateByIds(ids, visible); } }, /** * 控制底图显隐 * @param {string} mapTarget * @param {string} layerKey 底图图层数据的key * @param {Object} layerInfo 图层数据 * @param {boolean} visible 显隐 */ showBaseLayer(mapTarget, layerKey, layerInfo, visible) { if (!mapTarget || mapTarget === "") { mapTarget = global_event_default().getCurrentMapTarget(); } const mapType = global_event_default().getMapTypeByMapTarget(mapTarget); let _webmap = global_event_default().getMapInfoByMapTarget(mapTarget).webMap; if (mapType === "leaflet") { if (_webmap) { _webmap.showBaseLayer(layerKey, layerInfo, visible); } } else if (mapType === "cesium") { if (_webmap) { _webmap._layerManager._scenceView.showBaseLayer(layerKey, layerInfo, visible); } } }, /** * 获取显示的底图数据 * @param {string} mapTarget */ getCheckedBaseLayerKey(mapTarget) { if (!mapTarget || mapTarget === "") { mapTarget = global_event_default().getCurrentMapTarget(); } const mapType = global_event_default().getMapTypeByMapTarget(mapTarget); let _webmap = global_event_default().getMapInfoByMapTarget(mapTarget).webMap; if (mapType === "leaflet") { if (_webmap) { return _webmap.getCheckedBaseLayerKey(); } } }, /** * 设置图层透明度 * @param {string} mapTarget * @param {string} guid 图层数据的唯一标识 * @param {number} opacity 透明度 0-1 */ setLayerOpacityStateById(mapTarget, guid, opacity) { if (!mapTarget || mapTarget === "") { mapTarget = global_event_default().getCurrentMapTarget(); } const mapType = global_event_default().getMapTypeByMapTarget(mapTarget); let _webmap = global_event_default().getMapInfoByMapTarget(mapTarget).webMap; if (mapType === "leaflet") { if (_webmap) { _webmap.setLayerOpacityStateById(guid, opacity); } } else if (mapType === "cesium") { if (_webmap) { _webmap._layerManager.setLayerOpacityById(guid, opacity); } } }, /** * 图层置顶 * @param {string} mapTarget * @param {string} guid 图层数据的唯一标识 * @param {boolean} isFront 是否置顶 true-置顶 false-还原 */ setLayerBringToFrontById(mapTarget, guid, isFront) { if (!mapTarget || mapTarget === "") { mapTarget = global_event_default().getCurrentMapTarget(); } const mapType = global_event_default().getMapTypeByMapTarget(mapTarget); let _webmap = global_event_default().getMapInfoByMapTarget(mapTarget).webMap; if (mapType === "leaflet") { _webmap.setLayerBringToFrontById(guid, isFront); } else if (mapType === "cesium") { _webmap._layerManager.setLayerBringToFrontById(guid, isFront); } }, /** * 设置layer的样式 * @param {string} mapTarget * @param {L.path|L.geojson} layer 修改样式的对象 * @param {Object} style 样式 */ setLayerStyle(mapTarget, layer, style) { if (!mapTarget || mapTarget === "") { mapTarget = global_event_default().getCurrentMapTarget(); } const mapType = global_event_default().getMapTypeByMapTarget(mapTarget); if (mapType === "leaflet") { layer.setStyle(style); } }, /** * 获取显示的图层的key * @param mapTarget * @returns {Array} */ getLayerCheckedListKey(mapTarget) { if (!mapTarget || mapTarget === "") { mapTarget = global_event_default().getCurrentMapTarget(); } const mapType = global_event_default().getMapTypeByMapTarget(mapTarget); let _webmap = global_event_default().getMapInfoByMapTarget(mapTarget).webMap; if (mapType === "leaflet") { return _webmap ? _webmap.getLayerCheckedListKey() : null; } else if (mapType === "cesium") { return _webmap ? _webmap._layerManager.getLayerCheckedListKey() : null; } }, /** * 获取显示图层的数据 * @param {string} mapTarget * @returns {Array} */ getLayerCheckedList(mapTarget) { if (!mapTarget || mapTarget === "") { mapTarget = global_event_default().getCurrentMapTarget(); } const mapType = global_event_default().getMapTypeByMapTarget(mapTarget); let _webmap = global_event_default().getMapInfoByMapTarget(mapTarget).webMap; if (mapType === "leaflet") { return _webmap ? _webmap.getLayerCheckedList() : null; } else if (mapType === "cesium") { return _webmap ? _webmap._layerManager.getLayerCheckedList() : null; } }, /** * 获取勾选图层的图层数据,如果是有融合图层,则只返回融合图层的子图层 * @param {string} mapTarget * @returns {*|null} */ getLayerDataByLayerChecked(mapTarget) { if (!mapTarget || mapTarget === "") { mapTarget = global_event_default().getCurrentMapTarget(); } const mapType = global_event_default().getMapTypeByMapTarget(mapTarget); let _webmap = global_event_default().getMapInfoByMapTarget(mapTarget).webMap; if (mapType === "leaflet") { return _webmap ? _webmap.getLayerDataByLayerChecked() : null; } else if (mapType === "cesium") { return _webmap ? _webmap._layerManager.getLayerDataByLayerChecked() : null; } }, /** * 获取所有图层的key(包括adddata组件的临时图层数据,不包括底图baselayer) * @param {string}mapTarget * @returns {Array} */ getLayerDataKey(mapTarget) { if (!mapTarget || mapTarget === "") { mapTarget = global_event_default().getCurrentMapTarget(); } const mapType = global_event_default().getMapTypeByMapTarget(mapTarget); let _webmap = global_event_default().getMapInfoByMapTarget(mapTarget).webMap; if (mapType === "leaflet") { return _webmap ? _webmap.getLayerDataKey() : null; } else if (mapType === "cesium") { return _webmap ? _webmap._layerManager.getLayerDataKey() : null; } }, /** * 获取所有图层的数据(包括adddata组件的临时图层数据,不包括底图baselayer) * @param {string} mapTarget * @returns {array} */ getLayerData(mapTarget) { if (!mapTarget || mapTarget === "") { mapTarget = global_event_default().getCurrentMapTarget(); } const mapType = global_event_default().getMapTypeByMapTarget(mapTarget); let _webmap = global_event_default().getMapInfoByMapTarget(mapTarget).webMap; if (mapType === "leaflet") { return _webmap ? _webmap.getLayerData() : null; } else if (mapType === "cesium") { return _webmap ? _webmap._layerManager.getLayerData() : null; } }, /** * 获取树结构的图层数据 * @param {string} mapTarget * @returns {null|Array} */ getLayerTreeData(mapTarget) { // mapTarget为空了 获取当前操作状态mapTarget if (!mapTarget || mapTarget === "") { mapTarget = global_event_default().getCurrentMapTarget(); } // 类型 const mapType = global_event_default().getMapTypeByMapTarget(mapTarget); // 地图视图的viewmodel let _webmap = global_event_default().getMapInfoByMapTarget(mapTarget).webMap; if (mapType === "leaflet") { return _webmap ? _webmap.getLayerTreeData() : null; } else if (mapType === "cesium") { return _webmap ? _webmap._layerManager.getLayerTreeData() : null; } }, /** * 设置图层上移 * @param {string} mapTarget * @param {string} guid 图层数据的唯一标识 */ raiseLayerByTreeId(mapTarget, guid) { if (!mapTarget || mapTarget === "") { mapTarget = global_event_default().getCurrentMapTarget(); } const mapType = global_event_default().getMapTypeByMapTarget(mapTarget); let _webmap = global_event_default().getMapInfoByMapTarget(mapTarget).webMap; if (mapType === "leaflet") { _webmap.raiseLayerByTreeId(guid); } else if (mapType === "cesium") { _webmap._layerManager.raiseLayerById(guid); } }, /** * 设置图层下移 * @param {string} mapTarget * @param {string} guid 图层数据的唯一标识 */ lowerLayerByTreeId(mapTarget, guid) { if (!mapTarget || mapTarget === "") { mapTarget = global_event_default().getCurrentMapTarget(); } const mapType = global_event_default().getMapTypeByMapTarget(mapTarget); let _webmap = global_event_default().getMapInfoByMapTarget(mapTarget).webMap; if (mapType === "leaflet") { _webmap.lowerLayerByTreeId(guid); } else if (mapType === "cesium") { _webmap._layerManager.lowerLayerById(guid); } }, /** * 还原所有图层顺序 * @param mapTarget */ resetLayerZIndex(mapTarget) { if (!mapTarget || mapTarget === "") { mapTarget = global_event_default().getCurrentMapTarget(); } const mapType = global_event_default().getMapTypeByMapTarget(mapTarget); let _webmap = global_event_default().getMapInfoByMapTarget(mapTarget).webMap; if (mapType === "leaflet") { _webmap.resetLayerZIndex(); } else if (mapType === "cesium") { _webmap._layerManager.resetLayerIndex(); } }, delTempData(mapTarget, guid, eventTarget) { if (!mapTarget || mapTarget === "") { mapTarget = global_event_default().getCurrentMapTarget(); } const mapType = global_event_default().getMapTypeByMapTarget(mapTarget); let _webmap = global_event_default().getMapInfoByMapTarget(mapTarget).webMap; if (mapType === "leaflet") { _webmap.delTempData(guid, eventTarget); } else if (mapType === "cesium") { _webmap._layerManager.delTempData(guid); } } }; /** * 绘制相关操作 */ const mapDrawUtils = { /** * 鼠标拉框操作绘图。leaflet同时支持单点和拉框,cesium只能同时使用一个拉框 * @param {string} mapTarget * @param {Function} callbackFun 绘制结束后回调函数 * @param {boolean} isMultiple 是执行多次,还是一次, 默认: false * @param {boolean} isPoint 是否是点选, 默认: false * @param {string} imgUrl 根据不同的业务设置不同的地图鼠标状态 * @param {Object} drawStyle 绘制样式,可选,有默认 */ startDrawRectPoint(mapTarget, callbackFun, isMultiple, isPoint, imgUrl, drawStyle) { if (!mapTarget || mapTarget === "") { mapTarget = global_event_default().getCurrentMapTarget(); } const mapType = global_event_default().getMapTypeByMapTarget(mapTarget); let _webmap = global_event_default().getMapInfoByMapTarget(mapTarget).webMap; if (mapType === "leaflet") { const mapdraw = _webmap.mapDraw; mapdraw.startDrawRectPoint(callbackFun, isMultiple, isPoint, imgUrl, drawStyle); } else if (mapType === "cesium") { if (_webmap) { _webmap._drawManager.startDraw("rectangle", drawStyle, callbackFun); } } }, /** * 根据点、像素半径,生成当前比例尺下,矩形的geojson。暂时只支持leaflet * @param mapTarget * @param {Object} point GeoJSON格式中point格式 * @param {number} tolerance * @returns {GeoJSON} */ createRectByPoint(mapTarget, point, tolerance = 5) { if (!mapTarget || mapTarget === "") { mapTarget = global_event_default().getCurrentMapTarget(); } const mapType = global_event_default().getMapTypeByMapTarget(mapTarget); let _webmap = global_event_default().getMapInfoByMapTarget(mapTarget).webMap; if (mapType === "leaflet") { const webMapInfo = _webmap.webMapInfo; const res = webMapInfo && webMapInfo.resolutions ? webMapInfo.resolutions : null; const units = webMapInfo ? webMapInfo.spatialReference.units : "meter"; let latlng = { lat: point.coordinates[1], lng: point.coordinates[0] }; return (0,util_namespaceObject.createRectByPoint)(_webmap.map.getZoom(), res, units, latlng, tolerance); } }, /** * 点坐标绘制并定位 * @param {string} mapTarget * @param {Array} coordinate 坐标数组。[x, y] * @param {Object} drawStyle 绘制样式 * @param {Function} callback 回调函数 */ setLocationPoint(mapTarget, coordinate, drawStyle, callback) { if (!mapTarget || mapTarget === "") { mapTarget = global_event_default().getCurrentMapTarget(); } const mapType = global_event_default().getMapTypeByMapTarget(mapTarget); let _webmap = global_event_default().getMapInfoByMapTarget(mapTarget).webMap; const _geoJSON = { type: "Feature", properties: {}, geometry: { type: "Point", coordinates: mapType === "leaflet" ? [coordinate[0], coordinate[1]] : [coordinate[0], coordinate[1], coordinate[2]] } }; const options = drawStyle || { color: "#fb030f", dashArray: "1", fillColor: "#000000", fillOpacity: 0.5, weight: 2 }; if (mapType === "leaflet") { const location = _webmap.mapDraw.creareGeometryByGeoJson(_geoJSON, options); _webmap.map.setView([coordinate[1], coordinate[0]], _webmap.map.getZoom()); location.addTo(_webmap.map); callback && callback(location); } else if (mapType === "cesium") { _webmap._drawManager.drawFromGeojson(_geoJSON, "location", callback, drawStyle, true); } }, /** * 关闭拉框查询的状态 * @param {string} mapTarget */ stopDrawRectPoint(mapTarget) { if (!mapTarget || mapTarget === "") { mapTarget = global_event_default().getCurrentMapTarget(); } const mapType = global_event_default().getMapTypeByMapTarget(mapTarget); let _webmap = global_event_default().getMapInfoByMapTarget(mapTarget).webMap; if (mapType === "leaflet") { const mapdraw = _webmap.mapDraw; return mapdraw.stopDrawRectPoint(); } }, /** * 绘图操作停止,不包含拉框绘图的操作 * @param mapTarget */ stopDrawState(mapTarget) { if (!mapTarget || mapTarget === "") { mapTarget = global_event_default().getCurrentMapTarget(); } const mapType = global_event_default().getMapTypeByMapTarget(mapTarget); let _webmap = global_event_default().getMapInfoByMapTarget(mapTarget).webMap; if (mapType === "leaflet") { if (_webmap) { _webmap.map.stop(); _webmap.mapDraw.stopDrawState(); } } else if (mapType === "cesium") { if (_webmap) { _webmap._drawManager.stopDraw(); } } }, /** * 移除指定分组中的图形对象,cesium会删除分组中的所有图形对象 * @param {string} mapTarget * @param {L.layer} geometry 绘图对象 * @param {string} idCustom 绘图分组的id名称, 为空时查找所有的匹配 */ removeGeometry(mapTarget, geometry, idCustom) { if (!mapTarget || mapTarget === "") { mapTarget = global_event_default().getCurrentMapTarget(); } const mapType = global_event_default().getMapTypeByMapTarget(mapTarget); let _webmap = global_event_default().getMapInfoByMapTarget(mapTarget).webMap; if (mapType === "leaflet") { if (_webmap) _webmap.mapDraw.removeGeometry(geometry, idCustom); } else if (mapType === "cesium") { if (_webmap) { _webmap._drawManager.removeGeojsonByIdCustom(idCustom); } } }, /** * 删除指定绘图分组的所有图形.cesium没有分组,会删除所有 * @param {string} mapTarget * @param {string} idCustom 分组的key */ removeGeometryByIdCustom(mapTarget, idCustom) { if (!mapTarget || mapTarget === "") { mapTarget = global_event_default().getCurrentMapTarget(); } const mapType = global_event_default().getMapTypeByMapTarget(mapTarget); let _webmap = global_event_default().getMapInfoByMapTarget(mapTarget).webMap; if (mapType === "leaflet") { if (_webmap) _webmap.mapDraw.removeGeometryByIdCustom(idCustom); } else if (mapType === "cesium") { if (_webmap) { _webmap._drawManager.clearAll(); } } }, /** * 根据坐标绘制图形,并定位 * @param {string} mapTarget * @param {object} feature geojson对象 支持FeatureCollection GeometryCollection feature polygon的GeoJson格式 * @param {string} idCustom 绘图结果保存到layer分组的名称 默认result * @param {Function} callFun 回调方法 返回绘制的layer对象 * @param {Object} drawStyle 绘图样式 * @param {object} fillStyle 填充样式 颜色与宽度 例:{lineColor: 'rgba(0, 0, 255, 1)', lineWidth: '2px'} * @param {boolean} isFill 是否填充,默认为true */ drawAndFlytoGeometry(mapTarget, feature, idCustom, callFun, drawStyle, fillStyle, isFill) { if (!mapTarget || mapTarget === "") { mapTarget = global_event_default().getCurrentMapTarget(); } const mapType = global_event_default().getMapTypeByMapTarget(mapTarget); let _webmap = global_event_default().getMapInfoByMapTarget(mapTarget).webMap; if (mapType === "leaflet") { if (_webmap) _webmap.mapDraw.drawAndFlytoGeometry(feature, idCustom, callFun, drawStyle, fillStyle, isFill); } else if (mapType === "cesium") { if (_webmap) { _webmap._drawManager.drawFromGeojson(feature, idCustom, callFun, null, true); } } }, /** * 图形绘制 并闪烁 (不定位) * @param {string} mapTarget * @param {Object} feature geojson对象 支持FeatureCollection GeometryCollection feature polygon的GeoJson格式 * @param {string} idCustom 绘图结果保存到layer分组的名称 默认result */ locationDrawNotPos(mapTarget, feature, idCustom) { if (!mapTarget || mapTarget === "") { mapTarget = global_event_default().getCurrentMapTarget(); } const mapType = global_event_default().getMapTypeByMapTarget(mapTarget); let _webmap = global_event_default().getMapInfoByMapTarget(mapTarget).webMap; if (mapType === "leaflet") { if (_webmap) _webmap.mapDraw.locationDrawNotPos(feature, idCustom); } else if (mapType === "cesium") { if (_webmap) { _webmap._drawManager.drawFromGeojson(feature, idCustom, null, null, false); } } }, /** * 开启绘图操作 * @param mapTarget * @param {Function} callbackFun 回调函数,返回绘图坐标和绘图事件对象 * @param {string} geometryType 绘制类型 * @param {string} idCustom 绘图分组 * @param {Object} geometryOptions 绘图参数 */ startDraw(mapTarget, callbackFun, geometryType, idCustom, geometryOptions) { if (!mapTarget || mapTarget === "") { mapTarget = global_event_default().getCurrentMapTarget(); } const mapType = global_event_default().getMapTypeByMapTarget(mapTarget); let _webmap = global_event_default().getMapInfoByMapTarget(mapTarget).webMap; if (mapType === "leaflet") { if (_webmap) { _webmap.mapDraw.startDraw(callbackFun, geometryType, idCustom, geometryOptions); } } else if (mapType === "cesium") { if (_webmap) { _webmap._drawManager.startDraw(geometryType, geometryOptions, callbackFun); } } }, /** * 开启、关闭绘图的编辑操作 * @param mapTarget * @param {Object} layer 绘图对象 * @param {boolean} isEnable 开启、关闭 * @param {Function} callbackFun 回调函数,返回绘图对象和事件 */ enableEdit(mapTarget, layer, isEnable, callbackFun) { if (!mapTarget || mapTarget === "") { mapTarget = global_event_default().getCurrentMapTarget(); } const mapType = global_event_default().getMapTypeByMapTarget(mapTarget); let _webmap = global_event_default().getMapInfoByMapTarget(mapTarget).webMap; if (mapType === "leaflet") { if (_webmap) { _webmap.mapDraw.enableEdit(layer, isEnable, callbackFun); } } else if (mapType === "cesium") { if (_webmap) { _webmap._drawManager.enableEdit(isEnable); } } } }; module.exports = __webpack_exports__; /******/ })() ;