123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418 |
- define([
- 'html!templates/tools/toolCurrentArea',
- 'modDir/service/regionSearch',
- 'text!data/address_baike/db.json',
- 'css!styles/tools/toolCurrentArea'
- ],
- function(tplLayout, regionSearchF,addressBaikeDb) {
- /**
- * 模块状态,用于存储模块的状态 例如:收起,关闭
- * @type {Object}
- */
- var status = {
- initialized: false, //是否初始化
- modalStatus: false //界面是否弹出
- };
- /**
- * 模块数据 用于数据存储和外部调用
- * @type {Object}
- * 数据存放
- */
- var modValue = {
- currentAreaDataResult: {},
- currentCityInfo: null //当前区域json数据
- }
- /**
- * 初始化并订阅事件
- * @return {[type]} [description]
- */
- function init() {
- if (status.initialized === false) {
- setLayout();
- subscribe();
- bindEvent();
- getCurrentCity();
- hideModal();
- status.initialized = true;
- addressBaikeDb = JSON.parse(addressBaikeDb);
- } else {
- if (status.modalStatus) {
- hideModal();
- } else {
- showModal();
- }
- }
- };
- function setLayout(){
- $("#footer .tools-location").append(tplLayout);
- showModal();
- };
- /**
- * 设置地图到指定的区域
- * 支持url解析
- * @type {Function}
- * @param options {Object} {center:中心点,zoom:缩放比例}
- */
- function mapToPoint(options) {
- if (map23DData.display.map2D) {
- map2DViewer.setView({
- center: options.center,
- zoom: options.zoom
- });
- } else if (map23DData.display.map3D) {
- map3DViewer.setView({
- center: options.center,
- zoom: options.zoom
- });
- }
- setTimeout(function(){
- getCurrentCity();
- },500);
- };
- /**
- * 显示城市跳转模态窗口
- * @type {Function}
- */
- function showModal() {
- $("#footer .Arealinkimg").addClass('downIcon');
- // $($("#provinceModal")).css({ left: '10px' });
- // $($("#provinceModal")).css({ bottom:'40px' });
- $($("#provinceModal")).show();
- if(map23DData.display.map2D){
- $("#provinceModal .popup_html").removeClass('TD');
- }else{
- $("#provinceModal .popup_html").addClass('TD');
- }
- $("#cityPlaceList").mCustomScrollbar({
- scrollInertia: 1000
- });
- $("#cityPlaceList").mCustomScrollbar('update');
- status.modalStatus = true;
- };
- /**
- * 隐藏城市跳转模态窗口
- * @type {Function}
- */
- function hideModal() {
- $("#footer .Arealinkimg").removeClass('downIcon');
- $($("#provinceModal")).hide();
- status.modalStatus = false;
- };
- /**
- * 界面布局重置
- * @type {Function}
- */
- function layoutResize() {
- $("cityPlaceList").mCustomScrollbar('update');
- };
- /**
- * 获取当前城市信息
- * @type {Function}
- * @returns {*}
- */
- function getCurrentCity() {
- var center = map23DData.view.center;
- if(map23DData.display.map2D){
- center = map2DViewer.map.getCenter();
- }
- var zoom = map23DData.view.zoom;
- getPointCity(center, zoom);
- };
- /**
- * 在ONEMAP.M.user中记录当前城市信息
- * @type {Function}
- * @param data {Object} 城市名称,中心点,bounds范围
- * @private
- */
- function setONEMAPCityInfo(data) {
- ONEMAP.D.cityInfo.name = data.name.text;
- ONEMAP.D.cityInfo.center = data.center;
- ONEMAP.D.cityInfo.pac = data.code;
- ONEMAP.D.cityInfo.zoom = data.zoom;
- };
- /**
- * 获取目标城市信息数据
- * @type {Function}
- * @param center {Object} 中心点
- * @param zoom {Number} 缩放比例,不同比例返回的 区域等级不一样
- * @returns {*}
- * @private
- */
- function getPointCity(center, zoom) {
- var regionSearch = new regionSearchF;
- regionSearch.getRegionInfo({ latLng: [center.lat, center.lng], zoom: zoom }, function(data) {
- modValue.currentAreaDataResult = data.data;
- updateCurrentAreaPanel(data.data);
- //updateCurrentAreaWheater(data.data);
- });
- };
- /**
- * 更新天气
- */
- function updateCurrentAreaWheater(){
- var cityname = modValue.curAreaName;
- // 天气搜索结果
- meteo.c.http.httpFunction(meteo.c.http.station, cityname, null, function (json) {
- if(json.length>0){
- showList(json);
- }else{
- ONEMAP.C.publisher.publish({ type: 'error', message: '无此区域天气数据' }, 'noteBar::add');
- }
- })
- };
- function showList(json){
- // console.log(json)
- /*meteo.c.popup.showPopup("" + e.currentTarget.id.split("-")[2], json[key].cname, 0,
- '2017-12-25 20:00:00', '2017-12-25 08:00:00');*/
- }
- /**
- * 更新 当前城市信息面板 由地图拖动来驱动
- * @type {Function}
- * @param data {Object}
- * @returns {*}
- * @private
- */
- function updateCurrentAreaPanel(data) {
- if(!data){
- return false;
- }
- var curAreaName = '';
- var curArea = $('#provinceModal .modal-header h3');
- curArea.empty();
- var nextArea = $('#CurCityInfo');
- nextArea.empty();
- if (data.hasOwnProperty('level') && data.level.length > 0) {
- var i = 0;
- var l = data.level.length;
- var ABBtn = $('<span class="addressbaike hide"></span>');
- for (i; i < l; i++) {
- if (i !== (l - 1)) {
- var item = $('<a href="javascript:void(0)">' + data.level[i].name.text + '</a> > ');
- item.bind("click", { d: data.level[i] }, function(event) {
- mapToPoint({
- center: [event.data.d.center.lat, event.data.d.center.lon],
- zoom: event.data.d.zoom + 3,
- name: event.data.d.name.text
- });
- setONEMAPCityInfo(event.data.d);
- });
- } else if (i === (l - 1)) {
- var item = $('<strong>' + data.level[i].name.text + '</strong>');
- modValue.curAreaName = data.level[i].name.text;
- curAreaName = data.level[i].name.text;
- if(addressBaikeDb[(addPreZero(data.level[i].code))]){
- // ABBtn = $('<a class="addressbaike" title="'+curAreaName+'" bid="'+(addPreZero(data.level[i].code))+'">地名百科</a>');
- // ABBtn.bind('click',function(){
- // var title = $(this).attr("title");
- // var bid = $(this).attr("bid");
- // require(['modDir/tools/toolAddressBaike'],function(toolAddressBaike){
- // toolAddressBaike.init({
- // title:title,
- // bid:bid
- // });
- // });
- // })
- }
- //更新ONEMAP.D.cityInfo
- setONEMAPCityInfo(data.level[i]);
- }
- //设置当前 城市信息
- if (data.level[i].category === 'city') {
- modValue.currentCityInfo = data.level[i];
- }
- item.appendTo(curArea);
- }
- $("#curLocationArea").empty().text(curAreaName);
- $(".addressbaike").remove();
- ABBtn.insertAfter($('.tools-location'));
- } else {
- curArea.empty().html('<strong>全球</strong>');
- }
- if (data.hasOwnProperty('next_level') && data.next_level.length > 0) {
- var nextLevelAry = sortBy(data.next_level, 'code');
- for (var i = 0, l = nextLevelAry.length; i < l; i++) {
- var item = $('<a href="javascript:void(0)">' + nextLevelAry[i].name.text + '</a>');
- item.bind("click", { d: nextLevelAry[i] }, function(event) {
- mapToPoint({
- center: [event.data.d.center.lat, event.data.d.center.lon],
- zoom: event.data.d.zoom + 3,
- name: event.data.d.name.text
- });
- setONEMAPCityInfo(event.data.d);
- });
- item.appendTo(nextArea);
- }
- }
- };
- function addPreZero(num) {
- var t = (num + '').length,
- s = '';
- for (var i = 0; i < 11 - t; i++) {
- s += '0';
- }
- return num+s;
- }
- function sortBy(arr, prop, desc) {
- var props = [],
- ret = [],
- i = 0,
- len = arr.length;
- if (typeof prop == 'string') {
- for (; i < len; i++) {
- var oI = arr[i];
- (props[i] = new String(oI && oI[prop] || ''))._obj = oI;
- }
- }
- props.sort();
- for (i = 0; i < len; i++) {
- ret[i] = props[i]._obj;
- }
- if (desc) {
- ret.reverse();
- }
- return ret;
- };
- function popup_html_css(options){
- if(options == '2d'){
- $("#provinceModal .popup_html").removeClass('TD');
- }else if(options == '3d'){
- $("#provinceModal .popup_html").addClass('TD');
- }
- }
- /**
- * 注册监听
- * @type {Function}
- */
- function subscribe() {
- ONEMAP.C.publisher.subscribe(getCurrentCity, 'mapChange23D');
- ONEMAP.C.publisher.subscribe(popup_html_css, 'change23D');
- };
- /**
- * 取消监听
- * @type {Function}
- */
- function unSubscribe() {};
- /**
- * 监听数据推送
- * @type {Function}
- */
- function publish() {};
- /**
- * 点击事件绑定
- */
- function bindEvent() {
- $("#provinceModal .modal-header .close").bind("click", function() {
- hideModal();
- });
- $("#footer .location_wheater").bind('click',function(){
- updateCurrentAreaWheater();
- })
- $("#provinceModal .table a").bind("click", function() {
- var cityname = $(this).text().replace(':', '');
- require(["vendorDir/data/cityData"], function(cityData) {
- $.each(cityData, function(index, value) {
- if (value.n.indexOf(cityname) >= 0) {
- mapToPoint({ center: L.latLng(cityData[index].latLng[0], cityData[index].latLng[1]), zoom: 10 });
- return false;
- }
- });
- });
- });
- $("#provinceModal #CityHotCity a, #provinceModal #globalCity a").bind("click", function() {
- var cityname = $(this).text().replace(':', '');
- require(["vendorDir/data/cityData"], function(cityData) {
- $.each(cityData, function(index, value) {
- if (value.n.indexOf(cityname) >= 0) {
- mapToPoint({ center: L.latLng(cityData[index].latLng[0], cityData[index].latLng[1]), zoom: 10 });
- return false;
- }
- });
- });
- });
- $("#provinceModal #cityLetterList a").click(function() {
- if (L.Browser.ie6) {
- return false;
- }
- $("#provinceModal #cityPlaceList").mCustomScrollbar("scrollTo", $(this).data("role"));
- });
- //搜索
- $('#provinceModalCitySearch .input-small').bind('focus', function(e) {
- $(this).val('');
- });
- $('#provinceModalCitySearch .input-small').bind('keyup', function(e) {
- $('#provinceModalCitySearchResult').empty();
- var cityname = $(this).val().replace(' ', '');
- if (cityname === '') {
- $('#provinceModalCitySearchResult').css({ display: 'none' });
- return false;
- }
- require(["vendorDir/data/cityData"], function(cityData) {
- var count = 0;
- $.each(cityData, function(index, value) {
- if (value.n.indexOf(cityname) >= 0) {
- var item = $('<li><a href="javascript:void(0)">' + cityData[index].n + '</a></li>').appendTo($('#provinceModalCitySearchResult'));
- item.on("click", { data: value }, function(e) {
- mapToPoint({ center: L.latLng(e.data.data.latLng[0], e.data.data.latLng[1]), zoom: 10 });
- $('#provinceModalCitySearchResult').css({ display: 'none' });
- });
- count++
- if (count > 6) {
- return false;
- }
- }
- });
- if (count == 0) {
- $('<li>请输入正确的城市名</li>').appendTo($('#provinceModalCitySearchResult'))
- }
- });
- $('#provinceModalCitySearchResult').css({ display: 'block' });
- });
- $('#provinceModalCitySearch .input-small').bind('keydown', function(e) {
- if (e.keyCode === 13) {
- $('#provinceModalCitySearchResult').empty();
- var cityname = $(this).val().replace(' ', '');
- if (cityname === '') {
- $('#provinceModalCitySearchResult').css({ display: 'none' });
- return false;
- }
- require(["vendorDir/data/cityData"], function(cityData) {
- var count = 0;
- $.each(cityData, function(index, value) {
- if (value.n.indexOf(cityname) >= 0) {
- var item = $('<li><a href="javascript:void(0)">' + cityData[index].n + '</a></li>').appendTo($('#provinceModalCitySearchResult'));
- item.on("click", { data: value }, function(e) {
- mapToPoint({ center: L.latLng(e.data.data.latLng[0], e.data.data.latLng[1]), zoom: 10 });
- $('#provinceModalCitySearchResult').css({ display: 'none' });
- });
- count++
- if (count > 6) {
- return false;
- }
- }
- });
- if (count == 0) {
- $('<li>请输入正确的城市名</li>').appendTo($('#provinceModalCitySearchResult'))
- }
- });
- $('#provinceModalCitySearchResult').css({ display: 'block' });
- }
- });
- };
- return ONEMAP.M.CurrentArea = {
- init:init,
- showModal:showModal,
- hideModal:hideModal
- };
- })
|