質問編集履歴
2
URl削除
title
CHANGED
File without changes
|
body
CHANGED
@@ -93,7 +93,7 @@
|
|
93
93
|
|
94
94
|
// var
|
95
95
|
var latlng = new google.maps.LatLng( $marker.attr('data-lat'), $marker.attr('data-lng') );
|
96
|
-
var icon = new google.maps.MarkerImage('
|
96
|
+
var icon = new google.maps.MarkerImage('');
|
97
97
|
// create marker
|
98
98
|
var marker = new google.maps.Marker({
|
99
99
|
position : latlng,
|
1
コードを追記致しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -3,6 +3,170 @@
|
|
3
3
|
下記サイトのやり方で、wordpressのプラグインのACFを使用して一つだけは、
|
4
4
|
マーカーを設置しマーカー画像も変更出来ましたが、複数設置する方法が、分かりません。
|
5
5
|
|
6
|
+
```ここに言語を入力
|
7
|
+
/google map
|
8
|
+
|
9
|
+
(function($) {
|
10
|
+
|
11
|
+
/*
|
12
|
+
* render_map
|
13
|
+
*
|
14
|
+
* This function will render a Google Map onto the selected jQuery element
|
15
|
+
*
|
16
|
+
* @type function
|
17
|
+
* @date 8/11/2013
|
18
|
+
* @since 4.3.0
|
19
|
+
*
|
20
|
+
* @param $el (jQuery element)
|
21
|
+
* @return n/a
|
22
|
+
*/
|
23
|
+
|
24
|
+
function render_map( $el ) {
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
// var
|
29
|
+
var $markers = $el.find('.marker');
|
30
|
+
|
31
|
+
// vars
|
32
|
+
var args = {
|
33
|
+
zoom : 16,
|
34
|
+
center : new google.maps.LatLng(0, 0),
|
35
|
+
mapTypeId : google.maps.MapTypeId.ROADMAP,
|
36
|
+
draggable: true, //追記ドラッグ禁止
|
37
|
+
scrollwheel: false //スクロール禁止
|
38
|
+
};
|
39
|
+
|
40
|
+
// create map
|
41
|
+
var map = new google.maps.Map( $el[0], args);
|
42
|
+
|
43
|
+
// add a markers reference
|
44
|
+
map.markers = [];
|
45
|
+
|
46
|
+
// add markers
|
47
|
+
$markers.each(function(){
|
48
|
+
|
49
|
+
add_marker( $(this), map );
|
50
|
+
|
51
|
+
});
|
52
|
+
|
53
|
+
// center map
|
54
|
+
center_map( map );
|
55
|
+
|
56
|
+
}
|
57
|
+
|
58
|
+
/*
|
59
|
+
* add_marker
|
60
|
+
*
|
61
|
+
* This function will add a marker to the selected Google Map
|
62
|
+
*
|
63
|
+
* @type function
|
64
|
+
* @date 8/11/2013
|
65
|
+
* @since 4.3.0
|
66
|
+
*
|
67
|
+
* @param $marker (jQuery element)
|
68
|
+
* @param map (Google Map object)
|
69
|
+
* @return n/a
|
70
|
+
*/
|
71
|
+
|
72
|
+
function add_marker( $marker, map ) {
|
73
|
+
|
74
|
+
// color
|
75
|
+
var styleOptions = [{
|
76
|
+
'stylers': [{
|
77
|
+
'gamma': 1.2//ガンマ
|
78
|
+
}, {
|
79
|
+
'saturation': -100//彩度
|
80
|
+
}, {
|
81
|
+
'lightness': -20//明度
|
82
|
+
}]
|
83
|
+
}]
|
84
|
+
|
85
|
+
var styledMapOptions = {
|
86
|
+
name: 'mono'
|
87
|
+
}
|
88
|
+
var monoType = new google.maps.StyledMapType(styleOptions, styledMapOptions);
|
89
|
+
map.mapTypes.set('mono', monoType);
|
90
|
+
map.setMapTypeId('mono');
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
// var
|
95
|
+
var latlng = new google.maps.LatLng( $marker.attr('data-lat'), $marker.attr('data-lng') );
|
96
|
+
var icon = new google.maps.MarkerImage('http://watashinokaisya.com/wp-content/themes/coen/images/map_coen.png');
|
97
|
+
// create marker
|
98
|
+
var marker = new google.maps.Marker({
|
99
|
+
position : latlng,
|
100
|
+
map : map,
|
101
|
+
icon : icon
|
102
|
+
});
|
103
|
+
|
104
|
+
// add to array
|
105
|
+
map.markers.push( marker );
|
106
|
+
|
107
|
+
// if marker contains HTML, add it to an infoWindow
|
108
|
+
if( $marker.html() )
|
109
|
+
{
|
110
|
+
// create info window
|
111
|
+
var infowindow = new google.maps.InfoWindow({
|
112
|
+
content : $marker.html()
|
113
|
+
});
|
114
|
+
|
115
|
+
// show info window when marker is clicked
|
116
|
+
google.maps.event.addListener(marker, 'click', function() {
|
117
|
+
|
118
|
+
infowindow.open( map, marker );
|
119
|
+
|
120
|
+
});
|
121
|
+
}
|
122
|
+
|
123
|
+
}
|
124
|
+
|
125
|
+
/*
|
126
|
+
* center_map
|
127
|
+
*
|
128
|
+
* This function will center the map, showing all markers attached to this map
|
129
|
+
*
|
130
|
+
* @type function
|
131
|
+
* @date 8/11/2013
|
132
|
+
* @since 4.3.0
|
133
|
+
*
|
134
|
+
* @param map (Google Map object)
|
135
|
+
* @return n/a
|
136
|
+
*/
|
137
|
+
|
138
|
+
function center_map( map ) {
|
139
|
+
|
140
|
+
// vars
|
141
|
+
var bounds = new google.maps.LatLngBounds();
|
142
|
+
|
143
|
+
// loop through all markers and create bounds
|
144
|
+
$.each( map.markers, function( i, marker ){
|
145
|
+
|
146
|
+
var latlng = new google.maps.LatLng( marker.position.lat(), marker.position.lng() );
|
147
|
+
|
148
|
+
bounds.extend( latlng );
|
149
|
+
|
150
|
+
});
|
151
|
+
|
152
|
+
// only 1 marker?
|
153
|
+
if( map.markers.length == 1 )
|
154
|
+
{
|
155
|
+
// set center of map
|
156
|
+
map.setCenter( bounds.getCenter() );
|
157
|
+
map.setZoom( 16 );
|
158
|
+
}
|
159
|
+
else
|
160
|
+
{
|
161
|
+
// fit to bounds
|
162
|
+
map.fitBounds( bounds );
|
163
|
+
}
|
164
|
+
|
165
|
+
}
|
166
|
+
```
|
167
|
+
|
168
|
+
|
169
|
+
|
6
170
|
http://qiita.com/JumpeiSato/items/21cfc4e07288313cf3ab
|
7
171
|
|
8
172
|
ご教授いただけますと幸いです。
|