;(function(exports) {
var MapShare = {
}
var headFootUI = {
resizePage : function(){
}
}
// var headFootUI = new App.HeadFootUI({
// showHeadBanner : true,
// showFootBanner : true,
// showHeadNav : false,
// showFootNav : true,
// nav : [{
// name : '地图导航',
// url : 'upaGuidance.html'
// }],
// callAfterLoad:function(){
// MapShare.topHeight = this._elHead.height();
// }
// });
var loadingMov = {
loadingBegin : exports.loadingBegin,
loadingFinish : exports.loadingFinish
};
var configLan = { // configLan.interfaceErro
notResult : '无匹配结果',
clearHistory : '清除历史记录',
hasNotHistory : '暂无历史记录',
emptyWord : '',
locating : '正在定位您的位置..',
myPlace : '我的位置',
Tip : '温馨提示:',
putInStartPlace : '请输入起点',
putInEndPlace : '请输入终点',
interfaceErro:'接口出错'
}
var UpingAnUrl = {
store : 'data/guidance/store.json'
}
if(!App.IS_DEV){
UpingAnUrl.store = App.getWebServiceUrl('SearchLifeStoreAction');
}
var mapObj;
var searchPathView = null; //来自后面实例化的。。。
var curInforWindow = null; //当前的弹出窗口
var topHeight = 68;
var LocationModel = PackTools.Model.extend({
initLevel : 16, //16
currentLocal : null, //当前地理位置(用h5获),没定位到就为空
locating : false, //地理位置方法正在定位
serchKeyWord : '',
city : '', //与 init里的 mapObjects 的坐标对应 北京
imgUrl : '../../mobile/common_images/',
storeData : null, //平安门店数据,从平安接口得
defaults : {
locationLabel : configLan.locating,
curAddress : '', //当前位置的全信息
itemName : '', //多个地点弹出框 当前点钟的弹出框的名字. 每次点击弹出框都会被设置
pageFrom: '',//由于很多地方可能返回同一个页面(div),以此表示刚才从哪里来的,以便返回的时候返回到原地
aroundLocal : {
name : '',
pos : null
}, //周边搜索时用到的当前位置. name地点名称, pos:经度和纬度AMap.LngLat
aroundLocals : [] //多个地点周边搜索时. 参考queryOutlet:{infoId:item.infoId, position:pos}
},
aboutMe : function() {
},
getLocation : function(success, failure) {
// 正在定位
if(this.locating) {
return false;
}
loadingMov.loadingBegin();
this.locating = true;
App.consoleLog('App.IS_DEV:' + App.IS_DEV);
if(App.IS_DEV){ //stz test
success({
coords:{
latitude: 31.230393,
longitude: 121.473704
}
});
this.locating = false;
loadingMov.loadingFinish();
return;
}
if(navigator.geolocation) {
var self = this;
navigator.geolocation.getCurrentPosition(function(position) {
// 定位成功
success(position);
self.locating = false;
loadingMov.loadingFinish();
}, function(error) {
// 定位失败
failure(error);
self.locating = false;
loadingMov.loadingFinish();
}, {
enableHighAcuracy : true,//默认为false,是否尝试更精确地读取纬度和经度,移动设备上,这可能要使用手机上的GPS,这会消耗移动设备更多的电量
timeout : 30000,
maximumAge : 3000
});
} else {
// 设备不支持定位
failure('您的设备不支持Geolocation定位功能!');
this.locating = false;
loadingMov.loadingFinish();
}
},
query_byKeywords : function(PoiOptions, startPlace, city, sucess) {
//地图相关信息
loadingMov.loadingBegin();
var autoCompleter = new AMap.PoiSearch(PoiOptions);
autoCompleter.byKeywords(startPlace, city, function(resp) {
sucess(resp);
loadingMov.loadingFinish();
});
},
query_inputPrompt : function(PoiOptions, place, city, sucess) {
//地图相关信息
loadingMov.loadingBegin();
var autoCompleter = new AMap.PoiSearch(PoiOptions);
autoCompleter.inputPrompt(place, city, function(resp) {
sucess(resp);
loadingMov.loadingFinish();
});
},
query_byCenPoi : function(PoiOptions, keyword, sucess, failure) {
//周边搜索
loadingMov.loadingBegin();
var centXY = this.get('aroundLocal').pos;
if(!centXY) {
failure('坐标获取错误');
loadingMov.loadingFinish();
return;
}
var MSearch = new AMap.PoiSearch(PoiOptions);
MSearch.byCenPoi(centXY, keyword, function(resp) {
sucess(resp);
loadingMov.loadingFinish();
});
},
regeocode : function(callBack) {
// 逆编码当前位置信息
loadingMov.loadingBegin();
var geocoder = new AMap.Geocoder({
crossnum : 0,
roadnum : 0,
poinum : 1
});
var coords = this.currentLocal.coords;
geocoder.regeocode(new AMap.LngLat(coords.longitude, coords.latitude), function(data) {
callBack(data);
loadingMov.loadingFinish();
});
},
queryStore : function(coords, callBack) {
//查询平安服务门店信息
loadingMov.loadingBegin();
var model = this;
$.ajax({
url : UpingAnUrl.store, //App.getWebServiceUrl('QueryPAShopInfoController'), //'data/guidance/outlet.json'
data : {
provinceName : '',
cityName : model.city || '',
areaName : '',
longitude : coords.longitude.toString(),
latitude : coords.latitude.toString(),
radius : '10', //宝安机场到小梅沙直线距离
responseProtocol : 'json'
},
type : 'GET',
dataType : 'json',
error : function(xhr, errorType) {
App.consoleLog(errorType);
mapView.showMapTip('发生错误', '网络发生错误,请稍后重试!');
loadingMov.loadingFinish();
},
success : function(response) {
// 获取门店信息,在地图中进行标注
loadingMov.loadingFinish();
if(!response || +response.resultCode !== 0) {
mapView.showMapTip('发生错误', '获取门店信息失败,请稍后重试!');
return false;
}
if(!response || !response.claimStore || !response.claimStore.length) {
mapView.showMapTip('搜索失败', '附近还没有找到门店');
return false;
}
callBack(response);
}
});
}
});
var locationModel = new LocationModel();
locationModel.on('locationChange', function(txt) {
var _locationLabel = mapView.getElement('_locationLabel');
_locationLabel.text(txt);
})
var SearchBarView = PackTools.View.extend({
historySearchConf : {
range : 1000000, //9600000 960公里范围内
sort : 0,
retvalue : 1
},
tipSearchConf : {//这配置和 inputPrompt也没啥关系啊
range : 500000, //找附近50公里内
sort : 0,
retvalue : 1
},
renderHtml : '',
initialize : function() {
var searchbar = this.options.searchbar, drawList = this.options.drawList;
_.extend(this, {
searchField : searchbar.find('#searchPageField'),
searchBtn : searchbar.find('#searchPageBtn'),
searchTip : this.options.searchTip,
searchHistory : drawList,
searchHistoryList : drawList.find('#searchHistoryList'),
searchHistory_template : drawList.find('#searchHistory_template'),
clearHistoryBtn : drawList.find('#clearHistoryBtn')
});
var el = this.el, input = this.searchField, //parent=el.parent(), btn=this.searchBtn.parent(),
self = this;
// input.width(parent.width()-btn.width()-parseInt(input.css('padding-left'))-parseInt(input.css('padding-right')));
// drawList.width(parent.width()-5);
this.searchBtn.tap(function() {
var inputVal = input.val().trim();
if(inputVal) {
/*
var newData = Cookie('searchHistoryData');
var history = JSON.parse(newData);
if(!history)
history = [];
var hasVal = _.some(history, function(v, i) {
if(v.name == inputVal) {
return true
}
});
if(!hasVal) {//最多10条
history.unshift({
id : history.length,
name : inputVal
});
if(history.length > 10) {
history = history.slice(0, 10);
}
Cookie('searchHistoryData', JSON.stringify(history));
}
*/
//调周边搜索api 与首页的不同
self.model.query_byCenPoi(self.historySearchConf, inputVal, function(resp) {
if(!resp.list || !resp.list.length){
mapView.showMapTip(configLan.Tip, '没有搜索到关键字相关的地点');
return;
}
self.model.serchKeyWord = inputVal;
mapView.showSearchResult(resp);
},function(erro){
if(typeof(erro)=='string'){
mapView.showMapTip(configLan.interfaceErro, erro);
}
});
} else {
mapView.showMapTip('信息不完整', '请输入要搜索的地点或商户');
}
return false;
});
/*
input.on('focus', function() {
self.searchTip.hide();
//与首页的不同
var inputVal = input.val().trim();
if(!inputVal) {
var newData = Cookie('searchHistoryData');
if(!newData) {
self.clearHistoryBtn.text(configLan.hasNotHistory);
//与首页的不同
} else {
var newData = Cookie('searchHistoryData');
var history = JSON.parse(newData);
self.clearHistoryBtn.text(configLan.clearHistory);
self.renderHtml = _.template(self.searchHistory_template.html(), {
history : history
});
self.renderDrawList();
}
}
self.searchHistory.show();
//uPAResizePage();
});
input.on('blur', function() {
var inputVal = input.val().trim();
self.searchHistory.hide();
//uPAResizePage();
});
input.on('keydown', _.debounce(function(e) {
var inputVal = input.val().trim();
if(!inputVal){
return;
}
self.model.query_inputPrompt(self.tipSearchConf, inputVal, self.model.city, function(resp) {
var list = resp.list, history = [];
// self.clearHistoryBtn.text(configLan.emptyWord);
self.searchHistory.hide();
//输入时隐藏历史记录-与首页的不同
self.searchTip.show();
//输入时显示提示-与首页的不同
if(list && ( len = list.length)) {
len = len < 10 ? len : 10;
//最多10条记录
for(var i = 0; i < len; i++) {
history.unshift({
id : i,
name : list[i]
});
}
self.renderHtml = _.template(self.searchHistory_template.html(), {
history : history
});
self.renderSearchTip();
//与首页的不同
} else {
history.unshift({
id : -1,
name : configLan.notResult
});
self.renderHtml = _.template(self.searchHistory_template.html(), {
history : history
});
self.renderSearchTip();
//与首页的不同
}
});
}, 300));
this.clearHistoryBtn.tap(function() {
Cookie('searchHistoryData', null);
self.renderHtml = '';
self.renderDrawList();
});
this.searchHistoryList.tap(function(e) {
self.searchField.val(e.target.innerText);
});
this.searchTip.tap(function(e) {
self.searchField.val(e.target.innerText);
});
*/
// var searchHistoryData = Cookie('searchHistoryData');
// this.searchHistoryList.data('searchHistoryData',searchHistoryData);
// var history=JSON.parse(searchHistoryData);
// this.renderHtml = _.template(self.searchHistory_template.html(), {
// history : history
// });
},
renderDrawList : function() {
this.searchHistoryList.html(this.renderHtml);
},
renderSearchTip : function() {
this.searchTip.html(this.renderHtml);
//uPAResizePage();
}
});
var MapView = PackTools.View.extend({
_mapObj : null,
initialize : function() {
if(!this.el || !this.el.size()) {
throw new Error('dom element not found');
}
var _container = this.el;
this._mapCtx = _container.find('#mapObj');
this._topBar = _container.find('#centerSearchTop');
//顶部栏
this._bottomBar = _container.find('#mapService');
//底部栏
this._locationLabel = _container.find('#locationLabel');
this._serviceOutlet = _container.find('#serviceOutlet');
//门店按钮
this._locationLabel.text(configLan.locating);
var self = this;
var mapServiceVisible = true;
var _mapTip = $('#mapTip');
this._mapTipComp = {
el : _mapTip,
mapTipTitle : _mapTip.find('#mapTipTitle'),
mapTipText : _mapTip.find('#mapTipText'),
mapTipTimeout : null
}
//搜索首页 返回官网首页
/*
var topbarBack = this._topBar.find('#topbarBack');
topbarBack.tap(function() {
App.href('index.html');
});
*/
var searchbar = this._topBar.find('#searchbar');
var drawList = this._topBar.find('#searchBarTip');
var view = this;
this._searchbar = {//内部对象,首页搜索组件。对比 SearchView中的,将用 SearchBarView
el : searchbar,
isHistory : true, //默认的是历史记录列表,否则是提示列表
historySearchConf : {
range : 1000000, //9600000 960公里范围内
sort : 0,
retvalue : 1
},
tipSearchConf : {
range : 500000, //找附近50公里内
sort : 0,
retvalue : 1
},
searchField : searchbar.find('#searchPageField'),
searchBtn : searchbar.find('#searchPageBtn'),
searchHistory : drawList.find('#searchHistory'),
searchHistoryList : drawList.find('#searchHistoryList'),
searchHistory_template : drawList.find('#searchHistory_template'),
clearHistoryBtn : drawList.find('#clearHistoryBtn'),
closeHistoryBtn : drawList.find('#closeHistoryBtn'),
renderHtml : '',
init : function() {
var el = this.el, parent = el.parent(), input = this.searchField, btn = this.searchBtn.parent(), self = this;
//input.width(parent.width() - btn.width() - parseInt(input.css('padding-left')) - parseInt(input.css('padding-right')));
//drawList.width(parent.width() - 5);
this.searchBtn.tap(function() {
var inputVal = input.val().trim();
if(inputVal) {
/*
var newData = Cookie('searchHistoryData');
var history = JSON.parse(newData);
if(!history)
history = [];
//searchHistory.push(); //格式: [{id:1,name:"1"},{id:2,name:"2f"}]
var hasVal = _.some(history, function(v, i) {
if(v.name == inputVal) {
return true
}
});
if(!hasVal) {//最多10条
history.unshift({
id : history.length,
name : inputVal
});
if(history.length > 10) {
history = history.slice(0, 10);
}
Cookie('searchHistoryData', JSON.stringify(history));
}
*/
view.model.query_byKeywords(self.historySearchConf, inputVal, view.model.city, function(resp) {
if(!resp.list || !resp.list.length){
mapView.showMapTip(configLan.Tip, '没有搜索到关键字相关的地点');
return;
}
view.model.serchKeyWord = inputVal;
mapView.showSearchResult(resp);
});
} else {
mapView.showMapTip('信息不完整', '请输入要搜索的地点或商户');
}
return false;
});
/*
input.on('focus', function() {
self.isHistory = true;
var inputVal = input.val().trim();
if(!inputVal) {
var newData = Cookie('searchHistoryData');
if(!newData) {
self.clearHistoryBtn.text(configLan.emptyWord);
} else {
var newData = Cookie('searchHistoryData');
var history = JSON.parse(newData);
self.clearHistoryBtn.text(configLan.clearHistory);
self.renderHtml = _.template(self.searchHistory_template.html(), {
history : history
});
self.renderDrawList();
}
}
drawList.show();
});
input.on('blur', function() {
drawList.hide();
});
input.on('keydown', _.debounce(function(e) {
var inputVal = input.val().trim();
if(!inputVal){
return;
}
view.model.query_inputPrompt(self.tipSearchConf, inputVal, view.model.city, function(resp) {
var list = resp.list, history = [];
self.clearHistoryBtn.text(configLan.emptyWord);
if(list && ( len = list.length)) {
len = len < 10 ? len : 10;
//最多10条记录
for(var i = 0; i < len; i++) {
history.unshift({
id : i,
name : list[i]
});
}
self.renderHtml = _.template(self.searchHistory_template.html(), {
history : history
});
self.renderDrawList();
} else {
history.unshift({
id : -1,
name : configLan.notResult
});
self.renderHtml = _.template(self.searchHistory_template.html(), {
history : history
});
self.renderDrawList();
}
});
}, 300));
this.clearHistoryBtn.tap(function() {
Cookie('searchHistoryData', null);
self.renderHtml = '';
self.renderDrawList();
drawList.hide();
});
this.closeHistoryBtn.tap(function() {
drawList.hide();
});
this.searchHistoryList.tap(function(e) {
self.searchField.val(e.target.innerText);
});
*/
},
renderDrawList : function() {
this.searchHistoryList.html(this.renderHtml);
}
}.init();
this._serviceOutlet.tap(function() {
view.showServiceOutlet();
})
}, //initial
setMapObj : function(obj) {
this._mapObj = obj;
},
getMapObj : function(obj) {
return this._mapObj;
},
showServiceOutlet : function(jumpCurLocal) {
//jumpCurLocal: true 跳过 验证定位
var view = this;
var mapviewMod = view.model, coords = null;
var pos;
if(jumpCurLocal){
pos = mapviewMod.get('aroundLocal').pos;
coords = {
longitude: pos.lng,
latitude: pos.lat
};
}else{
if(!mapviewMod.currentLocal) {
if(mapviewMod.locating) {
mapView.showMapTip('正在定位', '正在获取您所在的位置,请稍等!');
} else {
mapView.showMapTip('定位失败', '对不起,无法检测到您的位置!');
}
return false;
}
coords = mapviewMod.currentLocal.coords
}
mapviewMod.queryStore(coords, function(response) {
mapObj.clearMap();
var data = response.claimStore, item = null;
mapviewMod.aroundLocals = [];
mapviewMod.storeData = data;
for(var i = 0, len = data.length; i < len; i++) {
item = data[i];
var pos = new AMap.LngLat(item.longitude, item.latitude); //平安经纬度不是x/y 而是 longitude latitude
var img = getCDNPicURL(mapviewMod.imgUrl + "map_pin.png");
var marker = new AMap.Marker({
map: mapObj,
draggable: 0,
position : pos, //position:e.lnglat
icon : new AMap.Icon({
size:new AMap.Size(50,56),
image:img
}),
offset : {
x:-14, //-37
y:-56
}
});
var info = _.template($('#upaInfoWinTempate').html(), {
titleClick : ' onmousedown="App.MapShare.detailView.showOutletDetail(' + item.infoId + ')"',
dataTp : item
});
var inforWindow = new AMap.InfoWindow({
autoMove : true,
isCustom : true,
size : new AMap.Size(330, 90),
offset : new AMap.Pixel(0, -58), //0, -45
content : info
});
mapviewMod.aroundLocals.push({
infoId : item.infoId,
position : pos
});
AMap.event.addListener(marker,'click',(function(inforWindow, marker, item) {
return function() {
var tempPos = marker.getPosition();
inforWindow.open(view._mapObj, tempPos);
var namet = item.storeName;
view.model.itemName = namet;
curInforWindow = inforWindow;
/*
var wordLen = namet.getByte(),
infoTitle = $('#upaInfoWin'+item.infoId+' .infoTitle'),
oldwordPix=infoTitle.width(), wordPix=wordLen*parseInt(infoTitle.css('font-size'))/2+3;
if(oldwordPix<wordPix){
infoTitle.width(wordPix);
$('#upaInfoWin'+item.infoId).css('margin-left',(oldwordPix-wordPix)/2+'px');
}
*/
}
})(inforWindow, marker, item));
}
mapObj.setFitView();
});
},
showMapTip : function(title, text) {
var _mapTipComp = this._mapTipComp;
clearTimeout(_mapTipComp.mapTipTimeout);
if(!title)
title = '温馨提示';
_mapTipComp.mapTipTitle.text(title);
_mapTipComp.mapTipText.text(text);
_mapTipComp.el.show();
_mapTipComp.el.on('click', function() {
_mapTipComp.el.hide();
})
_mapTipComp.mapTipTimeout = setTimeout(function() {
_mapTipComp.el.hide();
}, 3000);
},
drawCurPosition : function(pos) {
var mapviewMod = this.model;
if(!mapviewMod.currentLocal || !mapviewMod.currentLocal.coords) {
return false;
}
//var coords = mapviewMod.currentLocal.coords;
//console.log([coords.longitude, coords.latitude]);
//var pos = new AMap.LngLat(coords.longitude, coords.latitude);
// 绘制当前位置标识
var localCircle = new AMap.Circle({
map: mapObj,
center : pos,
radius : 255,
strokeColor : "#80aced",
strokeOpacity : 1,
strokeWeight : 2,
fillColor : "#80aced",
fillOpacity : 0.2
});
var img = getCDNPicURL(mapviewMod.imgUrl + "curPosIcon2.png");
var localMarker = new AMap.Marker({
map: mapObj,
// map : mapObj,
draggable: 0,
position : pos, //position:e.lnglat
icon : img,
offset : {
x:-22,
y:-34
}
});
/*
* new AMap.Icon({
size:new AMap.Size(50,56),
image:img,
})
*/
},
showCenterMap : function(hide) {
if(hide) {
this._topBar.hide();
this._bottomBar.hide();
} else {
this._topBar.show();
this._bottomBar.show();
}
},
showAroundSerach : function(itemName) {
searchView.showNearbySearchText(itemName);
searchView.searchTip.hide();
searchView.el.show();
this.el.hide();
//uPAResizePage();
},
showSearchResult : function(resp) {
if(!resp) {
return false;
}
var list = resp.list;
if(!list || !list.length) {
return false;
}
//---------------render List
var view = this, mapviewMod = view.model;
var mapObj = view.getMapObj();
mapObj.clearMap();
//设置各处标题
var firstItem = null;
var item = null;
mapviewMod.aroundLocals = [];
//var html = [];
for(var i = 0, len = list.length; i < len; i++) {
item = list[i];
var pos = new AMap.LngLat(item.x, item.y);
if(i == 0) {
firstItem = item;
}
var itemNew = {
infoId : ''+i,
name : item.name,
tel : item.tel,
address : item.address,
distance: item.distance,
eaddress: item.eaddress,
ename: item.ename,
match: item.match,
//name: item.name,
pguid: item.pguid,
srctype: item.srctype,
//tel: item.name,
type: item.type,
x: item.x,
y: item.y,
hasSetPos: false //窗体已经设置过位置
};
list[i] = itemNew; //用新格式的数据
var img = getCDNPicURL(mapviewMod.imgUrl + "map_pin.png");
var marker = new AMap.Marker({
map: mapObj,
draggable: 0,
position : pos, //position:e.lnglat
icon : new AMap.Icon({
size:new AMap.Size(50,56),
image:img
}),
offset : {
x:-14, //-37
y:-56
}
});
var info = _.template($('#upaInfoWinTempate').html(), { //窗口id也和 itemNew.infoId挂钩,这样,marker InfoWindow 都挂钩了并用这个作为区别
titleClick : ' onmousedown="App.MapShare.detailView.showOtherDetail(' + itemNew.infoId + ')"',
dataTp : itemNew
});
var inforWindow = new AMap.InfoWindow({
autoMove : true,
isCustom : true,
size : new AMap.Size(330, 90),
offset : new AMap.Pixel(0, -58),
content : info
});
mapviewMod.aroundLocals.push({
infoId : itemNew.infoId,
position : pos
});
AMap.event.addListener(marker,'click',(function(inforWindow, marker, item) {
return function() {
var tempPos = marker.getPosition();
inforWindow.open(view._mapObj, tempPos);
var namet = item.name || item.storeName;
view.model.itemName = namet;
curInforWindow = inforWindow;
/*
var wordLen = namet.getByte(),
infoTitle = $('#upaInfoWin'+item.infoId+' .infoTitle'),
oldwordPix=infoTitle.width(), wordPix=wordLen*parseInt(infoTitle.css('font-size'))/2+3;
if(oldwordPix<wordPix){
infoTitle.width(wordPix);
$('#upaInfoWin'+item.infoId).css('margin-left',(oldwordPix-wordPix)/2+'px');
//var newwidth
}
*/
}
})(inforWindow, marker, itemNew));
}
mapviewMod.storeData = list;
if(firstItem) {
mapObj.setCenter(new AMap.LngLat(firstItem.x, firstItem.y));
}
view.el.show();
view.showCenterMap();
view._locationLabel.parent().hide();
mapObj.setFitView();//2013-8-21 搜索结果自适应窗口
searchView.el.hide();
//uPAResizePage();
}
});
var DetailView = PackTools.View.extend({
_mapView : null,
_mapObj : null,
initialize : function() {
if(!this.el || !this.el.size()) {
throw new Error('dom element not found');
}
var el = this.el;
this._mapView = mapView;
this._mapObj = mapView._mapObj;
this.detailName = el.find('#detailName');
this.detailAddress = el.find('#detailAddress');
this.detailDistance = el.find('#detailDistance');
this.detailTel = el.find('#detailTel');
this.detailPageBack = el.find('#detailPageBack');
this.detailMapBtn = el.find('#detailMapBtn');
//查看地图
this.detailGoThere = el.find('#detailGoThere');
this.detailFromHere = el.find('#detailFromHere');
this.detailFindBtn = el.find('#detailFindBtn');
//附近
// mapView.el.data('box-shadow', mapView.el.css('box-shadow'));
// mapView.el.css('box-shadow','none')
// this.el.addClass('viewHasBG');
// this.el.css('top','60px'); // topHeight
// 从详情页返回
var view = this;
this.detailPageBack.tap(function() {
view.model.set('pageFrom',''); //返回首页清除页面来源地址
view._mapView.el.show();
view.el.hide();
//uPAResizePage();
});
this.detailMapBtn.tap(function() {
view._mapView.el.show();
view.el.hide();
//uPAResizePage();
});
this.detailGoThere.click(function() {
view.el.hide();
var model=view.model, around=model.get('aroundLocal');
model.set('pageFrom',detailView.name);
if(!searchPathView) searchPathView = MapShare.searchPathView;
// var startPlace = null, coords=null;
// if(model.currentLocal){//没定位到值才设置为空
// coords = model.currentLocal.coords;
// startPlace = {
// name: '我的位置',
// x: coords.longitude,
// y: coords.latitude
// }
// }
var place= view.getCurBusInfo();
searchPathView.setSearchInput(place,{
name: around.name,
x: around.pos.lng,
y: around.pos.lat
});
// $("#querypath #startPlace").val('');
// $("#querypath #endPlace").val(view.model.get('aroundLocal').name);
// view.el.hide();
// $('#querypath').show();
// uPAResizePage();
return false;
});
this.detailFromHere.click(function() {
view.el.hide();
var model=view.model, around=model.get('aroundLocal');
model.set('pageFrom',detailView.name);
if(!searchPathView) searchPathView = MapShare.searchPathView;
// var endPlace = null, coords=null;
// if(model.currentLocal){
// coords = model.currentLocal.coords;
// endPlace = {
// name: '我的位置',
// x: coords.longitude,
// y: coords.latitude
// }
// }
var place= view.getCurBusInfo();
searchPathView.setSearchInput({
name: around.name,
x: around.pos.lng,
y: around.pos.lat
},place);
// $("#querypath #startPlace").val(view.model.get('aroundLocal').name);
// $("#querypath #endPlace").val('');
// view.el.hide();
// $('#querypath').show();
// uPAResizePage();
return false;
});
this.detailFindBtn.tap(function() {
mapView.showAroundSerach(view.model.itemName);
view.el.hide();
searchView.el.show();
//uPAResizePage();
return false;
});
},
showOutletDetail : function(id) {
var view = mapView;
var target = event.target || event.srcElement;
var parentWin;
var data = null;
var model = view.model;
var aroundLocals = model.aroundLocals;
for(var i = 0, len = aroundLocals.length; i < len; i++) {
if(aroundLocals[i].infoId == id) {
data = aroundLocals[i];
break;
}
}
//详情页会用到 aroundLocal的pos,表示当前点击的是哪个地点
model.set({//每次点击弹出框都会进这 设置数据- 当前 地点。
aroundLocal : {
name : view.model.itemName,
pos : data.position
}
});
//详情
var storeData = model.storeData;
for(var i = 0, len = storeData.length; i < len; i++) {
if(storeData[i].infoId == id) {
data = storeData[i];
break;
}
}
mapView.el.hide();
detailView.showDetailPage(data);
},
getCurBusInfo : function(){
//如果有定位到就 返回 当前位置所组成的公交查询对象
var place = null, coords=null;
if(this.model.currentLocal){
coords = this.model.currentLocal.coords;
place = {
name: '我的位置',
x: coords.longitude,
y: coords.latitude
}
}
return place;
},
showOtherDetail : function(id) {//除门店等 非平安的详情
// var data = null;
// var outletData = this.model.outletData;
// for (var i = 0, len = outletData.length; i < len; i++) {
// if (outletData[i].infoId == id) {
// data = outletData[i];
// break;
// }
// }
// this._mapView.el.hide();
// this.showDetailPage(data);
this.showOutletDetail(id);
},
showDetailPage : function(data) {
this.detailName.html(data.name || data.storeName);
this.detailAddress.html(data.address);
//计算两点间距离
var currentPos = null, aroundPos = null, coords = null;
var distance;
if(this.model.currentLocal){
coords = this.model.currentLocal.coords;
currentPos = new AMap.LngLat(coords.longitude, coords.latitude);
aroundPos = new AMap.LngLat(data.x || data.longitude, data.y || data.latitude);
distance = currentPos.distance(aroundPos) / 1000;
this.detailDistance.html(distance.toFixed(2).toString());
this.detailDistance.parent().show();
}else{
this.detailDistance.parent().hide();
}
this.detailTel.html(data.tel || data.phone);
this.el.show();
//uPAResizePage();
}
});
var SearchView = PackTools.View.extend({
_mapObj : null,
initialize : function() {
if(!this.el || !this.el.size()) {
throw new Error('dom element not found');
}
var el = this.el;
this._mapObj = mapView._mapObj;
this.topbar = el.find('.position_box');
this.searchTip = el.find('#searchTip');
this.searchHistory = el.find('#searchHistory');
this.searchService = el.find('#searchService');
//top:
this.searchpageBack = el.find('#searchpageBack');
//searchService:
this.nearbySearchText = this.searchService.find('.near_search');
this.outletBtn = this.searchService.find('#serviceOutlet');
var view = this;
this.searchTip.hide();
this.searchHistory.hide();
this.searchpageBack.tap(function() {
//回首页- 不回详情了。 因为首页也有附近搜索
mapView.el.show();
view.el.hide();
//uPAResizePage();
})
this._searchbar = new SearchBarView({
el : view.topbar.find('#searchbar'),
model : locationModel,
searchbar : view.topbar.find('#searchbar'),
drawList : view.searchHistory,
searchTip : view.searchTip
});
this.outletBtn.tap(function() {
mapView.showServiceOutlet(true);
mapView._topBar.show();
mapView.el.show();
view.el.hide();
//uPAResizePage();
});
}, //initial
showNearbySearchText : function(text) {
this.nearbySearchText.find('span').text(text);
}
});
var mapView = new MapView({
el : $('#map'), //容器Dom对象 最外层的容器
model : locationModel,
name : 'mapView1'
});
var detailView = new DetailView({
el : $('#detailpage'),
model : locationModel,
name : 'detailView1'
});
var searchView = new SearchView({
el : $('#searchpage'),
model : locationModel,
name : 'searchView1'
})
function getLocation() {
var mapviewMod = mapView.model;
return mapviewMod.getLocation(function(position) {
var coords = position.coords;
mapviewMod.currentLocal = position;
// console.log([coords.longitude, coords.latitude]);
var pos=new AMap.LngLat(coords.longitude, coords.latitude);
// mapObj.setCenter(pos);
// mapObj.setZoom(mapviewMod.initLevel);
mapObj.setZoomAndCenter(mapviewMod.initLevel, pos);
mapObj.clearMap();
mapView.drawCurPosition(pos);
// mapObj.setFitView();
//stz必须在 setCenter后
mapviewMod.regeocode(function(data) {
if(data && data.list) {
var local = data.list[0];
var province = local.province.name;
var city = mapviewMod.city = local.city.name;
var district = local.district.name;
var road = local.roadlist || '';
if(road) {
road = road[0].name;
}
var address = local.poilist || '';
if(address) {
address = address[0].address || address[0].name;
}
var curAddress = province + ' ' + city + ' ' + district + ' ' + road + ' ' + address;
//road 加一条路
mapView._locationLabel.text(curAddress);
mapviewMod.set({
curAddress : curAddress
});
}
loadingMov.loadingFinish();
});
}, function(error) {
loadingMov.loadingFinish();
if( typeof (error) == 'string') {
mapView._locationLabel.text(error);
return;
}
switch(error.code) {
case error.TIMEOUT:
mapView._locationLabel.text('定位超时,请稍后重试!');
mapView.showMapTip('定位失败', '定位超时,请稍后重试!');
break;
case error.POSITION_UNAVAILABLE:
mapView._locationLabel.text('对不起,无法检测到您的位置!');
mapView.showMapTip('定位失败', '对不起,无法检测到您的位置!');
break;
case error.PERMISSION_DENIED:
mapView._locationLabel.text('请开启允许使用Geolocation功能!');
mapView.showMapTip('定位失败', '请开启允许使用Geolocation功能!');
break;
case error.UNKNOWN_ERROR:
mapView._locationLabel.text('发生未知错误!');
mapView.showMapTip('定位失败', '发生未知错误!');
break;
}
});
}
function init() {
// 获取用户当前位置
try {
// 调整地图高度
mapView.getElement().height(document.documentElement.clientHeight - topHeight);
//70 顶部banner条高度
//地图容器
var mapObjs = new AMap.Map('mapObj', {
center : new AMap.LngLat(116.397428, 39.90923),
level : 4 //options. mapView.model.initLevel
});
mapView.setMapObj(mapObjs);
mapObj = mapObjs;
//加载工具条插件
mapObj.plugin(["AMap.ToolBar"],function(){
//加载工具条
var tool = new AMap.ToolBar({
//初始化定义配置
//direction:true,//方向键盘
//ruler:false,//隐藏视野级别控制尺
offset:new AMap.Pixel(30,120)
// autoPosition:false
});
mapObj.addControl(tool);
});
//curInforWindow
} catch(e) {
App.onload();
console.dir(e);
mapView._locationLabel.text('发生未知错误!请检查网络并刷新页面');
mapView.showMapTip('地图初始化错误', '高德地图发生未知错误!请尝试重新刷新页面或检查网络');
}
AMap.event.addListener(mapObj,'click',function() {
if(curInforWindow){
curInforWindow.close();
curInforWindow = null;
}
});
setTimeout(function(){
getLocation();
},100)
App.onload();
}
init();
_.extend(MapShare,{//GuidanceMap
mapView : mapView,
detailView : detailView,
searchView : searchView,
configLan : configLan,
headFootUI : headFootUI,
clone : function(obj) {
var cloneClass = new Function();
cloneClass.prototype = obj;
return new cloneClass();
}
// topHeight : topHeight
// mapObj:mapObj,
// busInfo:{start:{name:'', x:0, y:0}, end: {}},
// city:'深圳',
// confirm: confirm,
// addSearchHistory: addSearchHistory,
// searchPageShow: searchPageShow,
// showOutletDetail:showOutletDetail,
// showMaintainDetail:showMaintainDetail
});
exports.MapShare = MapShare;
})(App);