<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    guidance

    ;(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);

    posted on 2014-04-22 09:47 koradji 閱讀(161) 評論(0)  編輯  收藏


    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    <2025年5月>
    27282930123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

    導航

    統計

    常用鏈接

    留言簿(2)

    隨筆分類

    隨筆檔案

    文章分類

    文章檔案

    收藏夾

    db2

    dos

    Groovy

    Hibernate

    java

    WAS

    web application

    搜索

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 亚洲三级中文字幕| 999国内精品永久免费视频| 亚洲小视频在线播放| 亚洲狠狠爱综合影院婷婷| 久久午夜免费视频| 久久这里只精品国产免费10| 美女扒开尿口给男人爽免费视频| 亚洲男女一区二区三区| 亚洲国产成人片在线观看无码 | 亚洲中文字幕第一页在线| 毛片大全免费观看| 91制片厂制作传媒免费版樱花| 国产高清视频免费在线观看| 亚洲AV无码专区在线厂| 亚洲狠狠成人综合网| 亚洲成人免费在线观看| 亚洲一区综合在线播放| 狠狠亚洲狠狠欧洲2019| 免费国产成人高清在线观看麻豆| 18禁超污无遮挡无码免费网站国产 | 日韩插啊免费视频在线观看 | 国产一级做a爱免费视频| 在人线av无码免费高潮喷水| 在线观看免费视频资源| 99精品在线免费观看| 国产无遮挡裸体免费视频在线观看 | 久久国产精品免费视频| 中文在线免费观看| 美女巨胸喷奶水视频www免费| 香蕉国产在线观看免费| 日本一区二区三区在线视频观看免费| 亚洲JIZZJIZZ妇女| 亚洲国产精华液2020| 亚洲gay片在线gv网站| 亚洲AV电影天堂男人的天堂| 亚洲欧美日韩自偷自拍| 亚洲AV无码专区在线观看成人 | 最近免费mv在线观看动漫| 中文永久免费观看网站| baoyu777永久免费视频| 国产精品99久久免费观看|