Files
youfang-app/fangija-zsyf/js/district/district-map.js
T
2018-04-09 18:42:07 +08:00

1141 lines
42 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
var that;
var mapConfig = {
/* 初始化入口*/
init: function () {
that = this;
that.lat = lat;
that.lng = lng;
that.map = new BMap.Map('districtMap');
var point = new BMap.Point(that.lng, that.lat);
that.map.centerAndZoom(point, 14);
// 编写自定义函数,创建标注
var marker = new BMap.Marker(point);
function CountOverlay(city, text){
this._city = city;
this._point = point;
this._text = text;
}
CountOverlay.prototype = new BMap.Overlay();
CountOverlay.prototype.initialize = function(map){
this._map = that.map;
var div = this._div = document.createElement("div");
div.style.position = "absolute";
div.style.zIndex = BMap.Overlay.getZIndex(this._point.lat);
div.style.backgroundColor = "grey";
div.style.border = "1px solid grey";
div.style.color = "white";
div.style.height = "25px";
div.style.padding = "2px";
div.style.lineHeight = "18px";
div.style.whiteSpace = "nowrap";
div.style.MozUserSelect = "none";
div.style.fontSize = "12px"
div.style.cursor = "pointer"
var span = this._span = document.createElement("span");
span.style.lineHeight = "inherit";
span.style.minWidth = "25px";
span.style.textAlign = "center";
div.appendChild(span);
span.appendChild(document.createTextNode(this._text));
var arrow = this._arrow = document.createElement("div");
// arrow.style.background = "url(http://map.baidu.com/fwmap/upload/r/map/fwmap/static/house/images/label.png) no-repeat";
arrow.style.position = "absolute";
arrow.style.width = "11px";
arrow.style.height = "10px";
arrow.style.top = "24px";
arrow.style.left = "28px";
arrow.style.overflow = "hidden";
div.appendChild(arrow);
/* div.addEventListener('click', function(e){
that.datas.zoom = that.datas.zoomThreshold + 2;
mp.centerAndZoom(city, that.datas.zoom)
}) */
that.map.getPanes().labelPane.appendChild(div);
return div;
}
CountOverlay.prototype.draw = function(){
var map = this._map;
var pixel = map.pointToOverlayPixel(this._point);
this._div.style.left = pixel.x - parseInt(this._arrow.style.left) - 13 + "px";
this._div.style.top = pixel.y - 60 + "px";
}
that.map.addOverlay(new CountOverlay(city, name));
that.map.addOverlay(marker);
that.map.enableScrollWheelZoom(true); // 开启鼠标滚轮缩放
that.map.citycenter = new BMap.Point(that.lng, that.lat);
/* 打开银行、餐饮等tab大类*/
$('.bar,#aroundLink').on('click', 'a', function () {
var $this = $(this);
//$this.addClass('current').siblings().removeClass('current');
var id = $this.attr('id');
that.hidden_all_mark()
that.openTypeWrap(id);
});
that.openTypeWrap('bus');
},
/* 计算两点间距离*/
getShortDistance: function (lon1, lat1, lon2, lat2) {
// PI
var DEF_PI = 3.14159265359;
// 2*PI
var DEF_2PI = 6.28318530712;
// PI/180.0
var DEF_PI180 = 0.01745329252;
// radius of earth
var DEF_R = 6370693.5;
var ew1, ns1, ew2, ns2, dx, dy, dew, distance;
// 角度转换为弧度
ew1 = lon1 * DEF_PI180;
ns1 = lat1 * DEF_PI180;
ew2 = lon2 * DEF_PI180;
ns2 = lat2 * DEF_PI180;
// 经度差
dew = ew1 - ew2;
// 若跨东经和西经180 度,进行调整
if (dew > DEF_PI) {
dew = DEF_2PI - dew;
} else if (dew < -DEF_PI) {
dew = DEF_2PI + dew;
}
// 东西方向长度(在纬度圈上的投影长度)
dx = DEF_R * Math.cos(ns1) * dew;
// 南北方向长度(在经度圈上的投影长度)
dy = DEF_R * (ns1 - ns2);
// 勾股定理求斜边长
distance = Math.sqrt(dx * dx + dy * dy);
return parseInt(distance);
},
/* 获取附近楼盘创建标记*/
// 设置条数:type大分类
setCount: function (type) {
var that = this;
var list = '#' + type + '_list';
var liCount = $(list).find('li[id]').length;;
var countDom = $('#' + type + 'Count'), text = '', split = '、', unit = '个';
// 楼盘
if (type === 'hs') {
// 医院
text += liCount ? liCount + unit + that.have_arr_new[type] + split : '';
/*for (var item in that.house_type) {
if (that.house_type.hasOwnProperty(item)) {
liCount = $('#' + item + '_list').find('li[id]').length;
text += liCount ? liCount + unit + that.house_type[item] + split : '';
}
}*/
} else if (that.house_near_merge[type]) {
// 交通 教育
for (var i = 0; i < that.house_near_merge[type].length; i++) {
if (that.house_near_merge[type][i]) {
var item_traffic = that.house_near_merge[type][i];
if (type === 'business') {
unit = '处';
} else if (type === 'school') {
unit = '所';
} else if (type === 'school') {
if (item_traffic === 'subway') {
unit = '条';
} else {
unit = '个';
}
}
liCount = $('#' + item_traffic + '_list').find('li[id]').length;
text += liCount ? liCount + unit + that.have_arr_new[item_traffic] + split : '';
}
}
} else if (type === 'hos') {
// 医院
text += liCount ? liCount + unit + that.have_arr_new[type] + split : '';
} else if (type === 'other') {
text = liCount + unit;
}
if (text) {
// 除去、
if (text.lastIndexOf(split) === text.length - 1) {
text = text.substr(0, text.length - 1);
}
countDom.text(text);
//隐藏无结果提示语
$('#' + type + '_noResult').hide();
} else {
//显示无结果提示
$('#' + type + '_noResult').show();
}
},
/* 按距离希尔排序*/
shellSort: function (arr) {
for (var step = arr.length >> 1; step > 0; step >>= 1) {
for (var i = 0; i < step; ++i) {
for (var j = i + step; j < arr.length; j += step) {
var k = j, value = arr[j].distance, tmp = arr[j];
while (k >= step && arr[k - step].distance > value) {
arr[k] = arr[k - step];
k -= step;
}
arr[k] = tmp;
}
}
}
return arr;
},
/* 添加标注:单一图标*/
// tag为true表示楼盘需要清除;n为索引;type为大分类
addMarker_s: function (info, tag, n, isShow) {
var that = this;
var latLng = new BMap.Point(info.x, info.y);
// var textIndent = (n + '').length > 1 ? ' style="text-indent:2px" ' : '';
var ltext = '<div class="mark-icon-box">';
ltext += ' <a class="map-icon mark-icon bus">' + n + '</a>';
ltext += '<div class="mark-tip" style="display: none">';
ltext += '<div class="title1"><span>' + info.title + '</span><b>' + info.distance + '米</b></div>';
ltext += '<i class="map-icon icon"></i>';
ltext += '</div></div>';
var marker = new BMapLib.RichMarker(ltext, latLng, {anchor: new BMap.Size(0, 0)});
tag && that.toDelterMarkers.push(marker);
marker.provalue = info;
that.openTip[info.uid] = that.opentip(marker);
that.map.addOverlay(marker);
if(isShow){
marker.hide();
}
return marker;
},
/* 鼠标划到描点事件*/
focusmarker_b: function (marker) {
var info = marker.provalue;
var focusInfoWinFun = function () {
var container = $(marker._container), mapDiv = container.find('.mark-icon-box');
if (mapDiv.length) {
marker.setTop && marker.setTop(true);
mapDiv.find('.mark-icon').addClass('mark-icon-h').end().find('.mark-tip').show();
// 恢复置顶
container.css('zIndex', Math.abs(container.css('zIndex')));
var list = $('#list' + info.uid);
list.find('a').css('background', '#e8f4ff');
}
};
marker.addEventListener('mouseover', focusInfoWinFun);
return focusInfoWinFun;
},
/* 鼠标划过描点事件*/
blurmarker_b: function (marker) {
var that = this;
var info = marker.provalue;
var blurInfoWinFun = function () {
if (that.isclick != info.uid) {
var container = $(marker._container), mapDiv = container.find('.mark-icon-box');
if (mapDiv.length) {
mapDiv.find('.mark-icon').removeClass('mark-icon-h').end().find('.mark-tip').hide();
// 恢复置顶
container.css('zIndex', -Math.abs(container.css('zIndex')));
var list = $('#list' + info.uid);
list.find('a').css('background', '#fff');
}
}
};
marker.addEventListener('mouseout', blurInfoWinFun);
return blurInfoWinFun;
},
/* maibuilding的hover*/
hoverMarker: function (marker, flg) {
var that = this;
if (!marker._div) {
return;
}
var cName = marker._div.className;
var tip_price = $('#tip_price');
if (flg) {
if (cName.indexOf('qp') > -1) {
marker._div.className = 'qp02';
}
marker._div.parentNode.style.zIndex = 1;
if (tip_price.length > 0) {
tip_price.css('display', 'inline');
}
} else {
if (that.isclick != marker.provalue.newCode) {
marker._div.parentNode.style.zIndex = marker._zindex;
if (cName.indexOf('qp') < 0) {
return;
}
if (tip_price) {
tip_price.css('display', 'none');
}
var lclass = 'qp01';
var sTc = {0: '04', 1: '01', 2: '05', 3: '03', 4: '01'};
if ('undefined' != typeof(marker.provalue.saling) && 'undefined' != typeof(sTc[marker.provalue.saling])) {
lclass = 'qp' + sTc[marker.provalue.saling];
}
marker._div.className = lclass;
}
}
},
/* 关闭详情窗口*/
closeTip: function () {
var that = this;
$('#maptip').css('visibility', 'hidden');
var tip_price = $('#tip_price');
if (tip_price) {
tip_price.css('display', 'none');
}
},
/* 弹出详情窗口****/
opentip: function (marker) {
var that = this;
var map = that.map;
var maptipDom = $('#maptip');
if (!maptipDom) {
return;
}
var opentheTip = function () {
var info = marker.provalue;
if (!info) {
return;
}
info.x = info.x || info.baidu_coord_x || info.mapx;
info.y = info.y || info.baidu_coord_y || info.mapy;
if (that.isclick && that.isclick == info.uid) {
that.closeTip();
return;
}
var point0 = new BMap.Point(marker._position.lng, marker._position.lat);
that.map.centerAndZoom(point0, 14);
};
marker.addEventListener('click', opentheTip);
return opentheTip;
},
panMap: function () {
var that = this;
that.map.setViewport(that.markerBounds);
},
/* 打开餐饮、银行大类信息*/
openTypeWrap: function (type) {
var that = this;
that.createPoints_new(type);
},
/* 重置所有标注-*/
reset_all_mark: function (fmaker) {
var that = this;
if ('undefined' != typeof that.map && 'undefined' != typeof that.house_near_p) {
// 设置背景为初始白色
$('li[id^=list] a').css('background', '#fff');
// 去除描点悬浮蓝色并且隐藏所有悬浮框
var map = $('#mapObj');
map.find('.mark-icon').removeClass('mark-icon-h').end().find('.mark-tip').hide();
if (fmaker && !fmaker._div) {
var info = fmaker.provalue;
var container = $(fmaker._container);
container.css('zIndex', Math.abs(container.css('zIndex')));
var listNew = $('#list' + info.uid);
listNew.find('a').css('background', '#e8f4ff');
}
}
},
/* 隐藏所有标注*/
hidden_all_mark: function () {
var that = this;
if ('undefined' != typeof that.map && 'undefined' != typeof that.house_near_p) {
for (var key in that.house_near_p) {
if (that.house_near_p[key].length < 1) {
return;
}
for (var j = 0; j < that.house_near_p[key].length; j++) {
var point = that.house_near_p[key][j];
point && point.hide();
}
}
}
},
/* 只传入类型的大类标注*/
hideOtherPoints: function (type) {
var that = this;
if ('undefined' == typeof that.map || 'undefined' == typeof that.house_near_p || null == type) {
return;
}
for (var key in that.house_near_p) {
if (that.house_near_p[key].length > 0) {
for (var j = 0; j < that.house_near_p[key].length; j++) {
var point = that.house_near_p[key][j];
if(point){
if(key == type){
point.show();
}else{
point.hide()
}
}
}
}
}
},
/* 显示周边楼盘标注*/
createPoints_house: function () {
var that = this;
that.panTo(that.map.citycenter);
that.hidden_all_mark();
if (that.have_arr['hs'] == 1 && 'undefined' != typeof that.map && 'undefined' != typeof that.house_near_p) {
for (var key in that.house_near_p) {
if ('hs' != key) {
continue;
}
for (var j = 0; j < that.house_near_p[key].length; j++) {
var point = that.house_near_p[key][j];
point && point.show();
}
break;
}
} else {
//that.getNearHouse();
}
},
/**
* 创建小分类下的标注:若已经创建则显示已经创建的
* @param type 分类
* @returns null
*/
createPoints_new: function (type) {
if (null == type) {
return;
}
type = type.replace(/\s+/g, '');
var that = this;
that.panTo(that.map.citycenter);
that.hideOtherPoints(type);
// 若已经存在
if (that.have_arr[type] == 1) {
//that.hideOtherPoints(type);
/* 刷新地图标注*/
// that.hideOtherPoints(type);
/* 显示该分类下所有的内容*/
/*var typeList = $('#' + type + '_list');
// 记录滚动位置
that.topScroll = typeList.parent().scrollTop();
typeList.find('li').show();
typeList.show().siblings().hide();*/
/* 隐藏更多按钮*/
$('.mscoputup').show();
$('.mscomore').hide();
} else {
/*if (type == 'hs') {
//that.getNearHouse();
} else {
that.getnear_s(that.have_arr_new[type], that.maxMarker_count, that.view_count, that.limit, that.maxMarker_count);
}*/
that.getnear_s(type,that.maxMarker_count, that.view_count, that.limit, that.maxMarker_count);
}
},
panTo: function(e, a) {
e && a && that.map.panTo(new BMap.Point(a, e))
},
/**
* 创建大分类下的标注:若已经创建则显示已经创建的
* @param key 大分类
* @returns null
*/
createPoints_merge: function (key) {
var that = this;
that.panTo(that.map.citycenter);
/* 隐藏地图上所有标注*/
that.hidden_all_mark();
var mergeArr = that.house_near_merge[key];
/* 显示标注*/
var flag = false, i, j = 0, l;
for (i = 0, l = mergeArr.length; i < l; i++) {
if (that.have_arr[mergeArr[i]] == 1) {
flag = true;
break;
}
}
/* 显示全部*/
if (flag) {
if ('undefined' != typeof that.map && 'undefined' != typeof that.house_near_p) {
// 显示当前大分类下所有小分类列表
var typeList = $('#' + mergeArr[0] + '_list');
typeList.show().siblings().show();
/* 显示更多按钮 隐藏收起按钮*/
$('.mscoputup').hide();
$('.mscomore').show();
for (var k in that.house_near_p) {
if (that.in_array(k, mergeArr)) {
for (j = 0; j < that.house_near_p[k].length; j++) {
var point = that.house_near_p[k][j];
point && (j < that.view_count ? point.show() : point.hide());
}
}
}
for (i = 0, l = mergeArr.length; i < l; i++) {
var objs = $('#' + mergeArr[i] + '_list').find('li');
for (j = that.view_count; j < that.maxMarker_count; j++) {
if (null == objs[j]) {
break;
}
$(objs[j]).hide();
}
}
// 滚到展开位置
typeList.parent().scrollTop(that.topScroll || 0);
}
} else {
that.init_search_merge(key);
}
},
init_search_merge: function (key) {
var that = this;
var mergeArr = that.house_near_merge[key];
for (var i = 0, l = mergeArr.length; i < l; i++) {
that.getnear_s(mergeArr[i], that.maxMarker_count, that.view_count, that.limit, that.maxMarker_count, key);
}
},
/**
* 获取周围信息
* @param type 小分类
* @param count 需要搜索的最大个数
* @param view_count 非展开状态下显示个数
* @param limit 搜索距离(m)
* @param limit_count 页面上展示最大个数
* @param parentType 大分类
* @returns null
*/
getnear_s: function (type, count, view_count, limit, limit_count, parentType) {
var that = this;
/*if (cityy == '' || cityx == '' || null == type) {
return;
}*/
var searchname = that.have_arr_new[type];
var onLocalSearch = function (resData) {
// 娱乐由于合在了一起所以单独处理
//var isFun = that.in_array(type, that.house_near_merge['fun']);
/* 判断状态是否正确*/
if (localSearch.getStatus() == BMAP_STATUS_SUCCESS) {
var resultArr = [];
that.focusInfoWinFuns[type] = [];
that.blurInfoWinFuns[type] = [];
var uidarr = [];
var points = []
/* 处理百度返回信息*/
for (var i = 0; i < resData.getCurrentNumPois(); i++) {
var info = resData.getPoi(i);
if(info){
/* 过滤地铁中的地铁口*/
info['address'] = info['address'] ? info['address'] : '';
if ('subway' == type && (!that.array_in_array(that.type_tags[type], info.tags) || info['address'].indexOf('线') < 0)) {
continue;
}
/* 计算距离*/
info.distance = that.getShortDistance(that.map.citycenter.lng, that.map.citycenter.lat, info.point.lng, info.point.lat);
uidarr.push(info.uid);
resultArr.push(info);
points.push(new BMap.Point(info.point.lng,info.point.lat))
}
}
resData._pois = that.shellSort(resultArr);
that.have_arr[type] = 1;
// 所有周围娱乐数据加载完毕
var allFunIsFinished = that.have_arr['ktv'] && that.have_arr['bar'] && that.have_arr['cinema']
&& that.have_arr['beauty'] && that.have_arr['cafe'];
// 若是娱乐将type设为fun
/*if (isFun) {
type = 'fun';
searchname = '娱乐';
that.focusInfoWinFuns[type] = [];
that.blurInfoWinFuns[type] = [];
that.have_arr[type] = 1;
!that.funData && (that.funData = []);
that.funData = that.funData.concat(resData._pois);
// 若娱乐都检索完毕则可以画点
if (allFunIsFinished) {
resData._pois = that.shellSort(that.funData);
} else {
return;
}
}*/
that.house_near_p[type] = [];
/*if (!isFun || isFun && allFunIsFinished) {
that.getListAndMarker(resData._pois, limit_count, view_count, type, parentType, searchname);
}*/
that.getListAndMarker(resData._pois, limit_count, view_count, type, parentType, searchname);
that.map.setViewport(points);
} else {
// 若没搜索成功娱乐也加标识位,因为娱乐是所有加载完后再描点
/*if (isFun) {
that.have_arr[type] = 1;
if (that.have_arr['ktv'] && that.have_arr['bar'] && that.have_arr['cinema']
&& that.have_arr['beauty'] && that.have_arr['cafe']) {
that.getListAndMarker(that.funData, limit_count, view_count, type, parentType, '娱乐');
}
}*/
}
};
var localSearch = new BMap.LocalSearch(new BMap.Point(that.lng, that.lat), {onSearchComplete: onLocalSearch});
localSearch.setPageCapacity(count);
localSearch.searchNearby(searchname, that.map.citycenter, limit);
},
/**
* 拼接列表并描点
* @param rsData 描点数组
* @param limit_count 页面上展示最大个数
* @param view_count 非展开状态下显示个数
* @param type 小分类
* @param mergeType 大分类
* @param searchName 小分类列表头
* @param isNotVisible 是否需要隐藏
* @returns null
*/
getListAndMarker: function (resData, limit_count, view_count, type, mergeType, searchName, isNotVisible) {
var that = this;
var s = [], l = resData.length;
if (l > 0) {
s.push('<div class="list_title">' + searchName + '</div><ul class="list_content">');
for (var i = 0; i < l && i < limit_count; i++) {
var result = resData[i];
var selected = view_count && (i > view_count - 1) ? 'none' : '';
if (mergeType) {
s.push('<li id="list' + result.uid + '" style="display :' + selected + '">');
} else {
s.push('<li id="list' + result.uid + '">');
}
s.push('<a href="javascript:void(0)" title="' + result.title + '" data-MyData="' + type + ',' + result.uid + '" >');
//var textIndent = i + 1 > 9 ? ' style="text-indent:2px" ' : '';
s.push('<i>' + (i + 1) + '</i><p>' + that.cut_str(result.title, 12)+ '</p>');
if (result.distance) {
s.push('<small>' + result.distance + '米</small>');
}
s.push('</a></li>');
result.maptype = type;
// 删除other类型的描点
var tag = type === 'other';
if(that.house_near_merge[mergeType] && i>4){
var marker = that.addMarker_s(that.orgSearchInfo(result), tag, i + 1,true);
}else{
var marker = that.addMarker_s(that.orgSearchInfo(result), tag, i + 1,false);
}
that.house_near_p[type].push(marker);
// 搜索周围需要显示
/*if (!isNotVisible) {
mergeType ? view_count && i > view_count && that.house_near_p[type][i].hide() : that.house_near_p[type][i].hide();
}*/
that.focusInfoWinFuns[type][result.uid] = that.focusmarker_b(marker, i);
that.blurInfoWinFuns[type][result.uid] = that.blurmarker_b(marker, i);
}
if (mergeType && l > view_count) {
s.push('<div class="mscother"><span class="mscomore"><a style="color: #01a1ff;" data-More="' + type);
s.push('" href="javascript:void(0)" >更多<em></em></a></span>');
s.push('<span class="mscoputup" style="display:none;">');
s.push('<a style="color: #01a1ff;" href="javascript:void(0)" data-Shrink="' + mergeType + '" >收起</a>');
s.push('</span>');
s.push('</div>');
}
s.push('</ul>');
var domList = $('#' + type + '_list');
domList.html(s.join(''));
/* 注册多个事件*/
that.addEventsListener(domList);
that.setCount(mergeType || type);
}
},
/* 添加多个事件 提出来了*/
addEventsListener: function (dom) {
var that = this;
if (!dom) {
return;
}
dom.on('mouseover mouseout click', 'a', function (e) {
var $this = $(this), dataS = $this.attr('data-mydata'), dataMore = $this.attr('data-More'), dataShrink = $this.attr('data-Shrink');
if (!dataS && !dataMore && !dataShrink) {
return;
}
var data = dataS ? dataS.split(',') : undefined;
switch (e.type) {
case 'click':
/* 更多和收起按钮的动作*/
if (dataMore) {
that.createPoints_new(dataMore);
break;
}
if (dataShrink) {
that.createPoints_merge(dataShrink);
break;
}
that.openTip[data[1]]();
break;
case 'mouseover':
data && that.focusInfoWinFuns[data[0]][data[1]]();
break;
case 'mouseout':
data && that.blurInfoWinFuns[data[0]][data[1]]();
break;
}
});
},
/* 获取周围餐馆、银行、医院、公交车***/
searchNearby: function (x, y, keyword, title) {
var that = this;
if (!keyword) {
return;
}
var onLocalSearch = function (resData) {
// 判断状态是否正确
if (local.getStatus() == BMAP_STATUS_SUCCESS) {
var resultArr = [];
var type = 'other';
that.house_near_p[type] = [];
that.focusInfoWinFuns[type] = [];
that.blurInfoWinFuns[type] = [];
/* 处理百度返回信息*/
for (var i = 0; i < resData.getCurrentNumPois(); i++) {
var info = resData.getPoi(i);
/* 计算距离*/
info.distance = that.getShortDistance(that.map.citycenter.lng, that.map.citycenter.lat, info.point.lng, info.point.lat);
resultArr.push(info);
}
resData._pois = that.shellSort(resultArr);
//
that.getListAndMarker(resData._pois, that.maxMarker_count, null, type, null, title + '周边' + keyword, true);
$('.myWrap').hide();
$('#' + type + '_wrap').show();
}
};
var local = new BMap.LocalSearch(that.map._map, {
onSearchComplete: onLocalSearch
});
local.setPageCapacity(20);
local.searchNearby(keyword, new BMap.Point(x, y), that.limit);
that.hidden_all_mark();
that.removeOtherOverlays();
},
cut_str: function (str, len) {
var char_length = 0;
for (var i = 0; i < str.length; i++) {
var son_str = str.charAt(i);
encodeURI(son_str).length > 2 ? char_length += 1 : char_length += 0.5;
if (char_length >= len) {
var sub_len = char_length == len ? i + 1 : i;
return str.substr(0, sub_len);
}
}
return str;
},
drawMarkers: function () {
var that = this;
for (var i = 0; i < that.metaMarkers.length; i++) {
var proValue = that.metaMarkers[i];
that.markerBounds.extend(that.createMarker(proValue));
}
},
createMarker: function (info) {
var that = this;
that.this_code = info.newCode;
var latLng = new BMap.Point(info.baidu_coord_x || info.mapx, info.baidu_coord_y || info.mapy);
var lclass = 'labeledMarkerStyle3';
var sTc = {0: '2', 2: '4', 3: '1'};
if ('undefined' != typeof(info.saling) && 'undefined' != typeof(sTc[info.saling])) {
lclass = 'labeledMarkerStyle' + sTc[info.saling];
}
var ltext, opts;
if ('hs' != that.iType && info.maplogo != '') {
lclass = 'lpmctd';
ltext = '<div class="' + lclass + '" id="tip' + info.newCode + '"><div class="lpmctdpic"><img style="width:100px;" src="' + info.maplogo;
ltext += '" alt="" /></div></div>';
opts = {anchor: new BMap.Size(-50, -47)};
} else {
lclass = 'qp01';
sTc = {0: '04', 1: '01', 2: '05', 3: '03', 4: '01'};
if ('undefined' != typeof(info.saling) && 'undefined' != typeof(sTc[info.saling])) {
lclass = 'qp' + sTc[info.saling];
}
ltext = '<div class="' + lclass + '" id="tip' + info.newCode + '"><div class="s1"><em>' + info.title;
ltext += '<span style="display: none;" id="tip_price">|' + info.price_type + info.price_num + info.price_unit + '</span></em></div></div>';
opts = {anchor: new BMap.Size(-5, -38)};
}
var marker = new BMapLib.RichMarker(ltext, latLng, opts);
marker.provalue = that.orgInfo(info);
marker.addEventListener('mouseover', function () {
that.hoverMarker(marker, true);
});
marker.addEventListener('mouseout', function () {
that.hoverMarker(marker, false);
});
that.opentip(marker);
that.centerMarker = marker;
that.map.addMarker(marker);
marker._div = $('#tip' + info.newCode)[0];
marker._zindex = marker._div.parentNode.style.zIndex;
return latLng;
},
/* 组织页面*/
orgInfo: function (info) {
var that = this;
info.uid = info.newCode;
info.detailUrl = that.httpAddress(info.purpose) + info.newCode + '.htm';
var stimetempstr = '';
if (info.startTime) {
if (info.startTime.indexOf('-') > -1) {
var stimetemparr = info.startTime.split('-');
stimetempstr += stimetemparr[0] + '年';
if ('undefined' != typeof stimetemparr[1]) {
stimetempstr += stimetemparr[1] + '月';
}
if ('undefined' != typeof stimetemparr[2]) {
stimetempstr += stimetemparr[2] + '日';
}
} else {
stimetempstr += info.startTime.substr(0, 4) + '年';
if (info.startTime.substr(4, 2) != '') {
stimetempstr += info.startTime.substr(4, 2) + '月';
}
if (info.startTime.substr(6, 2) != '') {
stimetempstr += info.startTime.substr(6, 2) + '日';
}
}
}
info.startTime = stimetempstr;
if (info.picAddress == '') {
info.picAddress = imgUrl + 'shipin0.gif';
}
info.mapUrl = 'http://map.' + nowsite + '.com/house/' + city + '/index.php';
if (info.tel) {
info.tel = info.tel.replace(/\s+/g, '');
info.tel = info.tel.replace(/(转)/g, '</span> $1 <span class="mpucred">');
}
if ('' == info.houseurl) {
info.houseurl = 'javascript:void(0)';
}
info.saleType = info.saling ? '<dt class="shouw rbox2 fl ml10 mt15">' + that.saling[info.saling] + '</dt>' : '';
if (info.category && info.esfNum && '2' == info.category) {
if (0 == info.esfNum) {
info.saleType = '<span>(暂无房源信息)</span>';
} else {
info.saleType = '<span>(' + info.esfNum + '套房源)</span>';
}
}
if (!info.price_num) {
info.price_num = '价格暂无';
}
if ('--' == info.price_unit) {
info.price_unit = '';
}
if (info.mobilepayment && 'undefined' != typeof info.mobilepayment) {
info.youhui = '<span class="rbox2 ml05" title="' + info.mobilepayment + '">' + that.cut_str(info.mobilepayment, 7) + '</span>';
} else if (info.signupname && 'undefined' != typeof info.signupname) {
info.youhui = '<span class="rbox2 ml05" title="' + info.signupname + '">' + that.cut_str(info.signupname, 7) + '</span>';
} else if (info.soufun_card_client && 'undefined' != typeof info.soufun_card_client) {
info.youhui = '<span class="rbox2 ml05" title="' + info.soufun_card_client + '">' + that.cut_str(info.soufun_card_client, 7) + '</span>';
} else {
info.youhui = '';
}
info.city_a = '<a style="color: #333;" href="http://www.' + nowsite + '.com/house/s/' + info.city + '" target="_blank">' + info.city + '</a>';
info.district_a = info.district ? ' - ' + '<a style="color: #333;" href="http://www.' + nowsite + '.com/house/s/' + info.district + '/" target="_blank">' + info.district + '</a>' : '';
info.comarea_a = info.comarea ? ' - ' + '<a style="color: #333;" href="http://www.' + nowsite + '.com/house/s/' + info.comarea + '/" target="_blank">' + info.comarea + '</a>' : '';
info.title_l = that.cut_str(info.title, 14);
if (!info.x) {
info.x = info.lng;
}
if (!info.y) {
info.y = info.lat;
}
info.maptype = 'hs';
return info;
},
/* 拼url*/
httpAddress: function (purpose) {
var soufunhttp = '';
var city_cn = '';
if ('undefined' != typeof cname) {
city_cn = cname;
} else if ('undefined' !== typeof searchcondition['cityname']) {
city_cn = searchcondition['cityname'];
}
// IE兼容 indexOf
if (!Array.indexOf) {
Array.prototype.indexOf = function (obj) {
for (var i = 0; i < this.length; i++) {
if (this[i] == obj) {
return i;
}
}
return -1;
};
}
if (purpose.indexOf('写字楼') > -1) {
/* 北京、成都、广州、深圳、天津、上海、重庆、苏州、杭州、沈阳*/
var isInThose = city == 'bj' || city == 'sh' || city == 'cd' || city == 'gz' || city == 'sz' || city == 'tj' || city == 'cq';
if (isInThose || city == 'sy' || city == 'hz' || city == 'suzhou') {
if (city == 'bj') {
soufunhttp = 'http://office.' + nowsite + '.com';
} else {
soufunhttp = 'http://office.' + city + '.' + nowsite + '.com';
}
return soufunhttp + '/house/' + city_cn + '_';
}
} else if (purpose.indexOf('商铺') > -1) {
/* 北京、天津、上海、深圳、东莞、武汉、南京、苏州*/
if (city == 'bj' || city == 'sh' || city == 'dg' || city == 'sz' || city == 'tj' || city == 'wuhan' || city == 'nanjing' || city == 'suzhou') {
if (city == 'bj') {
soufunhttp = 'http://shop.' + nowsite + '.com';
} else {
soufunhttp = 'http://shop.' + city + '.' + nowsite + '.com';
}
return soufunhttp + '/house/' + city_cn + '_';
}
}
if (city == 'bj') {
soufunhttp = 'http://www.' + nowsite + '.com/house/';
} else if (city == 'nanjing') {
soufunhttp = 'http://nanjing.' + nowsite + '.com/house/';
} else {
soufunhttp = 'http://newhouse.' + city + '.' + nowsite + '.com/house/';
}
return soufunhttp;
},
orgSearchInfo: function (info) {
info.x = info.point.lng;
info.y = info.point.lat;
info.address = info.address ? info.address : '暂无';
info.phoneNumber = info.phoneNumber ? info.phoneNumber : '暂无';
return info;
},
/* 测距**/
openDis: function () {
var that = this;
if ('undefined' == typeof that._disTool) {
that._disTool = new BMapLib.DistanceTool(that.map._map);
that._disTool.addEventListener('drawend',
function () {
that._disTool.close();
});
}
that._disTool.open();
},
/* 用戶行為*/
yhxw: function (action) {
_ub.city = vars.cityname;
/* 业务 地图*/
_ub.biz = 'n';
/* 用户动作(浏览0、搜索1)*/
var b = 0;
var p = {
nh: encodeURIComponent(action)
};
/* 收集方法*/
_ub.collect(b, p);
},
array_in_array: function (arr1, arr2) {
if ('undefined' != typeof arr1 && 'undefined' != typeof arr2) {
for (var key in arr1) {
for (var key2 in arr2) {
if ('string' == typeof arr2[key2] && 'string' == typeof arr1[key] && arr2[key2].indexOf(arr1[key]) >= 0) {
return true;
}
}
}
}
return false;
},
in_array: function (type, arr) {
if ('undefined' != typeof arr && 'undefined' != typeof type && $.inArray(type, arr) > -1) {
return true;
} else {
return false;
}
}
}
function initMapConfig(){
mapConfig.map = null,
mapConfig.defaultZoom= 13,
mapConfig.cityx=121.356766,
mapConfig.cityy=31.213703,
zoom=14,
/* 获取附近楼盘url的参数*/
mapConfig.params= {
x1: 121.356766,
y1: 31.213703,
distance: '2',
strNewCode: ''
},
/* 用来存储当前页面上所有点的信息*/
mapConfig.markerList= {},
/* 地图边界:可用来控制地图的显示范围*/
mapConfig.markerBounds= new BMap.Bounds(),
mapConfig.iType= 'hs',
mapConfig.house_type= {zz: '住宅', sp: '商铺', xzl: '写字楼', bs: '别墅'},
// 销售状态
mapConfig.saling= {
1: '在&nbsp;售',
2: '待&nbsp;售',
3: '在&nbsp;租',
4: '待&nbsp;租',
0: '售&nbsp;完'
},
/* 以下是周边查询的***/
mapConfig.have_arr= {
hs: '',
jj: '',
zs: '',
bus: '',
subway: '',
ct: '',
bank: '',
school: '',
hos: '',
buy: '',
park: '',
parking: '',
gas: '',
ktv: '',
bar: '',
cinema: '',
beauty: '',
cafe: '',
kindergarten: '',
primarysc: '',
middlesc: '',
university: '',
traffic: '',
fun: ''
},
mapConfig.have_arr_new= {
bus: '公交',
subway: '地铁',
ct: '餐饮',
bank: '银行',
school: '学校',
hos: '医院',
buy: '购物',
park: '公园',
parking: '停车场',
gas: '加油站',
supermark: '超市',
ktv: 'KTV',
bar: '酒吧',
cinema: '电影院',
beauty: '美容院',
cafe: '咖啡厅',
kindergarten: '幼儿园',
primarysc: '小学',
middlesc: '中学',
university: '大学',
traffic: '交通',
fun: '娱乐',
hs: '小区'
},
// 需要删除的点集合包含路线,搜附近type为other的点
mapConfig.toDelterMarkers= [],
// 已描点集合
mapConfig.house_near_p= [],
/* 打开标注框方法集***/
mapConfig.openTip= [],
/* 标注获得焦点方法集***/
mapConfig.focusInfoWinFuns= [],
/* 标注失去焦点方法集***/
mapConfig.blurInfoWinFuns= [],
/* 具有小分类的周边搜索***/
mapConfig.house_near_merge= {
traffic: ['subway', 'bus', 'parking', 'gas'],
// 商业包含娱乐 超市 餐饮 银行 公园
business: ['fun', 'supermark', 'ct', 'bank', 'park'],
// 娱乐
fun: ['ktv', 'bar', 'cinema', 'beauty', 'cafe'],
school: ['kindergarten', 'primarysc', 'middlesc', 'university']
},
/* 大分类列表***/
mapConfig.search_wrap= ['hs', 'traffic', 'fun', 'supermark', 'ct', 'bank', 'hos', 'park', 'school'],
/* 需要进行搜索返回值过滤的周边***/
mapConfig.type_tags= {subway: ['地铁']},
/* 获取周边条数*/
mapConfig.maxMarker_count= 20,
// 列表中初始化可看到的元素
mapConfig.view_count= 5,
/* 获取周边范围(m)*/
mapConfig.limit= 2000,
/* 驾车查询的参数*/
mapConfig.searchdrive= {start: '', x1: '', y1: '', sstatus: '', end: '', x2: '', y2: '', estatus: '', type: '', tag: ''},
mapConfig.sstartname= null,
mapConfig.sendname= null,
mapConfig.tag= null
}
function loadMapPoi(){
initMapConfig();
mapConfig.init();
}