質問編集履歴
1
JS指摘部分修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -295,3 +295,169 @@
|
|
295
295
|
どなたかお助け下さい。
|
296
296
|
|
297
297
|
宜しくお願い致します。
|
298
|
+
|
299
|
+
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
###JSコード追記部分
|
306
|
+
|
307
|
+
```
|
308
|
+
|
309
|
+
var mclick = [];
|
310
|
+
|
311
|
+
(function($) {
|
312
|
+
|
313
|
+
function new_map( $el ) {
|
314
|
+
|
315
|
+
var $markers = $el.find('.marker' ,'.marker_click');
|
316
|
+
|
317
|
+
var args = {
|
318
|
+
|
319
|
+
zoom : 16,
|
320
|
+
|
321
|
+
center : new google.maps.LatLng(0, 0),
|
322
|
+
|
323
|
+
mapTypeId : google.maps.MapTypeId.ROADMAP
|
324
|
+
|
325
|
+
};
|
326
|
+
|
327
|
+
// create map
|
328
|
+
|
329
|
+
var map = new google.maps.Map( $el[0], args);
|
330
|
+
|
331
|
+
// add a markers reference
|
332
|
+
|
333
|
+
map.markers = [];
|
334
|
+
|
335
|
+
// add markers
|
336
|
+
|
337
|
+
$markers.each(function(){
|
338
|
+
|
339
|
+
mclick.push( add_marker( $(this), map ) );
|
340
|
+
|
341
|
+
});
|
342
|
+
|
343
|
+
// center map
|
344
|
+
|
345
|
+
center_map( map );
|
346
|
+
|
347
|
+
// return
|
348
|
+
|
349
|
+
return map;
|
350
|
+
|
351
|
+
}
|
352
|
+
|
353
|
+
|
354
|
+
|
355
|
+
function add_marker( $marker, map ) {
|
356
|
+
|
357
|
+
var latlng = new google.maps.LatLng( $marker.attr('data-lat'), $marker.attr('data-lng') );
|
358
|
+
|
359
|
+
// create marker
|
360
|
+
|
361
|
+
var marker = new google.maps.Marker ({
|
362
|
+
|
363
|
+
position : latlng,
|
364
|
+
|
365
|
+
map : map
|
366
|
+
|
367
|
+
});
|
368
|
+
|
369
|
+
// add to array
|
370
|
+
|
371
|
+
map.markers.push( marker );
|
372
|
+
|
373
|
+
// if marker contains HTML, add it to an infoWindow
|
374
|
+
|
375
|
+
if( $marker.html() )
|
376
|
+
|
377
|
+
{
|
378
|
+
|
379
|
+
// create info window
|
380
|
+
|
381
|
+
var infowindow = new google.maps.InfoWindow({
|
382
|
+
|
383
|
+
content : $marker.html()
|
384
|
+
|
385
|
+
});
|
386
|
+
|
387
|
+
// show info window when marker is clicked
|
388
|
+
|
389
|
+
google.maps.event.addListener(marker, 'click', function() {
|
390
|
+
|
391
|
+
infowindow.open( map, marker );
|
392
|
+
|
393
|
+
});
|
394
|
+
|
395
|
+
}
|
396
|
+
|
397
|
+
return marker;
|
398
|
+
|
399
|
+
}
|
400
|
+
|
401
|
+
|
402
|
+
|
403
|
+
function center_map( map ) {
|
404
|
+
|
405
|
+
var bounds = new google.maps.LatLngBounds();
|
406
|
+
|
407
|
+
// loop through all markers and create bounds
|
408
|
+
|
409
|
+
$.each( map.markers, function( i, marker ){
|
410
|
+
|
411
|
+
var latlng = new google.maps.LatLng( marker.position.lat(), marker.position.lng() );
|
412
|
+
|
413
|
+
bounds.extend( latlng );
|
414
|
+
|
415
|
+
});
|
416
|
+
|
417
|
+
// only 1 marker?
|
418
|
+
|
419
|
+
if( map.markers.length == 1 )
|
420
|
+
|
421
|
+
{
|
422
|
+
|
423
|
+
// set center of map
|
424
|
+
|
425
|
+
map.setCenter( bounds.getCenter() );
|
426
|
+
|
427
|
+
map.setZoom( 16 );
|
428
|
+
|
429
|
+
}
|
430
|
+
|
431
|
+
else
|
432
|
+
|
433
|
+
{
|
434
|
+
|
435
|
+
// fit to bounds
|
436
|
+
|
437
|
+
map.fitBounds( bounds );
|
438
|
+
|
439
|
+
}
|
440
|
+
|
441
|
+
}
|
442
|
+
|
443
|
+
|
444
|
+
|
445
|
+
// global var
|
446
|
+
|
447
|
+
var map = null;
|
448
|
+
|
449
|
+
$(document).ready(function(){
|
450
|
+
|
451
|
+
$('.acf-map').each(function(){
|
452
|
+
|
453
|
+
// create map
|
454
|
+
|
455
|
+
map = new_map( $(this) );
|
456
|
+
|
457
|
+
});
|
458
|
+
|
459
|
+
});
|
460
|
+
|
461
|
+
})(jQuery);
|
462
|
+
|
463
|
+
```
|