-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
222 lines (208 loc) · 7.43 KB
/
index.html
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<!DOCTYPE html>
<html>
<head>
<title>原宿には飯屋がない(こともなかった)</title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=0.1">
<link rel="stylesheet" href="./base.css" />
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="./jsdeferred.jquery.js"></script>
<script type="text/javascript" src="./util.js"></script>
<script>
$(function(){
lunch.getFlickrPhotoset();
// mapSwitch
$("#mapSwitch li:last").bind('click',function(){ scroll.leap('FlickrPhotos'); return false; });
$("#mapSwitch li:first").bind('click',function(){ scroll.leap('GoogleMaps'); return false; });
});
//
// 1. Get Flickr Photoset
// 2. Set Data
// 3. Append Photo-Cards
// 4. preset Map-mode
// 5. addEvents
//
// Docs:
// http://www.flickr.com/services/api/
// https://github.com/cho45/jsdeferred
// http://code.google.com/intl/ja/apis/maps/documentation/javascript/basics.html
var lunch = {
data: [],
iw: [],
cardLink: [],
api_key: '20323d0dcecbd6355010f69d2e341ea3',
setData: function(data){
$.each(data.photoset.photo, function(i, item){
lunch.data[i] = {
id : item.id,
title : item.title,
server : item.server,
secret : item.secret,
farm : item.farm,
link : 'http://www.flickr.com/photos/sigwyg20/' + item.id + '/',
imgSrc : 'http://farm' + item.farm + '.static.flickr.com/' + item.server + '/' + item.id + '_' + item.secret,
latitude : item.latitude,
longitude : item.longitude,
tags : $.trim(item.tags.replace(/d3100/, ''))
};
});
},
getFlickrPhotoset: function(){
$.ajax({
type : 'GET',
url : 'http://www.flickr.com/services/rest/?nojsoncallback=1',
data : {
format : 'json',
method : 'flickr.photosets.getPhotos',
api_key : lunch.api_key,
user_id : '12068798@N00',
sort : 'date-posted-asc',
photoset_id : '72157627461006892',
extras : "geo,tags",
per_page : '50',
},
dataType : 'jsonp',
jsonp : 'jsoncallback',
success : function(data, dataType){
if (dataType == 'success') {
lunch.setData(data);
lunch.setPhotoCards();
lunch.setGoogleMaps();
lunch.setMarker();
}
}
});
},
getPhotoInfo: function(i, item){
return $.ajax({
type : 'GET',
url : 'http://www.flickr.com/services/rest/?nojsoncallback=1',
data : {
format : 'json',
method : 'flickr.photos.getInfo',
api_key : lunch.api_key,
photo_id : item.id,
secret : item.secret
},
dataType : 'jsonp',
jsonp : 'jsoncallback',
success : function(data, dataType){
if (dataType == 'success') {
lunch.data[i].description = data.photo.description._content;
}
}
}) ;
},
setPhotoCards: function(){
// <article id="day1">
// <a href>
// <img src="" />
// <div class="wrap">
// <h1>Shop name</h1>
// <p>tag</p>
// </div>
// </a>
// </article>
$.each(lunch.data, function(i, item){
var article = $('<article/>',{id: "day" + i});
var link = $('<a/>',{href: item.link}).appendTo(article);
var image = $('<img/>',{src: item.imgSrc + "_m.jpg" }).appendTo(link);
var wrap = $('<div/>',{class: 'wrap'}).appendTo(link);
var title = $('<h1/>',{text: item.title}).appendTo(wrap);
$('#FlickrPhotos').append(article);
lunch.cardLink.push(link);
});
},
//
// GoogleMaps
//
setGoogleMaps: function() {
var latlng = new google.maps.LatLng(35.670168, 139.708687);
var myOptions = {
zoom: 16,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
lunch.map = new google.maps.Map(document.getElementById("GoogleMaps"), myOptions);
},
setMarker: function() {
var map = lunch.map;
// Set Markers
$.each(lunch.data, function(i, item){
var marker = new google.maps.Marker({
position : new google.maps.LatLng(item.latitude, item.longitude),
map : map,
title : item.title,
zindex : i
});
// Prepare infoWindow
lunch.getPhotoInfo(i,item).next(function () {
var description = item.description.replace(/^\([^)]{2,}?\)/,'');
var desc = description.split('/');
if(desc[1]){ desc[0] = desc[0] + '</li><li>' + desc[1] }
var infowindow = new google.maps.InfoWindow({
content:
'<div>'
+ '<h1><img src="' + item.imgSrc + '_m.jpg" alt="' + item.title + '" /></h1>'
+ '<ul>'
+ '<li>[' + item.tags + '] ' + item.title + '</li>'
+ '<li>' + desc[0] + '</li>'
+ '</ul>'
+ '</div>',
maxWidth: 280
});
lunch.iw[i] = infowindow;
// Popup infoWindow
// - on Clicked a marker
google.maps.event.addListener(marker, 'click', function(){
$.each(lunch.iw, function(i,item){ item.close() })
infowindow.open(map,marker);
});
// Add Event to Card
$(lunch.cardLink[i])
.bind('click',function(){
$.each(lunch.iw, function(i,item){ item.close() })
infowindow.open(map,marker);
//scrollTo(1024,120);
scroll.leap('GoogleMaps');
return false;
});
})
.error(function(){
alert(e);
})
marker.setMap(map);
});
}
};
</script>
</head>
<body class="">
<header>
<hgroup>
<h1>原宿には飯屋がない</h1>
<h2>(こともなかった)</h2>
</hgroup>
<nav id="mapSwitch">
<ul>
<li><a href="">map</a></li>
<li><a href="">card</a></li>
</ul>
</nav>
<nav id="mapItems">
<ul></ul>
</nav>
</header>
<!--: Start #contents -->
<div id="contents">
<div id="GoogleMaps"></div>
<div id="FlickrPhotos"></div>
</div>
<!--: End #contents -->
<footer></footer>
</body>
</html>