flat: 页面初始化

This commit is contained in:
史典卓
2024-11-18 16:33:37 +08:00
parent cf8fc80b20
commit ad4eb162a5
83 changed files with 8250 additions and 89 deletions

View File

@@ -0,0 +1,268 @@
<template>
<view style="width: 100%; height: 100%">
<view id="mapDiv" class="mapDiv" :apikey="apiKey" :prop="option" :change:prop="Trenderjs.initTMap"></view>
</view>
</template>
<script>
import tools from '../../tools.js';
import iconPath from '../../static/point2.png';
import iconRangePath from '../../static/range.png';
export default {
name: 'TianDiTu-Map',
data() {
return {
Tmap: null,
option: {
type: '',
apikey: '',
cover: null,
lng: '',
lat: '',
png: iconPath,
rangePng: iconRangePath,
showLabel: true,
showCirle: false,
range: 0,
},
};
},
props: {
apiKey: {
type: String,
require: true,
default: '',
},
customIcon: {
type: String,
default: '',
},
showLabel: {
type: Boolean,
default: true,
},
showCirle: {
type: Boolean,
default: true,
},
},
methods: {
compliteonLoadTianDiTu() {
this.$emit('onLoadTianDiTu');
},
initCharts(lng, lat) {
this.option = {
...this.option,
apikey: this.apiKey,
showLabel: this.showLabel,
showCirle: this.showCirle,
lng,
lat,
png: this.customIcon || this.option.png,
type: 'open',
};
},
upDataCharts(lng, lat) {
this.option = {
...this.option,
type: 'Icon',
lng,
lat,
png: this.customIcon || this.option.png,
type: 'update',
showLabel: this.showLabel,
};
},
addFeature(cover) {
this.option = {
...this.option,
type: 'Icon',
cover,
png: this.customIcon || this.option.png,
type: 'addFeature',
showLabel: this.showLabel,
};
},
changeRange(range) {
this.option = {
...this.option,
type: 'Icon',
png: this.customIcon || this.option.png,
type: 'changeRange',
showLabel: this.showLabel,
showCirle: this.showCirle,
range: range,
};
},
selectItem(info) {
this.$emit('onSelect', info);
},
},
};
</script>
<script module="Trenderjs" lang="renderjs">
var Tmap = null;
export default {
data() {
return {
options: {},
circle: [],
}
},
mounted() {
},
methods: {
initTMap(newValue, oldValue, ownerInstance, instance) {
this.options = newValue
if (newValue.type === 'open' && newValue.apikey) {
if (!window.T) {
const script = document.createElement('script')
script.src = 'http://api.tianditu.gov.cn/api?v=4.0&tk=' + this.options.apikey
script.onload = this.initChartsRender.bind(this)
document.head.appendChild(script)
console.log('open')
} else {
const {
lng,
lat
} = this.options
Tmap = null;
Tmap = new T.Map('mapDiv', {
projection: 'EPSG:4326',
});
const control = new T.Control.Zoom({ position: T_ANCHOR_TOP_RIGHT});
const scale = new T.Control.Scale({ position: T_ANCHOR_TOP_LEFT});
Tmap.addControl(scale);
Tmap.addControl(control);
this.upDataChartsRender(lng, lat)
this.$ownerInstance.callMethod('compliteonLoadTianDiTu')
}
} else {
const {
lng,
lat,
cover,
showLabel,
showCirle,
range
} = newValue
switch (newValue.type) {
case 'update':
this.upDataChartsRender(lng, lat)
break;
case 'addFeature':
Tmap.clearOverLays()
this.circle = []
cover.map((item, index) => {
this.setIcon(item.lon, item.lat, false, showLabel, false, showCirle, item)
})
break;
case 'changeRange':
this.setRange(range)
default:
break;
}
}
},
initChartsRender() {
this.$ownerInstance.callMethod('compliteonLoadTianDiTu')
const {
lng,
lat
} = this.options
var that = this;
Tmap = new T.Map('mapDiv', {
projection: 'EPSG:4326',
});
this.upDataChartsRender(lng, lat)
const control = new T.Control.Zoom({ position: T_ANCHOR_TOP_RIGHT});
const scale = new T.Control.Scale({ position: T_ANCHOR_TOP_LEFT});
Tmap.addControl(scale);
Tmap.addControl(control);
console.log('初始化1')
},
upDataChartsRender(lng, lat, zoom = 15) {
if (!Tmap) return
Tmap.centerAndZoom(new T.LngLat(lng, lat), zoom);
},
setRange(range) {
for (let item in this.circle) {
this.circle[item].setRadius(range * 1000)
}
// this.circle.setRadius(range * 1000)
},
setIcon(lng, lat, isClear, isClick = false, isLabel = false, isCirle = false, item) {
if (isClear) {
Tmap.clearOverLays()
}
const latlng = new T.LngLat(lng, lat)
const icon = new T.Icon({
iconUrl: this.options.png,
iconSize: new T.Point(30, 30),
iconAnchor: new T.Point(15, 30)
});
if (isLabel) {
const label = new T.Label({
text: `<div style="max-width: 50px; overflow: hidden">${item.label}</div>`,
position: latlng,
offset: new T.Point(-50, 0)
});
Tmap.addOverLay(label);
}
if(isCirle) {
const circleObj = new T.Circle(latlng , parseFloat(50), {
color:"#13C57C",weight:2,opacity:1,fillColor:"#13C57C",fillOpacity:0.24
})
this.circle.push(circleObj)
Tmap.addOverLay(circleObj);
}
const marker = new T.Marker(latlng, {
icon
});
if (isClick) {
this.removeMarkerClick(marker);
//注册标注的点击事件
marker.addEventListener("click", this.MarkerClick.bind(null, item));
}
Tmap.addOverLay(marker);
},
removeMarkerClick(marker) {
//移除标注的点击事件
marker.removeEventListener("click", this.MarkerClick);
},
MarkerClick(item, e) {
this.openInfo(item.label, e)
this.$ownerInstance.callMethod('selectItem', item)
},
openInfo(content, e) {
const point = e.lnglat;
const marker = new T.Marker(point); // 创建标注
const markerInfoWin = new T.InfoWindow(content, {
offset: new T.Point(0, -30)
}); // 创建信息窗口对象
Tmap.openInfoWindow(markerInfoWin, point); //开启信息窗口
}
},
}
</script>
<style scoped>
#mapDiv {
width: 100%;
height: 100%;
overflow: hidden;
}
/deep/ .tdt-control-copyright {
display: none;
}
/deep/ .tdt-label {
/* background: transparent;
box-shadow: none;
border: 0; */
}
</style>

