当前位置:   article > 正文

高德地图JS 离线部署方案,实现插件离线加载,自定义添加插件如RangingTool、ToolBar、Scale等_高德地图离线js

高德地图离线js

教程原始来源

此教程是基于 “深海的鲸同学 luvi”的 高德地图离线加载解决方案(内网部署)+本地地图瓦片加载 文章改进的,增加了自定义插件部分

责任声明

本教程旨在提供关于如何离线部署高德地图的技术信息和指导,仅供教育和个人学习目的。本教程中使用的高德地图API及其相关技术、图标和标识等均属于高德地图及其关联公司的财产。所有相关技术和标识的使用都应遵循高德地图提供的官方文档和版权声明。本教程或作者不拥有任何高德地图API或相关技术的权益,且本教程未经高德地图官方认可或直接支持。如需商用,请联系高德地图官方。

概要

最近在研究高德地图API相关使用,发现只有WEBJS的离线部署不被支持,所以在网上查询了一些相关教程,但是并不全面。上文提到的教程中包含了基本的离线API部署方案,但Plugin无法使用,于是自己研究了一下,出一个简单的插件集成教程。

1. 准备

请按照 “深海的鲸同学 luvi”的 高德地图离线加载解决方案(内网部署)+本地地图瓦片加载 教程先部署离线js

2. 获取插件源代码

在线获取的插件保存在localStorage,所以在 在线地图的页面查看F12–应用–本地存储空间,找到要用的插件
在这里插入图片描述

3.查看\修改插件源代码

可以将script内的内容复制到 编译器
把所有的 “\” 替换为 “” (空字符串):
在这里插入图片描述
然后格式化一下,查看有没有与在线相关的代码并进行适当修改,这里展示开头和结尾的格式:
开头格式

结尾格式

4.修改源码,复制到AMap3.js结尾

改完代码后可以使用一些工具压缩一下代码,如 https://www.toptal.com/developers/javascript-minifier

随后按照:

_jsload_('AMap.RangingTool', '! function(){ .... }();')
  • 1

的格式修改代码。开头和结尾示例如下:
在这里插入图片描述
在这里插入图片描述

5.测试

随后在页面直接使用插件:

 	measureDistance(){
      this.ruler = new AMap.RangingTool(this.mapObj);
      this.ruler.turnOn();
    }
  • 1
  • 2
  • 3
  • 4

在这里插入图片描述
查看控制台没有发现报错,且功能使用正常。

其它插件

后面测试了ToolBar、Scale,发现均能正常使用。
插件引入到AMap3.js的方法是一样的。

  const toolBar = new AMap.ToolBar({
            position: {
                top: '110px',
                right: '40px'
            }
        })
        const scale = new AMap.Scale();
        this.mapObj.addControl(toolBar);
        this.mapObj.addControl(scale);
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

部分插件代码

下面是Toolbar、scale、rangingtool的代码,可以直接粘贴到AMap3.js结尾:

