-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.mk_easyGoogleMap.js
77 lines (63 loc) · 1.69 KB
/
jquery.mk_easyGoogleMap.js
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
/*!
* $.fn.mk_easyGoogleMap
*
* Copyright (c) 2011 Skill Partners Inc. All Rights Reserved.
*
* http://www.geocoding.jp/ で、緯度経度を測って、オプションで渡すと、
* 指定のdivの中身を マーカー付きの Google Map にする。
*
* @require: jquery.js, http://maps.google.com/maps/api/js?sensor=false
* @create: 2011-08-19 [[email protected]]
* @modify: not yet
*/
(function($){ // start jquery
$.fn.mk_easyGoogleMap = function(options){
//Google Map をはめ込むエレメントがなかったら離脱
if (!this.length) {
return;
}
//default options
var defaults = {
lat: null,
lng: null,
width: null,
height: null,
zoom: 15
};
var o = $.extend(defaults, options);
//$this
var $this = $(this);
// Google Map を表示するには幅と高さのサイズ指定が必須なので、
// 1. optionsで渡した値
// 2. $(this)のサイズ
// 3. 固定値
// の優先順で幅と高さをセットする。
// GoogleMapにするdiv要素内に、JSオフ時用の静的画像を入れておけばそのサイズ(2)になる。
var w = o.width || $this.width() || 600;
var h = o.height || $this.height() || 480;
//set css width / height for Google Map
$this.css({
'width': w,
'height': h
});
//set Google Map
var latlng = new google.maps.LatLng(o.lat, o.lng);
var mapOpt = {
zoom: o.zoom,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map($this.get(0), mapOpt);
var marker = new google.maps.Marker({
position: latlng,
map: map
});
return this;
};
})(jQuery); // end jquery
/*
* Release Notes:
*
* 2011-08-19 [[email protected]]
* # create
*/