View File

@@ -0,0 +1,214 @@
<template>
<view style="width: 100%; height: 100%">
<view class="mask" style="width: 100%; height: 100%">
<tiandituMap
ref="tiandituMapRefs"
@onLoadTianDiTu="initMaps"
@onSelect="selectPoint"
:apiKey="apiKey"
:customIcon="icon"
:showLabel="showLabel"
:showCirle="showCirle"
></tiandituMap>
</view>
</view>
</template>
<script>
import tiandituMap from './tianditu-map.vue';
import tools from '../../tools.js';
export default {
name: 'zhuozhuoTiandituPlugin',
components: {
tiandituMap,
},
props: {
apiKey: {
type: String,
require: true,
default: '',
},
icon: {
type: String,
default: '',
},
showLabel: {
type: Boolean,
default: true,
},
showCirle: {
type: Boolean,
default: true,
},
},
data() {
return {
winWidth: 0,
winHeight: 0,
winTop: 0,
visible: false,
datalist: [],
selectItem: {},
iStatusBarHeight: 0,
option: {
apikey: 123123,
},
};
},
created() {
var that = this;
// #ifdef APP
// 44 + 10 44: search Input height
const searchHeight = this.search ? 54 : 10;
const { statusBarHeight, screenHeight, windowHeight } = uni.getSystemInfoSync();
if (screenHeight === windowHeight) {
that.iStatusBarHeight = statusBarHeight + searchHeight;
} else {
that.iStatusBarHeight = 0;
}
// #endif
uni.getSystemInfo({
success: function (res) {
that.winWidth = res.windowWidth;
that.winHeight = res.windowHeight;
that.winTop = res.windowTop;
},
});
},
methods: {
open(lon, lat) {
if (lon && lat) {
this.visible = true;
this.$nextTick(() => {
this.$refs.tiandituMapRefs.initCharts(lon, lat);
});
} else {
console.error('请传入lon, lat');
}
},
upDateLonLat(cover) {
if (lon && lat) {
this.$refs.tiandituMapRefs.upDataCharts(lon && lat);
} else {
console.error('请传入lon, lat');
}
},
addFeature(cover) {
if (cover && Array.isArray(cover) && cover.length) {
this.$refs.tiandituMapRefs.addFeature(cover);
} else {
console.error('请传入 cover', cover);
}
},
changeRange(range) {
this.$refs.tiandituMapRefs.changeRange(range);
},
selectPoint(e) {
this.$emit('onSelect', e);
},
initMaps() {
console.warn('--------天地图加载完成--------');
this.$emit('onLoad');
},
},
};
</script>
<style scope>
.mask {
/* overflow: hidden; */
/* position: fixed;
left: 0;
z-index: 399; */
background-color: #ffffff;
}
/* footer */
.list-boxd {
position: absolute;
bottom: 0;
left: 0;
z-index: 401;
right: 0;
border-radius: 14px 14px 0 0;
background: #ffffff;
transition: all 1s;
}
.list-header {
height: 20px;
position: relative;
border-bottom: 1px solid #f3f4f6;
cursor: pointer;
}
.list-header::after {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
content: '';
height: 6px;
width: 60px;
border-top: 1px solid #e8e8e8;
border-bottom: 1px solid #e8e8e8;
}
.list-content {
max-height: 50vh;
overflow-y: scroll;
}
.card {
min-height: 44px;
padding: 12px;
position: relative;
display: flex;
justify-content: space-between;
align-items: center;
}
.card-left {
display: flex;
flex-direction: column;
justify-content: center;
}
.card-right {
padding-right: 10px;
}
.arrow {
border-top: 2px solid #666666;
border-right: 2px solid #666666;
width: 10px;
height: 10px;
transform: rotate(45deg);
}
.card:active {
background-color: #f3f4f6;
}
.card::after {
position: absolute;
content: '';
bottom: 0;
height: 1px;
background-color: #e8e8e8;
width: 90%;
}
.card:last-child::after {
height: 0;
background-color: #ffffff;
}
.card-title {
font-size: 18px;
}
.card-text {
color: #e8e8e8;
font-size: 13px;
}
</style>