Add new types of events.
Add icons of events.
This commit is contained in:
102
index.html
102
index.html
@@ -4,6 +4,7 @@
|
|||||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
|
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
|
||||||
<title>上海艺术地图</title>
|
<title>上海艺术地图</title>
|
||||||
<link rel="stylesheet" href="http://cache.amap.com/lbs/static/main1119.css"/>
|
<link rel="stylesheet" href="http://cache.amap.com/lbs/static/main1119.css"/>
|
||||||
|
<!-- <link href="https://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"> -->
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
html, body {
|
html, body {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
@@ -84,49 +85,70 @@ function mapInit(){
|
|||||||
|
|
||||||
// https://github.com/unixcrh/DOUBANTONGCHENG/blob/master/DouBanTongCheng/ContentVC.m
|
// https://github.com/unixcrh/DOUBANTONGCHENG/blob/master/DouBanTongCheng/ContentVC.m
|
||||||
// https://developers.douban.com/wiki/?title=event_v2
|
// https://developers.douban.com/wiki/?title=event_v2
|
||||||
|
var doubanEvents = [
|
||||||
var doubanApi = "https://api.douban.com/v2/event/list?loc=shanghai&type=exhibition&max-results=50&callback=?";
|
"https://api.douban.com/v2/event/list?loc=shanghai&type=music&max-results=30&callback=?",
|
||||||
$.getJSON(doubanApi)
|
"https://api.douban.com/v2/event/list?loc=shanghai&type=drama&max-results=30&callback=?",
|
||||||
.done(function(json){
|
"https://api.douban.com/v2/event/list?loc=shanghai&type=film&max-results=30&callback=?",
|
||||||
//response json are now in the json variable
|
"https://api.douban.com/v2/event/list?loc=shanghai&type=exhibition&max-results=30&callback=?",
|
||||||
// console.log(json);
|
];
|
||||||
json.events.forEach(function(ev, i) {
|
// http://fontawesome.io/icons/
|
||||||
var geo = ev.geo.split(' ');
|
var doubanIcons = [
|
||||||
var marker = new AMap.Marker({
|
'<i class="fa fa-music" aria-hidden="true"></i>',
|
||||||
map: mapObj,
|
'<i class="fa fa-magic" aria-hidden="true"></i>',
|
||||||
position: new AMap.LngLat(geo[1], geo[0]),
|
'<i class="fa fa-film" aria-hidden="true"></i>',
|
||||||
icon: "http://webapi.amap.com/images/1.png",
|
'<i class="fa fa-paint-brush" aria-hidden="true"></i>',
|
||||||
// icon: ev.owner.alt.match('site') ? new AMap.Icon({
|
];
|
||||||
// image: ev.owner.avatar,
|
|
||||||
// }) : null,
|
|
||||||
// label: "vvvvvv",
|
|
||||||
title: ev.title + '\n' +
|
|
||||||
ev.address.replace(/上海(\s+|市)/g, '') + '\n' +
|
|
||||||
ev.begin_time.substring(5, ev.begin_time.length - 3) + ' ~ ' +
|
|
||||||
ev.end_time.substring(5, ev.end_time.length - 3)
|
|
||||||
});
|
|
||||||
|
|
||||||
marker.setLabel({//label默认蓝框白底左上角显示,样式className为:amap-marker-label
|
// http://www.flaticon.com/
|
||||||
offset: new AMap.Pixel(20, 20),//修改label相对于maker的位置
|
var doubanFlatIcons = [
|
||||||
content: ev.title
|
'media/music-player.png',
|
||||||
});
|
'media/theater.png',
|
||||||
// closure based
|
'media/camera.png',
|
||||||
// AMap.event.addListener(marker, 'click', function(marker_, i_) {
|
'media/college.png',
|
||||||
// return function() {
|
];
|
||||||
// // marker_.setContent(json.events[i_].content);
|
doubanEvents.forEach(function(doubanEvent, i) {
|
||||||
// window.open(json.events[i_].alt,'mywin','');
|
$.getJSON(doubanEvent)
|
||||||
// };
|
.done(function(json){
|
||||||
// }(marker, i));
|
//response json are now in the json variable
|
||||||
|
// console.log(json);
|
||||||
|
json.events.reverse().forEach(function(ev, j) {
|
||||||
|
var geo = ev.geo.split(' ');
|
||||||
|
var marker = new AMap.Marker({
|
||||||
|
map: mapObj,
|
||||||
|
position: new AMap.LngLat(geo[1], geo[0]),
|
||||||
|
icon: doubanFlatIcons[i],
|
||||||
|
// icon: ev.owner.alt.match('site') ? new AMap.Icon({
|
||||||
|
// image: ev.owner.avatar,
|
||||||
|
// }) : null,
|
||||||
|
// label: "vvvvvv",
|
||||||
|
title: ev.title + '\n' +
|
||||||
|
ev.address.replace(/上海(\s+|市)/g, '') + '\n' +
|
||||||
|
ev.begin_time.substring(5, ev.begin_time.length - 3) + ' ~ ' +
|
||||||
|
ev.end_time.substring(5, ev.end_time.length - 3)
|
||||||
|
});
|
||||||
|
|
||||||
AMap.event.addListener(marker, 'click', function() {
|
marker.setLabel({//label默认蓝框白底左上角显示,样式className为:amap-marker-label
|
||||||
// marker_.setContent(ev.content);
|
offset: new AMap.Pixel(26, 0),//修改label相对于maker的位置
|
||||||
window.open(ev.alt,'mywin','');
|
content: ev.title
|
||||||
|
});
|
||||||
|
// closure based
|
||||||
|
// AMap.event.addListener(marker, 'click', function(marker_, i_) {
|
||||||
|
// return function() {
|
||||||
|
// // marker_.setContent(json.events[i_].content);
|
||||||
|
// window.open(json.events[i_].alt,'mywin','');
|
||||||
|
// };
|
||||||
|
// }(marker, i));
|
||||||
|
|
||||||
|
AMap.event.addListener(marker, 'click', function() {
|
||||||
|
// marker_.setContent(ev.content);
|
||||||
|
window.open(ev.alt,'mywin','');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
})
|
||||||
})
|
.fail(function() {
|
||||||
.fail(function() {
|
alert('Can not use douban api');
|
||||||
alert('Can not use douban api');
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
BIN
media/camera.png
Normal file
BIN
media/camera.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 644 B |
BIN
media/college.png
Normal file
BIN
media/college.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 652 B |
BIN
media/music-player.png
Normal file
BIN
media/music-player.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 534 B |
BIN
media/theater.png
Normal file
BIN
media/theater.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1008 B |
Reference in New Issue
Block a user