_jsload_('AMap.ToolBar', '! function toolbar(){"use strict";var o=function(t,n){return(o=Object.setPrototypeOf||({__proto__:[]})instanceof Array&&function(o,t){o.__proto__=t}||function(o,t){for(var n in t)t.hasOwnProperty(n)&&(o[n]=t[n])})(t,n)},t=[2,26],n={position:{bottom:"20px",right:"20px"},offset:[15,15]},e=function(e){function i(o){void 0===o&&(o=n);var t=e.call(this,o)||this;return t._className="toolbar",t._handleZoomEnd=t._handleZoomEnd.bind(t),t._config=AMap.extend(n,o),t.initContainer(),t._initUI(),t}return!function t(n,e){function i(){this.constructor=n}o(n,e),n.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)}(i,e),i.prototype.addTo=function(o){e.prototype.addTo.call(this,o),this._handleZoomEnd(),o.on("zoomend",this._handleZoomEnd)},i.prototype.remove=function(){this.map&&this.map.off("zoomend",this._handleZoomEnd),e.prototype.remove.call(this)},i.prototype.removeFrom=function(o){o&&o.off("zoomend",this._handleZoomEnd),e.prototype.removeFrom.call(this,o)},i.prototype._handleZoomEnd=function(){var o=this.map,t=o.getZooms();o.getZoom()<=t[0]?this._zoomOut.style.color="#ddd":this._zoomOut.style.color="#000",o.getZoom()>=t[1]?this._zoomIn.style.color="#ddd":this._zoomIn.style.color="#000"},i.prototype._initUI=function(){var o=this;this._zoomIn=AMap.DomUtil.create("span",this._container,"amap-ctrl-zoomin"),this._zoomOut=AMap.DomUtil.create("span",this._container,"amap-ctrl-zoomout"),this._zoomIn.innerHTML="+",this._zoomOut.innerHTML="-",this._zoomIn.setAttribute("data-type","add"),this._zoomOut.setAttribute("data-type","sub"),this._container.addEventListener("click",function(n){if(n.target instanceof HTMLElement){var e=n.target.getAttribute("data-type"),i=o.map.getZoom();"add"===e?o.map.setZoom(Math.min(i+1,t[1])):"sub"===e&&o.map.setZoom(Math.max(i-1,2))}})},i}(AMap.Control);AMap.ToolBar=e}();')

_jsload_('AMap.Scale', '! function scale(){"use strict";var e=function(t,i){return(e=Object.setPrototypeOf||({__proto__:[]})instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i])})(t,i)},t={position:"LB",offset:[15,25]},i=function(i){function n(e){void 0===e&&(e=t);var n=i.call(this,e)||this;return n._className="scalecontrol",n._scaleLevel=[[1e7,"10000"],[5e6,"5000"],[2e6,"2000"],[1e6,"1000"],[5e5,"500"],[2e5,"200"],[1e5,"100"],[5e4,"50"],[3e4,"30"],[2e4,"20"],[1e4,"10"],[5e3,"5"],[2e3,"2"],[1e3,"1"],[500,"500"],[200,"200"],[100,"100"],[50,"50"],[25,"25"],[10,"10"],[5,"5"],[2,"2"],[1,"1"],[.5,"50"],[.2,"20"],[.1,"10"],[.05,"5"],[.02,"2"],[.01,"1"],[.01,"1"],[.01,"1"]],n._handleViewChange=n._handleViewChange.bind(n),n._config=AMap.extend(t,e),n.initContainer(),n}return!function t(i,n){function o(){this.constructor=i}e(i,n),i.prototype=null===n?Object.create(n):(o.prototype=n.prototype,new o)}(n,i),n.prototype.addTo=function(e){i.prototype.addTo.call(this,e),this._initUI(),e.on("viewchange",this._handleViewChange)},n.prototype.remove=function(){this.map&&this.map.off("viewchange",this._handleViewChange),this._destroyUI(),i.prototype.remove.call(this)},n.prototype.removeFrom=function(e){e&&e.off("viewchange",this._handleViewChange),this._destroyUI(),i.prototype.removeFrom.call(this,e)},n.prototype._handleViewChange=function(){this._updateUI()},n.prototype._initUI=function(){this._text=AMap.DomUtil.create("div",this._container,"amap-scale-text"),this._line=AMap.DomUtil.create("div",this._container,"amap-scale-line"),this._lineLeft=AMap.DomUtil.create("div",this._container,"amap-scale-edgeleft"),this._lineRight=AMap.DomUtil.create("div",this._container,"amap-scale-edgeright"),this._lineMid=AMap.DomUtil.create("div",this._container,"amap-scale-middle"),this._line.appendChild(this._lineLeft),this._line.appendChild(this._lineMid),this._line.appendChild(this._lineRight),this._updateUI()},n.prototype._destroyUI=function(){for(;this._container.firstChild;)this._container.removeChild(this._container.firstChild)},n.prototype._updateUI=function(){var e=this.map.getView().getStatus(),t=e.optimalZoom,i=e.center,n=e.resolution;this.map.getSize().toArray();for(var o=t-1,a=n*Math.cos(i[1]/180*Math.PI),s=this._scaleLevel[o][0]/a,h=o;h<this._scaleLevel.length&&!((s=this._scaleLevel[o][0]/a)<120);h++)o=Math.min(++o,this._scaleLevel.length-1);var l=this._scaleLevel[o][1];o<=13?l+=" 公里":o<23?l+=" 米":l+=" 厘米",this._text.innerText=l,this._text.style.width=s+8+"px",this._lineMid.style.width=s+"px",this._lineRight.style.left=s+1+"px"},n}(AMap.Control);AMap.Scale=i}(); ')

