map.js
6.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/**
* @fileOverview map页面JS
* @author wei.wang@yoho.cn
* @date 2014-05-21
*/
var $ = jQuery = require("jquery");
require("../public");
require("../plugin/nicescroll");
var _ui=require("jquery-ui");
_ui($);
require("jquery.imagesloaded");
initShopListHeight();
$(".city-list").niceScroll();
var currentZoom=0.85;
var OriginalWidth=0,OriginalHeight=0,OriginalMarks={};
exports.init=function(){
$(".map-zoom").show();
OriginalWidth=$("#citymap-img").width();
OriginalHeight=$("#citymap-img").height();
$("#map-zoom-max").click(function(){zoomMax();});
$("#map-zoom-min").click(function(){zoomMin();});
$(".big-mark").each(function(index,obj){
var top=$(this).top();
var left=$(this).left();
OriginalMarks[$(this).attr("id")]={left:left,top:top};
});
$(window).bind("resize",function(){
initShopListHeight();
});
$(".shop").unbind("hover").hover(
function(){
$("#citymap").stop();
$(".mark-tips").hide();//隐藏现有的气泡
moveShopToView(this);
},
function(){
var shopId=$(this).id().replace("shoplist-","mark");
$("#"+shopId).find(".mark-tips").hide();
}
);
$(".big-mark").hover(
function(){$(this).find(".mark-tips").css("display","table");},
function(){$(this).find(".mark-tips").css("display","none");}
);
$(".shop-name").click(function(){
var url=$(this).attr("src");
window.open(url);
});
$(".big-mark").click(function(){
var href=$("a[val='"+$(this).attr("val")+"']").attr("src");
window.open(href);
});
var bodyHeight = document.body.clientHeight - 177;
$(".map-city-content").height(bodyHeight);
$(window).bind("resize", function()
{
var bodyHeight = document.body.clientHeight - 177;
$(".map-city-content").height(bodyHeight);
$("#citymap-img").width($("#citymap").width());
$("#citymap-img").height($("#citymap").height());
});
$("#citymap-img").imagesLoaded(function()
{
$(this).width("100%").height("100%");
$("#citymap").css({width: $(this).width(), height: $(this).height(), position: "relative"}).draggable({
drag: function() {},
stop: function() {
mapRevert(this);
}
});
});
var isMouseDown = false;
};
function initShopListHeight(){
var currentWidth=document.body.clientWidth;
if(currentWidth>=1190)
{
$(".city-list").height(document.body.clientHeight-310);
}
else if(currentWidth<1190&¤tWidth>769)
{
$(".city-list").height(document.body.clientHeight-260);
}
else if(currentWidth<=768)
{
$(".city-list").height(document.body.clientHeight-178);
}
}
/*在商店上显示tips*/
function shopShowTips(obj){
var shopId=$(obj).id().replace("shoplist-","mark");
$("#"+shopId).find(".mark-tips").show();
}
/*如果店铺不在当前视野范围内,则移动到当前范围*/
function moveShopToView(obj){
var contentHeight=$(".map-city-content").height();
var contentWidth=document.body.clientWidth;
var shopId=$(obj).id().replace("shoplist-","mark");
var top=$("#"+shopId).offset().top;
var left=$("#"+shopId).offset().left;
var absoluteTop=0;
var absoluteLeft=0;//$("#"+shopId).offset().left+$("#citymap").left();
if ($("#"+shopId).css("top").indexOf("%")>0) {
absoluteTop=parseFloat($("#"+shopId).css("top").replace("%",""))/100*$("#citymap").height();
absoluteLeft=parseFloat($("#"+shopId).css("left").replace("%",""))/100*$("#citymap").width();
}
else
{
absoluteTop=$("#"+shopId).top();
absoluteLeft=$("#"+shopId).left();
}
var location=getScreenCenter();
if(top<304&&top>0||top<0||
top+177>document.body.clientHeight
||left<$(".city-list").width()
||left>document.body.clientWidth
)
{
var toTop=location.y-absoluteTop;
var toLeft=location.x-absoluteLeft;
if (toLeft>$(".city-list").width()) {
toLeft=$(".city-list").width();
}
if (toTop>190) {
toTop=190;
}
$("#citymap").animate({top:toTop,left:toLeft},500,function(){
$("#"+shopId).find(".mark-tips").show();
});
}
else
{
$("#"+shopId).find(".mark-tips").show();
}
}
function zoom(){
var width=OriginalWidth*currentZoom;
var height=OriginalHeight*currentZoom;
$("#citymap").width(width);
$("#citymap").height(height);
}
function zoomMax(){
if(currentZoom>=1)
{
return;
}
currentZoom=currentZoom+0.05;
zoom();
}
function zoomMin(){
if(currentZoom<=0.7)
{
return;
}
currentZoom=currentZoom-0.05;
zoom();
}
function mapRevert(obj)
{
var top = parseFloat($(obj).css("top").replace("px", ""));
var left = parseFloat($(obj).css("left").replace("px", ""));
var contentHeight = $(".map-city-content").height();
var contentWidth = document.body.clientWidth;
var bottom = contentHeight - top - $(obj).height();
// var right = contentWidth - left - parseFloat($(obj).width());
// var rightForbid = contentWidth - $(".city-shop-list").width();
if (top > 120 && bottom < 0)
{
$(obj).animate({top: 120}, 500);
}
if (bottom > 0 && top < 120)
{
$(obj).animate({top: contentHeight - $(obj).height()}, 500);
}
if (left + $(obj).width() <= $(".city-shop-list").width())
{
$(obj).animate({left: contentWidth - $(obj).width()}, 500);
}
if (left > contentWidth)
{
$(obj).animate({left: contentWidth - $(obj).width()}, 500);
}
}
function getScreenCenter(){
var width=document.body.clientWidth;
var height=document.body.clientHeight;
var _left=(width-$(".city-shop-list").width())/2+$(".city-shop-list").width();
var _headerHeight=$("#maxEnterprise").height()-$(".enterprise-header").height()-12;
var _top=$(".map-city-content").height()/2;
//$("<span/>").css({position:"absolute",display:"block",width:20,height:20,"z-index":20,background:"#f00",left:_left,top:_top}).appendTo(document.body);
return {x:_left,y:_top};
}