From f8039fe174aeb033ce27fbad8349df26e822de1a Mon Sep 17 00:00:00 2001 From: 徐旺旺 <11530253@qq.com> Date: 星期四, 11 三月 2021 18:35:16 +0800 Subject: [PATCH] 箭头函数 --- src/views/MapTemplate.vue | 2 +- src/components/helpers/ServiceLayerHelper.js | 31 ++++++++++++++----------------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/components/helpers/ServiceLayerHelper.js b/src/components/helpers/ServiceLayerHelper.js index 26bd028..6a2ff71 100644 --- a/src/components/helpers/ServiceLayerHelper.js +++ b/src/components/helpers/ServiceLayerHelper.js @@ -140,11 +140,10 @@ * @param res */ loadGeojson (res, opt) { - var that = this var icon = opt.icon - const featureGroup = that.L.featureGroup() + const featureGroup = this.L.featureGroup() const featureList = [] - const geojson = that.L.geoJSON(res.features, { + const geojson = this.L.geoJSON(res.features, { style: function (feature) { return { fill: styles.defaultLineStyle.fill, @@ -157,8 +156,8 @@ dashSpeed: styles.defaultLineStyle.dashSpeed } }, - pointToLayer: function (geoJsonPoint, latlng) { - return that.L.canvasMarker(latlng, + pointToLayer: (geoJsonPoint, latlng) => { + return this.L.canvasMarker(latlng, { img: { // url: 'assets/images/map/marker-icon.png', @@ -167,21 +166,19 @@ } }) }, - onEachFeature: function (feature, layer) { - console.log(feature) - console.log(layer) + onEachFeature: (feature, layer) => { featureList.push(layer) - layer.bindPopup(function (layer) { - that.popupComp.setDatas(layer) - that.popupComp.setShow() - return that.popupComp.$el + layer.bindPopup((layer) => { + this.popupComp.setDatas(layer) + this.popupComp.setShow() + return this.popupComp.$el }, { className: 's-map-popup', minWidth: 300, closeButton: false, autoClose: false }) - .bindTooltip(function (layer) { + .bindTooltip((layer) => { const nameId = layer.feature.id let name = '' if (nameId.indexOf('涓夐��') !== -1 || nameId.indexOf('鍥涢��') !== -1 || nameId.indexOf('绐ㄤ簳') !== -1) { @@ -194,7 +191,7 @@ } return name }, { direction: 'bottom', offset: [0, 15], sticky: true }) - .on('mouseover', function (e) { + .on('mouseover', (e) => { const type = e.target.feature.geometry.type if (type === 'LineString' || type === 'MultiLineString') { layer.setStyle({ weight: 8, color: '#00ffff' }) @@ -208,7 +205,7 @@ layer.bringToFront() } - }).on('mouseout', function (e) { + }).on('mouseout', (e) => { const type = e.target.feature.geometry.type if (type === 'LineString' || type === 'MultiLineString') { layer.setStyle({ weight: styles.defaultLineStyle.weight, color: styles.defaultLineStyle.color }) @@ -225,8 +222,8 @@ } }) store.commit('addSewersDatas', geojson) - featureGroup.addTo(that.map) - that.setZIndex(featureGroup) + featureGroup.addTo(this.map) + this.setZIndex(featureGroup) return featureGroup } diff --git a/src/views/MapTemplate.vue b/src/views/MapTemplate.vue index 36d66bf..ce5e3cc 100644 --- a/src/views/MapTemplate.vue +++ b/src/views/MapTemplate.vue @@ -81,7 +81,7 @@ this.basemapHelper.initBasemap(this.config, false) // 绗簩涓弬鏁帮紝琛ㄧず鏄惁鍐呯綉搴曞浘 this.serviceLayerHelper = Sgis.initTileLayersHelper(this.map) // 鍒濆鍖栦笟鍔″簳鍥惧姪鎵� - console.log(this.$refs.popup.$el) + console.log('-------' + this.$refs.popup.$el) this.serviceLayerHelper.initServiceLayers(this.config, this.$refs.popup) this.vectorLayerHelper = Sgis.initVectorLayersHelper(this.map) // 鍒濆鍖栧姩鎬佽绱犲浘灞傚姪鎵� -- Gitblit v1.8.0