From ad9157065051ff705bb20de57c2f24e3b4d9d41a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=81=A5?= Date: Thu, 16 Sep 2021 11:49:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=B0=E5=9B=BE=E6=B8=B2=E6=9F=93=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../detail-announcement.js | 39 ++-- pages/look-detail/look-detail.js | 112 +--------- pages/look/look.js | 200 ++---------------- pages/lookStay-detail/lookStay-detail.js | 130 +++--------- utils/gitUtil.js | 15 ++ 5 files changed, 93 insertions(+), 403 deletions(-) diff --git a/components/detail-announcement/detail-announcement.js b/components/detail-announcement/detail-announcement.js index 854f6c9..ccd9bbd 100644 --- a/components/detail-announcement/detail-announcement.js +++ b/components/detail-announcement/detail-announcement.js @@ -1,5 +1,4 @@ const $api = require('../../utils/api').API; -const WKT = require('../../utils/terraformer-wkt-parser.min'); Component({ options: { addGlobalClass: true @@ -78,29 +77,31 @@ Component({ if (this.properties.info.transactionStatus == 'toBeListed') { $api.AJAX('GET', 'applets/landtolistlonlat/list/' + proposedseriaId, true).then(res => { if (res && res.data && res.data.length > 0) { - let point = WKT.parse(res.data[0].centerPoint).coordinates - let latitude = point[0] - let longitude = point[1] - wx.openLocation({ - latitude: Number(longitude), - longitude: Number(latitude), - name: res.data[0].name, - scale: 10 - }) + if (res.data[0].centerPoint) { + let centerPoint = res.data[0].centerPoint; + let longitude = centerPoint[0] + let latitude = centerPoint[1] + wx.openLocation({ + latitude: Number(latitude), + longitude: Number(longitude), + scale: 10 + }) + } } }) } else { $api.AJAX('GET', 'applets/landlistedlonlat/list/' + landListedId, true).then(res => { if (res && res.data && res.data.length > 0) { - let point = WKT.parse(res.data[0].centerPoint).coordinates - let latitude = point[0] - let longitude = point[1] - wx.openLocation({ - latitude: Number(longitude), - longitude: Number(latitude), - name: res.data[0].name, - scale: 10 - }) + if (res.data[0].centerPoint) { + let centerPoint = res.data[0].centerPoint; + let longitude = centerPoint[0] + let latitude = centerPoint[1] + wx.openLocation({ + latitude: Number(latitude), + longitude: Number(longitude), + scale: 10 + }) + } } }) } diff --git a/pages/look-detail/look-detail.js b/pages/look-detail/look-detail.js index 27ed9c4..4e35867 100644 --- a/pages/look-detail/look-detail.js +++ b/pages/look-detail/look-detail.js @@ -1,7 +1,6 @@ // pages/look-detail/look-detail.js const $api = require('../../utils/api').API; -const WKT = require('../../utils/terraformer-wkt-parser.min'); -const util = require('../../utils/util') +const gisUtil = require('../../utils/gitUtil') Page({ /** @@ -50,18 +49,6 @@ Page({ isDone: false, mid: '', }, - //定位当前 - // gotoLocation(id) { - // $api.AJAX('GET', 'applets/landlistedlonlat/list/' + id, true).then(res => { - // var latitude = res.data[0].landLonLat.split(';')[0].split(',')[0] - // var longitude = res.data[0].landLonLat.split(';')[0].split(',')[1] - // this.setData({ - // latitude: longitude, - // longitude: latitude, - // }) - // }) - - // }, setMark(e) { let { markShow @@ -108,24 +95,17 @@ Page({ }) }, getData(id) { - // ===正常拿到数据后做以下操作======== - - let centerPoint;//经纬度 - let geom;//集合 - - $api.AJAX('GET', 'applets/landlistedlonlat/list/' + id, { landListedId: id }, true).then(res => { if (res&&res.data&&res.data.length > 0) { - this.setWKT1(res, 2) - if(res.data[0].centerPoint){ - centerPoint = res.data[0].centerPoint; - let point = WKT.parse(centerPoint); + if (res.data[0].centerPoint) { + let centerPoint = res.data[0].centerPoint; this.setData({ - latitude: point.coordinates[1], - longitude: point.coordinates[0], + longitude: centerPoint[0], + latitude: centerPoint[1], }) + gisUtil.setWKT(this, res, 2) } } }) @@ -190,83 +170,6 @@ Page({ }) }, - - - //复制了一份,因为参数问题 - setWKT1(data, id) { - let { - polygons - } = this.data; - let newPolygons = data.data.filter(item=>{ - return item.geoms || item.geom; - }).map(item => { - let geomPoints = WKT.parse(item.geoms || item.geom); - let points = []; - geomPoints.coordinates[0].forEach(ele => { - if (typeof (ele[0]) === 'number') { - points.push({ - longitude: ele[0], - latitude: ele[1] - }) - } else { - points = ele.map(once => { - let lonlat = { - longitude: once[0], - latitude: once[1] - } - return lonlat - }) - } - }) - let strokeColor; - let fillColor; - if(item.lineColor){ - strokeColor = '' + item.lineColor + util.ten2XO(item.lineOpaqueness); - } - let strokeWidth = item.lineWidth ? Number(item.lineWidth) : 2; - if(item.fillColor){ - fillColor = '' + item.fillColor + util.ten2XO(item.fillOpaqueness); - } - let polygon = { - points, - strokeColor, - strokeWidth, - fillColor, - zIndex: 1, - id - } - return polygon - }); - // polygons = polygons.concat(newPolygons); - this.setData({ - polygons: polygons.concat(newPolygons) - }) - }, - wkt2polygon(geom) { - let geomPoints = WKT.parse(geom); - let points = []; - geomPoints.coordinates[0].forEach(ele => { - if (typeof (ele[0]) === 'number') { - points.push({ - longitude: ele[0], - latitude: ele[1] - }) - } else { - points = ele.map(once => { - let lonlat = { - longitude: once[0], - latitude: once[1] - } - return lonlat - }) - } - }) - let polygon = { - points, - zIndex: 1, - } - return polygon; - }, goCalculate() { if (this.data.active === 4) { let basis = this.selectComponent('#basis'); @@ -310,17 +213,14 @@ Page({ * 生命周期函数--监听页面加载 */ onLoad: function (options) { - console.log(options); let active = options.active; this.setData({ landListedId: options.id, mid: options.mid }) - // this.gotoLocation(this.data.landListedId); this.getData(options.id) if (active) { active = Number(active); - console.log(active) if (active > 3) { this.setData({ state: false, diff --git a/pages/look/look.js b/pages/look/look.js index 6d4827c..246499b 100644 --- a/pages/look/look.js +++ b/pages/look/look.js @@ -2,9 +2,7 @@ const $api = require('../../utils/gisApi').API; const $apiT = require('../../utils/api').API; const QQMapWX = require('../../utils/qqmap-wx-jssdk.min.js'); -const WKT = require('../../utils/terraformer-wkt-parser.min'); const gisUtil = require('../../utils/gitUtil') -const util = require('../../utils/util') let qqmapsdk; const global = {}; @@ -182,12 +180,11 @@ Page({ if (res && res.data && res.data.length > 0) { if (res.data[0].centerPoint) { let centerPoint = res.data[0].centerPoint; - let point = WKT.parse(centerPoint); this.setData({ - latitude: point.coordinates[1], - longitude: point.coordinates[0], + latitude: centerPoint[0], + longitude: centerPoint[1], }) - this.setWKT1(res, 2) + gisUtil.setWKT(this, res, 2) this.addFeaturesToList(res, 2); } } @@ -231,11 +228,11 @@ Page({ }); global.selectFeature = feature; //tid 代表地块类型,1:已出让,2:挂牌中;3:拟挂牌。 - let tid = feature.tid; //tid:1,2,3 + let tid = feature.id; //tid:1,2,3 //属性property 包含 地块id字段,按需使用。 let property = feature.properties; if (tid == 1 || tid == 2) { - $apiT.AJAX('GET', 'applets/landlisted/' + (property.land_listed_id || property.landListedId), true).then(res => { + $apiT.AJAX('GET', 'applets/landlisted/' + (property.landId), true).then(res => { this.setData({ type: 'landlisted', titleLand: res.data.landCode, @@ -247,7 +244,7 @@ Page({ }); }) } else { - $apiT.AJAX('GET', 'applets/landtolist/' + (property.proposedseria_id || property.proposedseriaId), true).then(res => { + $apiT.AJAX('GET', 'applets/landtolist/' + (property.landId), true).then(res => { this.setData({ type: 'landtolist', titleLand: res.data.landCode, @@ -619,30 +616,6 @@ Page({ }) } }, - // showCenterLocation(centerPoint) { - // let id = -1; - // let { - // latitude, - // longitude, - // } = centerPoint; - // this.clearPoint(id); - // let { - // markers - // } = this.data - // let mark = { - // // iconPath: "../../assets/images/add.png", - // aid: id, - // id: id, - // latitude, - // longitude, - // width: 16, - // height: 24, - // } - // markers.push(mark) - // this.setData({ - // markers: markers - // }) - // }, //定位当前 scaleBack() { let that = this; @@ -659,10 +632,6 @@ Page({ longitude, }, }) - // that.showCenterLocation({ - // latitude, - // longitude - // }) } }) }, @@ -726,7 +695,7 @@ Page({ start: `${start}-01-01`, end: `${end}-12-31`, }).then(data => { - that.setWKT(data, id); + gisUtil.setWKT(that, data, id) that.addFeaturesToList(data, id); }) }, @@ -738,7 +707,7 @@ Page({ lon: res.longitude, lat: res.latitude }).then(data => { - that.setWKT(data, id); + gisUtil.setWKT(that, data, id) that.addFeaturesToList(data, id); }) }, @@ -750,33 +719,22 @@ Page({ lon: res.longitude, lat: res.latitude }).then(data => { - that.setWKT(data, id); + gisUtil.setWKT(that, data, id) that.addFeaturesToList(data, id); }) }, addFeaturesToList(data, tid) { let key = 'key' + tid; - let features = data.data.map(item => { - let geomPoints = WKT.parse(item.geoms || item.geom).coordinates; - let properties = item; - properties.tid = tid; //类型 - let polygon = { - key, - tid, - properties, - type: "Feature", - geometry: { - type: "Polygon", - coordinates: geomPoints - } + if (data && data.data && data.data.length > 0) { + let features = data.data.map(item => { + return item.feature; + }); + if (global.features[key] && global.features[key].length > 0) { + global.features[key] = global.features[key].concat(features) + } else { + global.features[key] = features; } - return polygon; - }); - if (global.features[key] && global.features[key].length > 0) { - global.features[key] = global.features[key].concat(features) - } else { - global.features[key] = features; } }, removeFeaturesToList(tid) { @@ -802,7 +760,7 @@ Page({ } for (let i = 0; i < features.length; i++) { let feature = features[i]; - let hitTest = gisUtil.isPointInPolygon(y, x, feature.geometry.coordinates[0]); + let hitTest = gisUtil.isPointInPolygon(y, x, feature.coordinates); if (hitTest) { selectList.push(feature); if (selectList.length >= maxCount) { @@ -812,12 +770,6 @@ Page({ } return selectList }, - - // MORE地块 - getMoreInfo(res, id) { - - }, - // 配套 getComplete(res, id) { const that = this; @@ -829,7 +781,6 @@ Page({ that.setPoint(data, id, iconPath); }) }, - // 环线数据 getLoop(res, id) { const that = this; @@ -837,7 +788,7 @@ Page({ lon: res.longitude, lat: res.latitude }).then(data => { - that.setWKT(data, id); + gisUtil.setWKT(that, data, id) }) }, @@ -848,7 +799,7 @@ Page({ lon: res.longitude, lat: res.latitude }).then(data => { - that.setWKT(data, id); + gisUtil.setWKT(that, data, id) }) }, @@ -860,7 +811,7 @@ Page({ lat: res.latitude, type }).then(data => { - that.setWKT(data, id); + gisUtil.setWKT(that, data, id) }) }, bindupdated(e) { @@ -869,112 +820,6 @@ Page({ console.log("渲染耗时====》" + time); } }, - // 地块数据解析 - setWKT(data, id) { - let { - polygons - } = this.data; - let newPolygons = data.data.filter(item => { - return item.geoms || item.geom; - }).map(item => { - let geomPoints = WKT.parse(item.geoms || item.geom); - let points = []; - geomPoints.coordinates[0].forEach(ele => { - if (typeof (ele[0]) === 'number') { - points.push({ - longitude: ele[0], - latitude: ele[1] - }) - } else { - points = ele.map(once => { - let lonlat = { - longitude: once[0], - latitude: once[1] - } - return lonlat - }) - } - }) - let strokeColor; - let fillColor; - if (item.line_color) { - strokeColor = '' + item.line_color + util.ten2XO(item.line_opaqueness); - } - let strokeWidth = item.line_width ? Number(item.line_width) : 2; - if (item.fill_color) { - fillColor = '' + item.fill_color + util.ten2XO(item.fill_opaqueness); - } - let polygon = { - points, - strokeColor, - strokeWidth, - fillColor, - zIndex: 1, - id - } - return polygon - }); - let length = newPolygons.length>0&&newPolygons.map(item => { - return item.points.length - }).reduce((a, b) => { - return a + b; - }) - console.log(length); - this.setData({ - polygons: polygons.concat(newPolygons) - }) - start = new Date().getTime(); - }, - //复制了一份,因为参数问题 - setWKT1(data, id) { - let { - polygons - } = this.data; - let newPolygons = data.data.filter(item => { - return item.geoms || item.geom; - }).map(item => { - let geomPoints = WKT.parse(item.geoms || item.geom); - let points = []; - geomPoints.coordinates[0].forEach(ele => { - if (typeof (ele[0]) === 'number') { - points.push({ - longitude: ele[0], - latitude: ele[1] - }) - } else { - points = ele.map(once => { - let lonlat = { - longitude: once[0], - latitude: once[1] - } - return lonlat - }) - } - }) - let strokeColor; - let fillColor; - if (item.lineColor) { - strokeColor = '' + item.lineColor + util.ten2XO(item.lineOpaqueness); - } - let strokeWidth = item.lineWidth ? Number(item.lineWidth) : 2; - if (item.fillColor) { - fillColor = '' + item.fillColor + util.ten2XO(item.fillOpaqueness); - } - let polygon = { - points, - strokeColor, - strokeWidth, - fillColor, - zIndex: 1, - id - } - return polygon - }); - this.setData({ - polygons: polygons.concat(newPolygons) - }) - }, - bindAddressChange(e) { let city = this.data.cityList[e.detail.value] wx.setStorageSync('city', city) @@ -1034,7 +879,6 @@ Page({ start: arryList[sIdx].value, end: arryList[eIdx].value, }) - // this.scaleBack(); }, /** * 生命周期函数--监听页面显示 @@ -1060,7 +904,7 @@ Page({ path: 'pages/look/look', // 路径,传递参数到指定页面。 } }, - onShareTimeline(){ + onShareTimeline() { return { title: '艾儿数据', path: 'pages/look/look', // 路径,传递参数到指定页面。 diff --git a/pages/lookStay-detail/lookStay-detail.js b/pages/lookStay-detail/lookStay-detail.js index e6a0192..0b633b5 100644 --- a/pages/lookStay-detail/lookStay-detail.js +++ b/pages/lookStay-detail/lookStay-detail.js @@ -1,7 +1,6 @@ // pages/look-detail/look-detail.js const $api = require('../../utils/api').API; -const WKT = require('../../utils/terraformer-wkt-parser.min'); -const util = require('../../utils/util') +const gisUtil = require('../../utils/gitUtil') Page({ /** @@ -14,8 +13,7 @@ Page({ tabList: [{ id: 1, name: '拟供地块' - } - ], + }], sedTabList: [{ id: 4, name: '基础测算' @@ -23,7 +21,7 @@ Page({ id: 5, name: '高级测算' }], - active: 1,//当前选择项 + active: 1, //当前选择项 markShow: false, annoutInfo: {}, clinchInfo: {}, @@ -39,20 +37,6 @@ Page({ orgiData: {}, isDone: false, }, - //定位当前 - gotoLocation(id) { - $api.AJAX('GET', 'applets/landtolistlonlat/list/' + id, true).then(res => { - if (res && res.data && res.data.length > 0) { - let point = WKT.parse(res.data[0].centerPoint).coordinates - let latitude = point[0] - let longitude = point[1] - this.setData({ - latitude: longitude, - longitude: latitude, - }) - } - }) - }, setMark(e) { let { markShow @@ -99,22 +83,22 @@ Page({ }) }, getData() { - $api.AJAX('GET', 'applets/landtolistlonlat/list/' + this.data.landListedId, true).then(res => { - if (res&&res.data&&res.data.length > 0) { - this.setWKT1(res, 3); - if(res.data[0].centerPoint){ + if (res && res.data && res.data.length > 0) { + if (res.data[0].centerPoint) { let centerPoint = res.data[0].centerPoint; - let point = WKT.parse(centerPoint); this.setData({ - latitude: point.coordinates[1], - longitude: point.coordinates[0], + longitude: centerPoint[0], + latitude: centerPoint[1], }) + gisUtil.setWKT(this, res, 3) } } }) - $api.AJAX('GET', 'applets/landtolist/' + this.data.landListedId, { id: this.data.landListedId }, true).then(res => { + $api.AJAX('GET', 'applets/landtolist/' + this.data.landListedId, { + id: this.data.landListedId + }, true).then(res => { for (let key in res.data) { if (!res.data[key]) { res.data[key] = '' @@ -122,21 +106,19 @@ Page({ } if (res.data.transactionStatus == 'toBeListed') { this.setData({ - tabList: [ - { - id: 1, - name: '拟供地块' - } - ] + tabList: [{ + id: 1, + name: '拟供地块' + }] }) } - if(res.data.totalConsArea&&res.data.totalConsArea!=''&&res.data.totalConsArea!=0){ - res.data.bizSpaceRatio=((res.data.bizSpace/res.data.totalConsArea)*100).toFixed(2); - res.data.commerceSpaceRatio=((res.data.commerceSpace/res.data.totalConsArea)*100).toFixed(2); - }else{ - res.data.bizSpaceRatio=0; - res.data.commerceSpaceRatio=0; + if (res.data.totalConsArea && res.data.totalConsArea != '' && res.data.totalConsArea != 0) { + res.data.bizSpaceRatio = ((res.data.bizSpace / res.data.totalConsArea) * 100).toFixed(2); + res.data.commerceSpaceRatio = ((res.data.commerceSpace / res.data.totalConsArea) * 100).toFixed(2); + } else { + res.data.bizSpaceRatio = 0; + res.data.commerceSpaceRatio = 0; } let totalConsArea = res.data.totalConsArea; @@ -147,16 +129,16 @@ Page({ let plan = 0; let planRatio = 0; let unplan = 0; - - for(let i in res.data){ - if(res.data[i].constructionType=='1'){ - plan+=res.data[i].constructionArea - }else if(res.data[i].constructionType=='2'){ - unplan+=res.data[i].constructionArea + + for (let i in res.data) { + if (res.data[i].constructionType == '1') { + plan += res.data[i].constructionArea + } else if (res.data[i].constructionType == '2') { + unplan += res.data[i].constructionArea } } - if (totalConsArea&&totalConsArea!=''&&totalConsArea!=0){ - planRatio = (plan/totalConsArea*100).toFixed(2); + if (totalConsArea && totalConsArea != '' && totalConsArea != 0) { + planRatio = (plan / totalConsArea * 100).toFixed(2); } this.setData({ @@ -167,58 +149,6 @@ Page({ }) }) }, - - //复制了一份,因为参数问题 - setWKT1(data, id) { - let { - polygons - } = this.data; - let newPolygons = data.data.filter(item=>{ - return item.geoms || item.geom; - }).map(item => { - let geomPoints = WKT.parse(item.geoms || item.geom); - console.log(geomPoints); - let points = []; - geomPoints.coordinates[0].forEach(ele => { - if (typeof (ele[0]) === 'number') { - points.push({ - longitude: ele[0], - latitude: ele[1] - }) - } else { - points = ele.map(once => { - let lonlat = { - longitude: once[0], - latitude: once[1] - } - return lonlat - }) - } - }) - let strokeColor; - let fillColor; - if(item.lineColor){ - strokeColor = '' + item.lineColor + util.ten2XO(item.lineOpaqueness); - } - let strokeWidth = item.lineWidth ? Number(item.lineWidth) : 2; - if(item.fillColor){ - fillColor = '' + item.fillColor + util.ten2XO(item.fillOpaqueness); - } - let polygon = { - points, - strokeColor, - strokeWidth, - fillColor, - zIndex: 1, - id - } - return polygon - }); - // polygons = polygons.concat(newPolygons); - this.setData({ - polygons: polygons.concat(newPolygons) - }) - }, goCalculate() { if (this.data.active === 4) { let basis = this.selectComponent('#basis'); @@ -265,7 +195,7 @@ Page({ this.setData({ landListedId: options.id }) - this.gotoLocation(this.data.landListedId); + // this.gotoLocation(this.data.landListedId); this.getData(options.id) if (active) { active = Number(active); diff --git a/utils/gitUtil.js b/utils/gitUtil.js index 4296f6b..4aada89 100644 --- a/utils/gitUtil.js +++ b/utils/gitUtil.js @@ -35,6 +35,21 @@ const isPointInPolygon = (aLat, aLon, pointList) => { return false } } + +const setWKT = (target, data, id) => { + let { + polygons + } = target.data; + if (data.data && data.data.length > 0) { + let newPolygons = data.data.map(item => { + return item.polygon + }) + target.setData({ + polygons: polygons.concat(newPolygons) + }) + } +} module.exports = { isPointInPolygon, + setWKT }; \ No newline at end of file