mirror of
https://gitee.com/java110/MicroCommunityWeb.git
synced 2026-02-24 21:59:12 +08:00
80 lines
2.4 KiB
JavaScript
80 lines
2.4 KiB
JavaScript
(function (vc) {
|
|
vc.extends({
|
|
data: {
|
|
selectMapPosInfo: {
|
|
mapX:'',
|
|
mapY:'',
|
|
mapData:{},
|
|
addMap:{}
|
|
}
|
|
},
|
|
_initMethod: function () {
|
|
},
|
|
_initEvent: function () {
|
|
vc.on('selectMapPos', 'init', function (_data) {
|
|
$that.selectMapPosInfo.mapData = _data;
|
|
$that._initSelectMapPos(_data);
|
|
});
|
|
},
|
|
methods: {
|
|
_initSelectMapPos:function(_data){
|
|
|
|
let _lng = 116.397128;
|
|
let _lat = 39.916527;
|
|
|
|
if(_data.lng){
|
|
_lng = _data.lng;
|
|
}
|
|
|
|
if(_data.lat){
|
|
_lat = _data.lat;
|
|
}
|
|
try{
|
|
if($that.selectMapPosInfo.addMap){
|
|
$that.selectMapPosInfo.addMap.destroy();
|
|
}
|
|
}catch(e){
|
|
|
|
}
|
|
|
|
|
|
let addMap = new TMap.Map(_data.element, {
|
|
center: new TMap.LatLng(_lat, _lng),
|
|
zoom: 13
|
|
});
|
|
// $that.addMapInfo.addMap = addMap;
|
|
let marker;
|
|
//添加监听事件 获取鼠标点击事件
|
|
addMap.on('click', function (event) {
|
|
if (!marker) {
|
|
marker = new TMap.MultiMarker({
|
|
styleId: "marker",
|
|
position: event.latLng,
|
|
map: addMap,
|
|
id: "1",
|
|
});
|
|
}
|
|
console.log(event)
|
|
//marker.setPosition(event.latLng);
|
|
|
|
$that.selectMapPosInfo.mapData.lat = event.latLng.lat;
|
|
$that.selectMapPosInfo.mapData.lng =event.latLng.lng;
|
|
|
|
marker.updateGeometries([
|
|
{
|
|
"styleId": "marker",
|
|
"id": "1",
|
|
"position": event.latLng,
|
|
}
|
|
])
|
|
});
|
|
//为地图注册click事件获取鼠标点击出的经纬度坐标
|
|
|
|
$that.selectMapPosInfo.addMap = addMap;
|
|
|
|
}
|
|
|
|
|
|
}
|
|
});
|
|
})(window.vc); |