Browse Source

地图渲染优化

master
王健 3 years ago
parent
commit
ad91570650
  1. 27
      components/detail-announcement/detail-announcement.js
  2. 112
      pages/look-detail/look-detail.js
  3. 190
      pages/look/look.js
  4. 124
      pages/lookStay-detail/lookStay-detail.js
  5. 15
      utils/gitUtil.js

27
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,30 +77,32 @@ 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]
if (res.data[0].centerPoint) {
let centerPoint = res.data[0].centerPoint;
let longitude = centerPoint[0]
let latitude = centerPoint[1]
wx.openLocation({
latitude: Number(longitude),
longitude: Number(latitude),
name: res.data[0].name,
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]
if (res.data[0].centerPoint) {
let centerPoint = res.data[0].centerPoint;
let longitude = centerPoint[0]
let latitude = centerPoint[1]
wx.openLocation({
latitude: Number(longitude),
longitude: Number(latitude),
name: res.data[0].name,
latitude: Number(latitude),
longitude: Number(longitude),
scale: 10
})
}
}
})
}
}

112
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,

190
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,34 +719,23 @@ 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;
if (data && data.data && data.data.length > 0) {
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
}
}
return polygon;
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;
}
}
},
removeFeaturesToList(tid) {
let key = 'key' + 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', // 路径,传递参数到指定页面。

124
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: [
{
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;
@ -148,15 +130,15 @@ Page({
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);

15
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
};
Loading…
Cancel
Save