service.map_wev8.js
3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
define("mService/map", ["mUtil", "amapHelper"], function(mUtil, amapHelper) {
return {
mounted: function($page, cfg){
var coordinate = cfg.coordinate || ""; //经度,纬度 或者 中文地址
var type = cfg.type || "2"; //坐标类型:1:高德,腾讯地图类的坐标系。2:百度地图类的坐标系。3:gps类的坐标系 (如果目的地是中文地址,坐标类型无意义)
var $mapContainer = $(".map-container", $page);
var $naviBtn = $(".navi-btn", $page);
mUtil.getLabel(388935, "去这里",function(labelText){
$naviBtn.html(labelText);
});
var $addrContainer = $(".addr-container", $page);
var amap = new AMap.Map($mapContainer[0], {
resizeEnable: true, //是否监控地图容器尺寸变化
zoom: 16
});
if((/.*[\u4e00-\u9fa5]+.*$/).test(coordinate)){ //中文地址
amapHelper.getPosition(coordinate, function(point){
setPoint(point, coordinate);
});
}else{
var arr = coordinate.split(",");
var lng = arr[0]; //地理经度
var lat = arr[1]; //地理纬度
var transPoint = [lng, lat];
if(type == "1"){
setPoint(transPoint);
}else{
amapHelper.convertPoint(transPoint, type, function(convertPoint) {
setPoint(convertPoint);
});
}
}
var destPoint;
$naviBtn.click(function(){
var $that = $(this);
if($that.hasClass("disabled")){
return;
}
$that.addClass("disabled");
Mobile_NS.getCurrPosition(function(result){
$that.removeClass("disabled");
var currLng = result["lng"];
var currLat = result["lat"];
var destLng = destPoint[0];
var destLat = destPoint[1];
var destAddr = $addrContainer.html();
if(mUtil.checkEmpJsApi("navigationLBS")){
mUtil.invokeEmApi("navigationLBS", {
startLatitude: currLat,
startLongitude: currLng,
endLatitude: destLat,
endLongitude: destLng,
address: destAddr
});
}else if(mUtil.runtime.isEmobile6()){
location.href = "emobile:navigation:"+currLat+":"+currLng+":"+destLat+":"+destLng+":"+destAddr;
}else{
location.href = "http://apis.map.qq.com/uri/v1/routeplan?type=drive&from=&fromcoord="+currLat+","+currLng+"&to="+destAddr+"&tocoord="+destLat+","+destLng+"&policy=1&referer=Emobile";
}
});
});
function setPoint(p, addr){
amap.setCenter(p);
var pMarker = new AMap.Marker({
position: p,
icon: new AMap.Icon({
size: new AMap.Size(40, 40),
image: '/mobilemode/mobile/images/plugin/current-location.png',
imageSize: new AMap.Size(40, 40),
imageOffset: new AMap.Pixel(0, 0)
}),
offset: new AMap.Pixel(-20, -35)
});
amap.add(pMarker);
if(addr){
$addrContainer.html(addr);
}else{
amapHelper.getAddress(p[0], p[1], function(rs){
$addrContainer.html(rs.addr);
});
}
$naviBtn.show();
destPoint = p;
}
}
};
});