ãºããã
é ãããœãŒã¹ã³ãŒããå
ã«ãäœãæ¿ããŠã¿ãŸããã
App Engineã«ãããã€ãŸã§ããŠã¯ããªãã®ã§ããããã¶ãåãã§ãããã
Google Maps APIã®æ©èœãã®ãã®ã«ãããŒã«ãŒã®è²ãå€ããæ©èœã¯ãããŸããã
ããŒã«ãŒã®ç»åãèªåã§çšæããå¿
èŠããããŸãã
ååå¥ã®ããŒã«ãŒããšã«æ
å ±ãŠã£ã³ããŠã®å
容ã倿Žããæ¹æ³ã§ããã
createMarker() ãšãã颿°ã®äžã§è¡ãªã£ãŠããŸãã
颿°ã®äžã§HTMLã®æååãäœæããããšã§ãããŒã«ãŒãã¯ãªãã¯ããæã«
ããããã®å
容ãç¶æ/衚瀺ããããã«ãªã£ãŠããŸãã
<script type="text/javascript">
var map;
var zoomLevel = 5;
var infoWindow = null;
var markerDic = {};
var preId = null;
//ãºãŒã ã¬ãã«ã倿Žã«ãªã£ããå®è¡ãã
function onZoomChanged() {
//æåŸã«ã¯ãªãã¯ãããããŒã«ãŒã®äœçœ®ãäžå¿äœçœ®ã«ãã
map.setCenter(markerDic[preId].getPosition());
}
//ãªã¹ããã¯ãªãã¯ããããå®è¡ãã
function onListItemClicked(id) {
//ããŒã«ãŒãæ¬äŒŒã¯ãªãã¯ãã
google.maps.event.trigger(markerDic[id], "click");
}
function initialize() {
//å°å³ã衚瀺ããã®ã«å¿
èŠãªãã©ã¡ãŒã¿
var latlng = new google.maps.LatLng(35.69836, 139.773104);
var myOptions = {
zoom : zoomLevel,
center : latlng,
mapTypeId : google.maps.MapTypeId.ROADMAP
};
//å°å³ãäœæãã
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
//æ
å ±ãŠã£ã³ããŠã1ã€ã ãäœæãã
infoWindow = new google.maps.InfoWindow();
//ãºãŒã ã¬ãã«ã倿Žã«ãªã£ãããonZoomChanged ãå®è¡ãã
google.maps.event.addListener(map, 'zoom_changed', onZoomChanged);
//ã«ããŽãªã«å¿ããç»åãèªåã§çšæããå¿
èŠããããŸã
var categories = {
"red" : "/img/markers/red.png",
"blue" : "/img/markers/blue.png"
};
{% for image in images %}
//ããŒã«ãŒãäœæãã颿°(createMarker)ã«ããŒã¿ãæž¡ãã
//颿°ããã¯ãäœæãããããŒã«ãŒãè¿ããã
var marker = createMarker({
map : map,
position : new google.maps.LatLng({{image.geo.lat}}, {{image.geo.lon}}),
image_key : "{{image.key}}",
image_author : "{{image.author}}",
image_title : "{{image.title}}",
image_place : "{{image.place}}",
image_createdTime : "{{image.createdTime}} JST",
image_comment : "{{image.comment}}",
//ã«ããŽãªã®æ¡ä»¶ã«ãã£ãŠãç»åãå€ããããã«ãã
image : categories["blue"]
});
//ããŒã«ãŒã®é
åã«è¿œå ãã
markerDic["{{image.key}}"] = marker;
if (prefId == null) {
//äžçªæåã«äœæããããŒã«ãŒãæ¬äŒŒã¯ãªãã¯ããããšã§ãæ
å ±ãŠã£ã³ããŠãéã
google.maps.event.trigger(marker, "click");
}
{% endfor %}
}
function createMarker(options) {
//HTMLã®æååãäœæãã
var html = [
'<div>',
'<a href="/img?key=' + options.image_key + '">',
'<img src="/img?key=' + options.image_key + '&width=100" align="left">',
'</a>',
'</div>',
'<div>',
'<div>' + options.image_author + '<br></div><br>',
'<div>' + options.image_title + '</div><br>',
'<div>' + options.image_place + '</div><br>',
'<div>' + options.image_createdTime + '</div><br>',
'<div>' + options.image_comment + '</div><br>',
'<br><br><div>ã³ã¡ã³ã</div><br>',
'</div>'
].join("");
//ããŒã«ãŒãäœæãã
var marker = new google.maps.Marker({
map : options.map,
image : options.image
});
//ã¯ãªãã¯ãããããæ
å ±ãŠã£ã³ããŠãéã
google.maps.event.addListener(marker, "click", function() {
//æåŸã«ã¯ãªãã¯ãããããŒãèšæ¶ããŠãã
prefId = options.image_key;
//æ
å ±ãŠã£ã³ããŠã®å
å®¹ãæŽæ°ãã
infoWindow.setContent(html);
//衚瀺ãã
infoWindow.open(options.map, marker);x
});
return marker;x
}
</script>