flat: 页面初始化
This commit is contained in:
@@ -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>
|
||||
@@ -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>
|
||||
83
uni_modules/zhuo-tianditu-MultiPoint-Mapper/package.json
Normal file
83
uni_modules/zhuo-tianditu-MultiPoint-Mapper/package.json
Normal file
@@ -0,0 +1,83 @@
|
||||
{
|
||||
"id": "zhuo-tianditu-MultiPoint-Mapper",
|
||||
"displayName": "zhuo-tianditu-MultiPoint-Mapper",
|
||||
"version": "1.0.0",
|
||||
"description": "zhuo-tianditu-MultiPoint-Mapper",
|
||||
"keywords": [
|
||||
"zhuo-tianditu-MultiPoint-Mapper"
|
||||
],
|
||||
"repository": "",
|
||||
"engines": {
|
||||
"HBuilderX": "^3.1.0"
|
||||
},
|
||||
"dcloudext": {
|
||||
"type": "component-vue",
|
||||
"sale": {
|
||||
"regular": {
|
||||
"price": "0.00"
|
||||
},
|
||||
"sourcecode": {
|
||||
"price": "0.00"
|
||||
}
|
||||
},
|
||||
"contact": {
|
||||
"qq": ""
|
||||
},
|
||||
"declaration": {
|
||||
"ads": "",
|
||||
"data": "",
|
||||
"permissions": ""
|
||||
},
|
||||
"npmurl": ""
|
||||
},
|
||||
"uni_modules": {
|
||||
"dependencies": [],
|
||||
"encrypt": [],
|
||||
"platforms": {
|
||||
"cloud": {
|
||||
"tcb": "u",
|
||||
"aliyun": "u",
|
||||
"alipay": "u"
|
||||
},
|
||||
"client": {
|
||||
"Vue": {
|
||||
"vue2": "u",
|
||||
"vue3": "u"
|
||||
},
|
||||
"App": {
|
||||
"app-vue": "u",
|
||||
"app-nvue": "u",
|
||||
"app-uvue": "u"
|
||||
},
|
||||
"H5-mobile": {
|
||||
"Safari": "u",
|
||||
"Android Browser": "u",
|
||||
"微信浏览器(Android)": "u",
|
||||
"QQ浏览器(Android)": "u"
|
||||
},
|
||||
"H5-pc": {
|
||||
"Chrome": "u",
|
||||
"IE": "u",
|
||||
"Edge": "u",
|
||||
"Firefox": "u",
|
||||
"Safari": "u"
|
||||
},
|
||||
"小程序": {
|
||||
"微信": "u",
|
||||
"阿里": "u",
|
||||
"百度": "u",
|
||||
"字节跳动": "u",
|
||||
"QQ": "u",
|
||||
"钉钉": "u",
|
||||
"快手": "u",
|
||||
"飞书": "u",
|
||||
"京东": "u"
|
||||
},
|
||||
"快应用": {
|
||||
"华为": "u",
|
||||
"联盟": "u"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
1
uni_modules/zhuo-tianditu-MultiPoint-Mapper/readme.md
Normal file
1
uni_modules/zhuo-tianditu-MultiPoint-Mapper/readme.md
Normal file
@@ -0,0 +1 @@
|
||||
# zhuo-tianditu-MultiPoint-Mapper
|
||||
BIN
uni_modules/zhuo-tianditu-MultiPoint-Mapper/static/point.png
Normal file
BIN
uni_modules/zhuo-tianditu-MultiPoint-Mapper/static/point.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 926 B |
BIN
uni_modules/zhuo-tianditu-MultiPoint-Mapper/static/point2.png
Normal file
BIN
uni_modules/zhuo-tianditu-MultiPoint-Mapper/static/point2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 841 B |
BIN
uni_modules/zhuo-tianditu-MultiPoint-Mapper/static/range.png
Normal file
BIN
uni_modules/zhuo-tianditu-MultiPoint-Mapper/static/range.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.5 KiB |
106
uni_modules/zhuo-tianditu-MultiPoint-Mapper/tools.js
Normal file
106
uni_modules/zhuo-tianditu-MultiPoint-Mapper/tools.js
Normal file
@@ -0,0 +1,106 @@
|
||||
/**
|
||||
* @param title String,提示的内容
|
||||
* @param duration String,提示的延迟时间,单位毫秒,默认:1500
|
||||
* @param mask Boolean,是否显示透明蒙层,防止触摸穿透,默认:false
|
||||
* @param icon String,图标:success、error、fail、exception、loading、none,默认:none
|
||||
**/
|
||||
export function createMessage(title, duration = 1500, mask = false, icon = "none") {
|
||||
uni.showToast({
|
||||
title,
|
||||
duration: duration,
|
||||
mask,
|
||||
icon
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param url String,请求的地址,默认:none
|
||||
* @param data Object,请求的参数,默认:{}
|
||||
* @param method String,请求的方式,默认:GET
|
||||
* @param loading Boolean,是否需要loading ,默认:false
|
||||
* @param header Object,headers,默认:{}
|
||||
* @returns promise
|
||||
**/
|
||||
export function createRequest(url, data = {}, loading = false, method = 'GET', header = {}) {
|
||||
if (loading) {
|
||||
uni.showLoading({
|
||||
title: '请稍后',
|
||||
mask: true
|
||||
})
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.request({
|
||||
url: url,
|
||||
method: method,
|
||||
data: data,
|
||||
header: header,
|
||||
success: res => {
|
||||
if (res.statusCode === 200) {
|
||||
resolve(res.data)
|
||||
} else {
|
||||
if (res.data.msg) {
|
||||
const str = typeof res.data.resolve === 'string' ? ',' + res.data.resolve :
|
||||
''
|
||||
createMessage(res.data.msg + str)
|
||||
}
|
||||
throw new Error('请求错误 ' + url)
|
||||
reject()
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
reject(err)
|
||||
},
|
||||
complete: () => {
|
||||
uni.hideLoading();
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据格式化
|
||||
* @param obj Object,响应的数据
|
||||
* @param type Number 0 | 1,处理类型
|
||||
* @returns Object {address = string, name = string, location = {lon, lat }, infomation = {}}
|
||||
*/
|
||||
export function formatterAdressLocation(obj, type) {
|
||||
switch (type) {
|
||||
case 1:
|
||||
return {
|
||||
address: obj.formatted_address,
|
||||
name: '',
|
||||
location: obj.location,
|
||||
infomation: obj.addressComponent
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
const [lon, lat] = obj.lonlat.split(',')
|
||||
return {
|
||||
address: obj.address,
|
||||
name: obj.name,
|
||||
location: {
|
||||
lon,
|
||||
lat
|
||||
},
|
||||
infomation: obj
|
||||
}
|
||||
break
|
||||
case 3:
|
||||
return {
|
||||
address: obj.location.keyWord,
|
||||
name: '',
|
||||
location: {
|
||||
lon: obj.location.lon,
|
||||
lat: obj.location.lat,
|
||||
},
|
||||
infomation: obj.location
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
export default {
|
||||
createMessage,
|
||||
createRequest,
|
||||
formatterAdressLocation
|
||||
}
|
||||
Reference in New Issue
Block a user