优化代码

This commit is contained in:
wuxw 2024-06-18 00:58:42 +08:00
parent 9bdc7edcfa
commit 0b0e3b1b83

View File

@ -1,43 +1,43 @@
/**
业主详情页面
**/
(function(vc) {
(function (vc) {
vc.extends({
data: {
inspectionTaskMapInfo: {
datas: [],
map:{}
map: {}
}
},
_initMethod: function() {
_initMethod: function () {
},
_initEvent: function() {
vc.on('inspectionTaskMap','initMap',function(_data){
_initEvent: function () {
vc.on('inspectionTaskMap', 'initMap', function (_data) {
$that._queryInspectionTaskMap(_data);
});
},
methods: {
_queryInspectionTaskMap:function(_route){
_queryInspectionTaskMap: function (_route) {
let param = {
params: {
communityId: vc.getCurrentCommunity().communityId,
inspectionRouteId: _route.inspectionRouteId,
taskId: _route.taskId,
page: 1,
row: 1000
}
};
//发送get请求
vc.http.apiGet('/inspectionRoute.listInspectionRoutePoints',
vc.http.apiGet('/inspection.queryInspectionTaskDetail',
param,
function (json) {
let _json = JSON.parse(json);
$that.inspectionTaskMapInfo.data = _json.inspectionPoints;
$that.inspectionTaskMapInfo.data = _json.data;
$that.initInspectionTaskMap(_json.inspectionPoints);
$that.initInspectionTaskMap(_json.data);
},
function () {
@ -45,19 +45,25 @@
}
);
},
initInspectionTaskMap:function(_pos) {
initInspectionTaskMap: function (_pos) {
let _lng = 116.307484;
let _lat = 39.984120;
// _pos.forEach(_m => {
// let _latLon = wgs84togcj02(_m.lng,_m.lat);
// });
if (_pos && _pos.length > 0) {
_lat = _pos[0].lat;
_lng = _pos[0].lng;
if (!_pos || _pos.length < 1) {
return;
}
_pos.forEach(_p => {
if (_p.lat) {
_lat = _p.lat;
_lng = _p.lng;
}
});
let center = new TMap.LatLng(_lat, _lng)
//定义map变量调用 TMap.Map() 构造函数创建地图
let map = new TMap.Map(document.getElementById('inspectionTaskMap'), {
@ -72,30 +78,30 @@
$that.inspectionTaskMapInfo.map = map;
$that._addTaskPointMachine(_pos);
},
_addTaskPointMachine:function(_pos) {
_addTaskPointMachine: function (_pos) {
let _geometriesMarker = [];
let _geometriesLabel = [];
let _path = [];
_pos.forEach(_m => {
try{
try {
let center = new TMap.LatLng(_m.lat, _m.lng);
_geometriesMarker.push({
"id": _m.inspectionId, //点标记唯一标识后续如果有删除、修改位置等操作都需要此id
"styleId": 'myStyle', //指定样式id
"position": center, //点标记坐标位置
});
_geometriesLabel.push({
'id': 'label_' + _m.inspectionId, //点图形数据的标志信息
'styleId': 'label', //样式id
'position': center, //标注点位置
// 'content': _m.staffName, //标注文本
'content':_m.inspectionName
// 'content': _m.staffName, //标注文本
'content': _m.inspectionName
});
_path.push(center);
}catch(e){
} catch (e) {
}
});
let markerLayer = new TMap.MultiMarker({
@ -114,8 +120,8 @@
//点标记数据数组
geometries: _geometriesMarker
});
var label = new TMap.MultiLabel({
let label = new TMap.MultiLabel({
id: 'label-layer',
map: $that.inspectionTaskMapInfo.map, //设置折线图层显示到哪个地图实例中
//文字标记样式
@ -132,8 +138,8 @@
//文字标记数据
geometries: _geometriesLabel
});
var polylineLayer = new TMap.MultiPolyline({
let polylineLayer = new TMap.MultiPolyline({
id: 'polyline-layer', //图层唯一标识
map: $that.inspectionTaskMapInfo.map,//设置折线图层显示到哪个地图实例中
//折线样式定义