PageSourceSearch

https://www.madoya-madosuke.com/wp/wp-content/plugins/mw-google-maps/js/jquery.mw-google-maps.js?ver=1.2.0

js madoya-madosuke.com collected 2026-10-05 03:02:29 UTC 9,282 bytes, 319 lines download raw bytes

1/**
2 * Name: jquery.mw-google-maps.js
3 * Plugin URI: http://2inc.org/blog/category/products/wordpress_plugins/mw-google-maps/
4 * Description: Google Maps API v3 操作
5 * Version: 1.2.1
6 * Author: Takashi Kitajima
7 * Author URI: http://2inc.org
8 * Created : August 28, 2013
9 * Modified: February 25, 2015
10 * License: GPL2
11 *
12 * Copyright 2013 Takashi Kitajima (email : [email protected])
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License, version 2, as
16 * published by the Free Software Foundation.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
26 *
27 * ========== 使い方 ==========
28 *	var gmap = $( '#map' ).mw_google_maps();
29 *	// マーカーの追加
30 *	gmap.mw_google_maps( 'addMarker', {
31 *		latitude : 11111111,
32 *		longitude: 11111111,
33 *		title    : 'hoge',
34 *		draggable: false
35 *	} );
36 *	// ジオコード
37 *	gmap.mw_google_maps( 'geocode', {
38 *		btn      : $( 'btn' ),
39 *		address  : $( '#address' ),
40 *		latitude : $( '#latitude' ),
41 *		longitude: $( '#longitude' )
42 *	} );
43 *	// レンダリング
44 *	gmap.mw_google_maps( 'render' );
45 */
46;( function( $ ) {
47
48	var plugname = 'mw_google_maps';
49	var useRoute = false;
50
51	var methods = {
52		/**
53		 * init
54		 * 初期化
55		 */
56		init   : function( params ) {
57			return this.each( function() {
58				var data = $( this ).data( plugname );
59				if ( !data ) {
60					var defaults = {
61						latitude : 35.71012566481748,
62						longitude: 139.81149673461914,
63						zoom     : 13
64					};
65					$( this ).data( plugname, {
66						config : $.extend( defaults, params ),
67						points : [],
68						geocode: {}
69					} );
70				}
71			} );
72		},
73
74		/**
75		 * addMarker
76		 * マーカーの追加
77		 */
78		addMarker: function( params ) {
79			return this.each( function() {
80				var data = $( this ).data( plugname );
81				var defaults = {
82					latitude : 35.71012566481748,
83					longitude: 139.81149673461914,
84					title    : '',
85					draggable: false
86				}
87				data.points.push( $.extend( defaults, params ) );
88			} );
89		},
90
91		/**
92		 * render
93		 * レンダリング
94		 */
95		render: function( params ) {
96			return this.each( function() {
97				var gmap = $( this );
98				var data = gmap.data( plugname );
99
100				// 初期位置設定
101				var position = new google.maps.LatLng(
102					data.config.latitude,
103					data.config.longitude
104				);
105				// マップ表示
106				var map = new google.maps.Map( gmap.get( 0 ), {
107					center: position,
108					zoom: data.config.zoom,
109					mapTypeId: google.maps.MapTypeId.ROADMAP,
110					scrollwheel: false,
111					scaleControl: true
112				} );
113				// マーカー設置
114				if ( data.points.length < 1 ||
115					 typeof( data.points[0].latitude ) == 'undefined' ||
116					 typeof( data.points[0].longitude ) == 'undefined' )
117					return true; // = jQuery's continue.
118
119				if ( useRoute === true ) {
120					// ルートを表示するマップを設定
121					var directionsRenderer = new google.maps.DirectionsRenderer();
122					directionsRenderer.setMap( map );
123
124					// 経由地点を設定(無料版は最大8箇所)
125					var wayPoints = [];
126					$.each( data.points, function( key, val ) {
127						wayPoints.push( {
128							location: new google.maps.LatLng(
129								val.latitude,
130								val.longitude
131							)
132						} );
133					} );
134
135					// 開始地点と終了地点、ルーティングの種類の設定
136					var request = {
137						origin: wayPoints[0].location,
138						destination: wayPoints.pop().location,
139						travelMode: google.maps.DirectionsTravelMode.DRIVING, // or BICYCLING, TRANSIT, WALKING
140						waypoints: wayPoints
141					};
142
143					// ルート検索を行う
144					var directionsService = new google.maps.DirectionsService();
145					directionsService.route( request, function( result, status ) {
146						if ( status == google.maps.DirectionsStatus.OK ) {
147							directionsRenderer.setDirections( result );
148							directionsRenderer.setOptions( {
149								suppressMarkers: true
150							} );
151						}
152					} );
153				}
154
155				// アイコン
156				var getIcon = function( key ) {
157					if ( useRoute === true ) {
158						return 'http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=' + ( key + 1 ) + '|F96757|000000';
159					}
160					return '';
161				}
162
163				var minLat = data.points[0].latitude;
164				var maxLat = data.points[0].latitude;
165				var minLng = data.points[0].longitude;
166				var maxLng = data.points[0].longitude;
167
168				var currentInfoWindow = null;
169				$.each( data.points, function( key, val ) {
170					var marker = new google.maps.Marker( {
171						position: new google.maps.LatLng(
172							val.latitude,
173							val.longitude
174						),
175						draggable: val.draggable,
176						map: map,
177						icon: getIcon( key )
178					} );
179
180					if ( typeof( val.title != 'undefined' ) ) {
181						var infowindow = new google.maps.InfoWindow( {
182							content: val.title
183						} );
184						google.maps.event.addListener( marker, 'click', function() {
185							if ( currentInfoWindow ) {
186								currentInfoWindow.close();
187							}
188							infowindow.open( map, marker );
189							currentInfoWindow = infowindow;
190						} );
191					}
192
193					if ( data.points.length > 1 ) {
194						var Lat = val.latitude;
195						var Lng = val.longitude;
196						//中心座標を取得するため、緯度経度の最小値と最大値を取得する
197						if ( Lat < minLat ) minLat = Lat;
198						if ( Lat > maxLat ) maxLat = Lat;
199						if ( Lng < minLng ) minLng = Lng;
200						if ( Lng > maxLng ) maxLng = Lng;
201					}
202
203					render_geocode( data, map, marker );
204				} );
205
206				if ( data.points.length > 1 ) {
207					//北西端の座標を設定
208					var sw = new google.maps.LatLng( maxLat, minLng );
209					//東南端の座標を設定
210					var ne = new google.maps.LatLng( minLat, maxLng );
211					//範囲を設定
212					var bounds = new google.maps.LatLngBounds( sw, ne );
213					//マーカーが全て収まるように地図の中心とズームを調整して表示
214					map.fitBounds( bounds );
215				} else {
216					var latlng = new google.maps.LatLng( data.points[0].latitude, data.points[0].longitude );
217					map.setCenter( latlng );
218				}
219
220			} );
221		},
222
223		/**
224		 * geocode
225		 * geocode用のテキストフィールド等を定義
226		 * テキストボックスから住所を取得
227		 * 検索ボタン, 住所フィールド, 緯度フィールド, 経度フィールドが必要
228		 * config.points.length == 1 のときのみ
229		 */
230		geocode: function( params ) {
231			return this.each( function() {
232				var data = $( this ).data( plugname );
233				var defaults = {
234					btn      : '',
235					address  : '',
236					latitude : '',
237					longitude: ''
238				}
239				data.geocode = $.extend( defaults, params );
240			})
241		},
242
243		/**
244		 * useRoute
245		 * ルートサービスを使用する
246		 */
247		useRoute: function() {
248			useRoute = true;
249		}
250	};
251
252	function render_geocode( data, map, marker ) {
253		if ( !(
254			 typeof( data.geocode.btn ) !== 'undefined' &&
255			 typeof( data.geocode.address ) !== 'undefined' &&
256			 typeof( data.geocode.latitude ) !== 'undefined' &&
257			 typeof( data.geocode.longitude ) !== 'undefined' &&
258			 typeof( data.geocode.zoom ) !== 'undefined' &&
259			 data.geocode.btn.length &&
260			 data.geocode.address.length &&
261			 data.geocode.latitude.length &&
262			 data.geocode.longitude.length &&
263			 data.geocode.zoom.length &&
264			 data.points.length == 1 )
265			)
266			return true;
267
268		data.geocode.btn.click( function() {
269			var geocoder = new google.maps.Geocoder();
270			// ジオコーディングを依頼する
271			geocoder.geocode(
272				{
273					address: data.geocode.address.val()
274				},
275				function( results, status ) {
276					if ( status == google.maps.GeocoderStatus.OK ) {
277						map.setCenter(results[0].geometry.location);
278						marker.setOptions({
279							position: results[0].geometry.location
280						});
281						setInputValueLatLng( results[0].geometry.location.lat(), results[0].geometry.location.lng() );
282					} else {
283						alert( 'Failed!' );
284					}
285				}
286			);
287		} );
288
289		// マーカーのドロップ(ドラッグ終了)時のイベント
290		google.maps.event.addListener( marker, 'dragend', function( event ) {
291			var latlng = new google.maps.LatLng( event.latLng.lat(), event.latLng.lng() );
292			map.setCenter( latlng );
293			data.geocode.address.val( '' );
294			setInputValueLatLng( event.latLng.lat(), event.latLng.lng() );
295		} );
296
297		google.maps.event.addListener( map, 'zoom_changed', function() {
298			var zoom = map.getZoom();
299			data.geocode.zoom.val( zoom );
300		} );
301
302		function setInputValueLatLng( lat, lng ) {
303			data.geocode.latitude.val( lat );
304			data.geocode.longitude.val( lng );
305		}
306	}
307
308	$.fn[plugname] = function( method ) {
309		if ( methods[method] ) {
310			return methods[method]
311			.apply( this, Array.prototype.slice.call( arguments, 1 ) );
312		} else if ( typeof method === 'object' || ! method ) {
313			return methods.init.apply( this, arguments );
314		} else {
315			$.error( 'Method ' +  method + ' does not exist on jQuery.' + plugname );
316			return this;
317		}
318	};
319} )( jQuery );

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.