_jsload_('AMap.RangingTool', '!function () {' +
  '  "use strict";' +
  '  var extendStatics = function (d, b) {' +
  '    extendStatics = Object.setPrototypeOf || {__proto__: []} instanceof Array && function (d, b) {' +
  '      d.__proto__ = b' +
  '    } || function (d, b) {' +
  '      for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]' +
  '    };' +
  '    return extendStatics(d, b)' +
  '  };' +
  '' +
  '  function __extends(d, b) {' +
  '    extendStatics(d, b);' +
  '' +
  '    function __() {' +
  '      this.constructor = d' +
  '    }' +
  '' +
  '    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __)' +
  '  }' +
  '' +
  '  var RangingTool = function (_super) {' +
  '    __extends(RangingTool, _super);' +
  '' +
  '    function RangingTool(map, opts) {' +
  '      var _this = _super.call(this) || this;' +
  '      _this["CLASS_NAME"] = "AMap.RangingTool";' +
  '      _this.STATUS = {OFF: 0, READY: 1, WORKING: 2};' +
  '      if (!map) {' +
  '        throw new Error("创建AMap.RangingTool实例必须传入地图对象作为第一个参数: new AMap.RangingTool(mapObj);")' +
  '      }' +
  '      _this._map = map;' +
  '      _this._container = _this._map.getMapsContainer();' +
  '      opts = opts || {};' +
  '      var imgHost = AMap.getConfig()["protocol"] + "://webapi.amap.com";' +
  '      var nodeImg = imgHost + "/images/pldot.png";' +
  '      var nodeSize = new AMap.Size(12, 12);' +
  '      var nodeOptionsArray = [];' +
  '      var lineOptions = {' +
  '        strokeColor: "#1791fc",' +
  '        strokeOpacity: .8,' +
  '        strokeWeight: 2,' +
  '        bubble: true,' +
  '        draggable: false,' +
  '        innerOverlay: true' +
  '      };' +
  '      _this._keydownEvent = _this._onKeyDown.bind(_this);' +
  '      var labelOffset = new AMap.Pixel(-6, 6);' +
  '      for (var i = 0; i < 3; i += 1) {' +
  '        nodeOptionsArray.push({' +
  '          icon: new AMap.Icon({' +
  '            size: nodeSize,' +
  '            imageOffset: new AMap.Pixel(-12 * i, 0),' +
  '            image: nodeImg' +
  '          }),' +
  '          anchor: "top-left",' +
  '          offset: [-6, -6],' +
  '          cursor: "pointer",' +
  '          bubble: true,' +
  '          draggable: false,' +
  '          zIndex: 120,' +
  '          innerOverlay: true' +
  '        })' +
  '      }' +
  '      _this["startMarkerOptions"] = nodeOptionsArray[0];' +
  '      _this["midMarkerOptions"] = nodeOptionsArray[2];' +
  '      _this["endMarkerOptions"] = nodeOptionsArray[1];' +
  '      _this["lineOptions"] = _this["tmpLineOptions"] = lineOptions;' +
  '      _this["startLabelText"] = "起点</div>";' +
  '      _this["midLabelText"] = "{d}公里</div>";' +
  '      _this["endLabelText"] = "共{d}公里</div>";' +
  '      _this["startLabelOffset"] = _this["midLabelOffset"] = _this["endLabelOffset"] = labelOffset;' +
  '      _this.keyboardEve = false;' +
  '      _this.d = 1e3;' +
  '      if (opts["d"] === 1) {' +
  '        _this.d = 1;' +
  '        _this["midLabelText"] = "{d}米</div>";' +
  '        _this["endLabelText"] = "共{d}米</div>"' +
  '      }' +
  '      _this.dn = "<img class=\'deleteNode\' src=\'" + imgHost + "/images/remove.png\' />";' +
  '      _this.dl = "<img class=\'delimg\' src=\'" + imgHost + "/images/destroy.png\' />";' +
  '      _this.merge(_this, opts);' +
  '      _this._lastRecord = null;' +
  '      _this._status = _this.STATUS.OFF;' +
  '      return _this' +
  '    }' +
  '' +
  '    RangingTool.prototype["turnOn"] = function () {' +
  '      if (this._status === this.STATUS.OFF) {' +
  '        this._off2Ready();' +
  '        this._cacheDoubleClickZoom = this._map["getStatus"]()["doubleClickZoom"];' +
  '        this._map["setStatus"]({doubleClickZoom: false})' +
  '      }' +
  '    };' +
  '    RangingTool.prototype["turnOff"] = function (removeOverlays) {' +
  '      if (this._status === this.STATUS.READY) {' +
  '        this._ready2Off();' +
  '        this._map["setStatus"]({doubleClickZoom: this._cacheDoubleClickZoom})' +
  '      } else if (this._status === this.STATUS.WORKING) {' +
  '        this._onEnd();' +
  '        this._working2Off();' +
  '        this._map["setStatus"]({doubleClickZoom: this._cacheDoubleClickZoom})' +
  '      }' +
  '      if (removeOverlays) {' +
  '        this._removeAllRecords()' +
  '      }' +
  '    };' +
  '    RangingTool.prototype.setOptions = function (opts) {' +
  '      this.merge(this, opts)' +
  '    };' +
  '    RangingTool.prototype.merge = function (obj1, obj2) {' +
  '      for (var i in obj2) {' +
  '        if (obj2.hasOwnProperty(i)) {' +
  '          obj1[i] = obj2[i];' +
  '          if (i === "tmpLineOptions" || i === "lineOptions") {' +
  '            obj1[i]["bubble"] = true' +
  '          }' +
  '        }' +
  '      }' +
  '    };' +
  '    RangingTool.prototype.updateOptions = function (marker, options) {' +
  '      var setting = {' +
  '        position: [undefined, "setPosition"],' +
  '        draggable: [false, "setDraggable"],' +
  '        content: [undefined, "setContent"],' +
  '        icon: [undefined, "setIcon"],' +
  '        offset: [undefined, "setOffset"],' +
  '        zIndex: [100, "setzIndex"]' +
  '      };' +
  '      for (var key in setting) {' +
  '        if (setting.hasOwnProperty(key)) {' +
  '          var value = options[key] || setting[key][0];' +
  '          if (value !== undefined) {' +
  '            marker[setting[key][1]](value)' +
  '          }' +
  '        }' +
  '      }' +
  '    };' +
  '    RangingTool.prototype._off2Ready = function () {' +
  '      this._map.on("click", this._onStart, this, true);' +
  '      this._status = this.STATUS.READY' +
  '    };' +
  '    RangingTool.prototype._ready2Off = function () {' +
  '      this._map.off("click", this._onStart, this);' +
  '      this._status = this.STATUS.OFF' +
  '    };' +
  '    RangingTool.prototype._ready2Working = function () {' +
  '      this._map.on("click", this._onAddNode, this);' +
  '      this._map.on("mousemove", this._onMouseMove, this);' +
  '      this._map.on("rightclick", this._onEnd, this, true);' +
  '      this._map.on("dblclick", this._onEnd, this, true);' +
  '      this._container.addEventListener("keydown", this._keydownEvent);' +
  '      this._status = this.STATUS.WORKING' +
  '    };' +
  '    RangingTool.prototype._working2Off = function () {' +
  '      this._map.off("click", this._onStart, this);' +
  '      this._map.off("click", this._onAddNode, this);' +
  '      this._map.off("mousemove", this._onMouseMove, this);' +
  '      this._map.off("rightclick", this._onEnd, this);' +
  '      this._map.off("dblclick", this._onEnd, this, true);' +
  '      this._container.removeEventListener("keydown", this._keydownEvent);' +
  '      this._status = this.STATUS.OFF' +
  '    };' +
  '    RangingTool.prototype._working2Ready = function () {' +
  '      this._working2Off();' +
  '      this._off2Ready();' +
  '      this._status = this.STATUS.READY' +
  '    };' +
  '    RangingTool.prototype._onStart = function (e) {' +
  '      this._map["setStatus"]({allBubble: true});' +
  '      var record = {prev: this._lastRecord};' +
  '      var node = {_position: e["lnglat"], _marker: null};' +
  '      record._lastNode = node;' +
  '      if (this._lastRecord) {' +
  '        this._lastRecord.next = record' +
  '      }' +
  '      this.originDraggable = this._map["getStatus"]()["dragEnable"];' +
  '      this._map["setStatus"]({dragEnable: false});' +
  '      this._lastRecord = record;' +
  '      this._renderMarker(node, this["startMarkerOptions"]);' +
  '      this._renderLabel(node, this["startLabelText"], this["startLabelOffset"], this._getRemoveNodeFunction(node, record));' +
  '      this._ready2Working();' +
  '      var addnodeEvent = {position: e["lnglat"], marker: node._marker};' +
  '      this.emit("addnode", addnodeEvent)' +
  '    };' +
  '    RangingTool.prototype._onAddNode = function (e) {' +
  '      var record = this._lastRecord;' +
  '      var prevNode = record._lastNode;' +
  '      var newNode = {_position: e["lnglat"], prev: prevNode, _marker: null};' +
  '      if (prevNode && prevNode._position.equals(e["lnglat"])) {' +
  '        this._onEnd();' +
  '        return' +
  '      }' +
  '      prevNode.next = newNode;' +
  '      record._lastNode = newNode;' +
  '      this._renderMarker(newNode, this["midMarkerOptions"]);' +
  '      this._renderLabel(newNode, this["midLabelText"], this["midLabelOffset"], this._getRemoveNodeFunction(newNode, record));' +
  '      this._renderLine(record);' +
  '      if (this._tmpLine) {' +
  '        this._tmpLine["setPath"]([e["lnglat"], e["lnglat"]])' +
  '      }' +
  '      var addnodeEvent = {position: e["lnglat"], marker: newNode._marker};' +
  '      this.emit("addnode", addnodeEvent)' +
  '    };' +
  '    RangingTool.prototype._onMouseMove = function (e) {' +
  '      var record = this._lastRecord;' +
  '      var position = record._lastNode._position;' +
  '      if (!this._tmpLine) {' +
  '        this._tmpLine = new AMap.Polyline(this["tmpLineOptions"]);' +
  '        this._tmpLine.name = "tmpLine";' +
  '        this._map.add(this._tmpLine)' +
  '      }' +
  '      this._tmpLine.isOfficial = true;' +
  '      this._tmpLine["setPath"]([position, e["lnglat"]]);' +
  '      var distance = this._tmpLine["getLength"]();' +
  '      if (record._line) {' +
  '        distance += record._line["getLength"]()' +
  '      }' +
  '      var moveEvent = {position: e["lnglat"], distance: distance, target: this};' +
  '      this.emit("move", moveEvent)' +
  '    };' +
  '    RangingTool.prototype._onKeyDown = function (e) {' +
  '      if (e.keyCode === 27) {' +
  '        this._onEnd()' +
  '      }' +
  '    };' +
  '    RangingTool.prototype._onEnd = function () {' +
  '      var record = this._lastRecord;' +
  '      var node = record && record._lastNode;' +
  '      this._map["setStatus"]({allBubble: false, dragEnable: this.originDraggable});' +
  '      this["endMarkerOptions"]["bubble"] = false;' +
  '      if (node && node.prev) {' +
  '        this._renderMarker(node, this["endMarkerOptions"]);' +
  '        this._renderLabel(node, this["endLabelText"], this["endLabelOffset"], this._getRemoveNodeFunction(node, record), this._getRemoveRecordFunction(record))' +
  '      } else if (record) {' +
  '        this._removeRecord(record)' +
  '      }' +
  '      this._working2Ready();' +
  '      if (this._tmpLine) {' +
  '        this._map.remove(this._tmpLine);' +
  '        this._tmpLine = null' +
  '      }' +
  '      if (record && record._line) {' +
  '        record._line["setOptions"]({bubble: false});' +
  '        var endEvent = {' +
  '          polyline: record._line,' +
  '          points: record._line["getPath"](),' +
  '          distance: record._line["getLength"]()' +
  '        };' +
  '        this.emit("end", endEvent)' +
  '      } else {' +
  '        this.emit("cancel", {obj: false})' +
  '      }' +
  '    };' +
  '    RangingTool.prototype._renderLine = function (record) {' +
  '      var path = [];' +
  '      var cur = record._lastNode;' +
  '      while (cur) {' +
  '        path.unshift(cur._position);' +
  '        cur = cur.prev' +
  '      }' +
  '      if (path.length < 2) {' +
  '        this._removeRecord(record)' +
  '      } else {' +
  '        if (record._line) {' +
  '          record._line["setPath"](path)' +
  '        } else {' +
  '          record._line = new AMap.Polyline(this["lineOptions"]);' +
  '          record._line.isOfficial = true;' +
  '          record._line.name = "recrdLine";' +
  '          record._line["setPath"](path);' +
  '          this._map.add(record._line)' +
  '        }' +
  '      }' +
  '    };' +
  '    RangingTool.prototype._renderMarker = function (node, options) {' +
  '      var isNew = !node._marker;' +
  '      var map = this._map;' +
  '      this.merge(options, {position: node._position, bubble: true, innerOverlay: true});' +
  '      if (!isNew) {' +
  '        this.updateOptions(node._marker, options)' +
  '      } else {' +
  '        node._marker = new AMap.Marker(options);' +
  '        node._marker.name = "marker";' +
  '        this._map.add(node._marker);' +
  '        node._marker.isOfficial = true' +
  '      }' +
  '    };' +
  '    RangingTool.prototype._renderLabel = function (node, text, offset, dnCallback, dlCallback) {' +
  '      var content = document.createElement("div");' +
  '      var d = 0;' +
  '      if (node._label) {' +
  '        this._map.remove(node._label);' +
  '        delete node._label' +
  '      }' +
  '      if (text.match("{d}")) {' +
  '        var cur = node.prev;' +
  '        while (cur) {' +
  '          var dis = AMap.GeometryUtil.distance(cur._position, cur.next._position);' +
  '          d += dis;' +
  '          cur = cur.prev' +
  '        }' +
  '        d = (d / this.d).toFixed(this.d === 1 ? 1 : 2);' +
  '        text = text.replace("{d}", d)' +
  '      }' +
  '      content.className = "amap-ranging-label";' +
  '      var span = document.createElement("span");' +
  '      span.innerHTML = text;' +
  '      content.appendChild(span);' +
  '      if (dnCallback) {' +
  '        content.appendChild(this._getSmallButton(this.dn, dnCallback))' +
  '      }' +
  '      if (dlCallback) {' +
  '        content.appendChild(this._getSmallButton(this.dl, dlCallback))' +
  '      }' +
  '      node._label = new AMap.Marker({' +
  '        content: content,' +
  '        position: node._position,' +
  '        offset: offset,' +
  '        cursor: "pointer",' +
  '        zIndex: 110,' +
  '        bubble: false' +
  '      });' +
  '      node._label.isOfficial = true;' +
  '      node._marker.name = "label";' +
  '      this._map.add(node._label)' +
  '    };' +
  '    RangingTool.prototype._updateLabels = function (record) {' +
  '      var cur = record._lastNode;' +
  '      if (cur) {' +
  '        this._renderLabel(cur, this["endLabelText"], this["endLabelOffset"], this._getRemoveNodeFunction(cur, record), this._getRemoveRecordFunction(record));' +
  '        while (cur.prev) {' +
  '          cur = cur.prev;' +
  '          this._renderLabel(cur, this["midLabelText"], this["midLabelOffset"], this._getRemoveNodeFunction(cur, record))' +
  '        }' +
  '        this._renderLabel(cur, this["startLabelText"], this["startLabelOffset"], this._getRemoveNodeFunction(cur, record))' +
  '      }' +
  '    };' +
  '    RangingTool.prototype._getSmallButton = function (html, callback) {' +
  '      var button = document.createElement("span");' +
  '      button.innerHTML = html;' +
  '      button.addEventListener("click", function (e) {' +
  '        callback()' +
  '      });' +
  '      button.addEventListener("mousedown", function (e) {' +
  '        e.stopPropagation()' +
  '      });' +
  '      return button' +
  '    };' +
  '    RangingTool.prototype._getRemoveNodeFunction = function (node, record) {' +
  '      var _this = this;' +
  '      var removeNodeFun = function () {' +
  '        if (_this._status !== _this.STATUS.WORKING) {' +
  '          _this._removeNode(node, record)' +
  '        }' +
  '      };' +
  '      return removeNodeFun' +
  '    };' +
  '    RangingTool.prototype._getRemoveRecordFunction = function (record) {' +
  '      var self = this;' +
  '      return function (e) {' +
  '        if (self._status !== self.STATUS.WORKING) {' +
  '          self.emit("delete", {target: self});' +
  '          self._removeRecord(record)' +
  '        }' +
  '      }' +
  '    };' +
  '    RangingTool.prototype._removeNode = function (node, record) {' +
  '      if (node.prev) {' +
  '        node.prev.next = node.next' +
  '      } else if (node.next) {' +
  '        this._renderMarker(node.next, this["startMarkerOptions"])' +
  '      }' +
  '      if (node.next) {' +
  '        node.next.prev = node.prev' +
  '      } else if (node.prev) {' +
  '        this._renderMarker(node.prev, this["endMarkerOptions"]);' +
  '        record._lastNode = node.prev' +
  '      }' +
  '      node.prev = node.next = null;' +
  '      if (node._marker) {' +
  '        this._map.remove(node._marker);' +
  '        node._marker = null' +
  '      }' +
  '      if (node._label) {' +
  '        this._map.remove(node._label);' +
  '        node._label = null' +
  '      }' +
  '      this._renderLine(record);' +
  '      this._updateLabels(record);' +
  '      var removenodeEvent = {' +
  '        polyline: record._line,' +
  '        points: record._line ? record._line["getPath"]() : [],' +
  '        distance: record._line ? record._line["getLength"]() : null,' +
  '        target: this' +
  '      };' +
  '      this.emit("removenode", removenodeEvent)' +
  '    };' +
  '    RangingTool.prototype._removeRecord = function (record) {' +
  '      var node = record._lastNode;' +
  '      if (record._line) {' +
  '        this._map.remove(record._line);' +
  '        record._line = null' +
  '      }' +
  '      while (node) {' +
  '        if (node._marker) {' +
  '          this._map.remove(node._marker);' +
  '          node._marker = null' +
  '        }' +
  '        if (node._label) {' +
  '          this._map.remove(node._label);' +
  '          node._label = null' +
  '        }' +
  '        node = node.prev' +
  '      }' +
  '      if (record.prev) {' +
  '        record.prev.next = record.next' +
  '      }' +
  '      if (record.next) {' +
  '        record.next.prev = record.prev' +
  '      } else {' +
  '        this._lastRecord = record.prev' +
  '      }' +
  '      record._lastNode = record.prev = record.next = null' +
  '    };' +
  '    RangingTool.prototype._removeAllRecords = function () {' +
  '      while (this._lastRecord) {' +
  '        this._removeRecord(this._lastRecord)' +
  '      }' +
  '    };' +
  '    return RangingTool' +
  '  }(AMap.Event);' +
  '  AMap["RangingTool"] = RangingTool' +
  '}();' )
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209
  • 210
  • 211
  • 212
  • 213
  • 214
  • 215
  • 216
  • 217
  • 218
  • 219
  • 220
  • 221
  • 222
  • 223
  • 224
  • 225
  • 226
  • 227
  • 228
  • 229
  • 230
  • 231
  • 232
  • 233
  • 234
  • 235
  • 236
  • 237
  • 238
  • 239
  • 240
  • 241
  • 242
  • 243
  • 244
  • 245
  • 246
  • 247
  • 248
  • 249
  • 250
  • 251
  • 252
  • 253
  • 254
  • 255
  • 256
  • 257
  • 258
  • 259
  • 260
  • 261
  • 262
  • 263
  • 264
  • 265
  • 266
  • 267
  • 268
  • 269
  • 270
  • 271
  • 272
  • 273
  • 274
  • 275
  • 276
  • 277
  • 278
  • 279
  • 280
  • 281
  • 282
  • 283
  • 284
  • 285
  • 286
  • 287
  • 288
  • 289
  • 290
  • 291
  • 292
  • 293
  • 294
  • 295
  • 296
  • 297
  • 298
  • 299
  • 300
  • 301
  • 302
  • 303
  • 304
  • 305
  • 306
  • 307
  • 308
  • 309
  • 310
  • 311
  • 312
  • 313
  • 314
  • 315
  • 316
  • 317
  • 318
  • 319
  • 320
  • 321
  • 322
  • 323
  • 324
  • 325
  • 326
  • 327
  • 328
  • 329
  • 330
  • 331
  • 332
  • 333
  • 334
  • 335
  • 336
  • 337
  • 338
  • 339
  • 340
  • 341
  • 342
  • 343
  • 344
  • 345
  • 346
  • 347
  • 348
  • 349
  • 350
  • 351
  • 352
  • 353
  • 354
  • 355
  • 356
  • 357
  • 358
  • 359
  • 360
  • 361
  • 362
  • 363
  • 364
  • 365
  • 366
  • 367
  • 368
  • 369
  • 370
  • 371
  • 372
  • 373
  • 374
  • 375
  • 376
  • 377
  • 378
  • 379
  • 380
  • 381
  • 382
  • 383
  • 384
  • 385
  • 386
  • 387
  • 388
  • 389
  • 390
  • 391
  • 392
  • 393
  • 394
  • 395
  • 396
  • 397
  • 398
  • 399
  • 400
  • 401
  • 402
  • 403
  • 404
  • 405
  • 406
  • 407
  • 408
  • 409
  • 410
  • 411
  • 412
  • 413
  • 414
  • 415
  • 416
  • 417
  • 418
  • 419
  • 420
  • 421
  • 422
  • 423
  • 424
  • 425
  • 426
  • 427
  • 428
  • 429
  • 430
  • 431
  • 432
  • 433
  • 434
  • 435
  • 436
  • 437
  • 438
本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/824537
推荐阅读
  

闽ICP备14008679号