###前提・実現したいこと
wordpressにて開発を行っていまして。
javascriptをgulpで一つにまとめて圧縮しているのですが、googlemapを埋め込んだ時に、googlemapを配置しているページ以外でも読み込もうとしてしまっているようで、それを止めるために。
googlemapが配置しているページだけで作動するようにif関数を入れたいのですが、どこに入れてもうまくいきません。
if関数以外を使うのがいいのか、そもそも圧縮しない方がいいのか教えていただければ嬉しいです。
###発生している問題・エラーメッセージ
エラーメッセージ
###該当のソースコード
function initialize() { var latlng = new google.maps.LatLng();/*表示したい場所の経度、緯度*/ var myOptions = { zoom: 14, /*拡大比率*/ center: latlng, /*表示枠内の中心点*/ disableDefaultUI: true, mapTypeId: google.maps.MapTypeId.ROADMAP }; var map = new google.maps.Map(document.getElementById('access_map'), myOptions); /*スタイルのカスタマイズ*/ var styleOptions = [ { featureType: "all", elementType: "all", stylers: [ { hue: "#FFD500" }, { visibility: "on" }, { lightness: -5 }, { saturation: -56 } ] } ]; var lopanType = new google.maps.StyledMapType(styleOptions); map.mapTypes.set('noText', lopanType); map.setMapTypeId('noText'); // var styledMapOptions = { name: '' } // var sampleType = new google.maps.StyledMapType(styleOptions, styledMapOptions); // map.mapTypes.set('sample', sampleType); // map.setMapTypeId('sample'); var icon = new google.maps.MarkerImage('',/ new google.maps.Size(80,80),/ new google.maps.Point(0,0)/ ); /*マーカーの設置*/ var markerOptions = { position: latlng, map: map, icon: icon, title: '' }; var marker = new google.maps.Marker(markerOptions); } if ($('.access').length){ google.maps.event.addDomListener(window, 'load', initialize); }; google.maps.event.addDomListener(window, 'load', initialize); google.maps.event.addDomListener(window, 'resize', function(){ map.panTo(mapOptions.center); });
###試したこと
if(getElementByid('access_map')を冒頭に入れて、
googlemapを配置するページにもIDでaccess_mapというタグを設定したりしてみたのですが、googlemap自体が起動しなくなってしまいます。
bodyタグには<body onload="initialize()">というのが入っています。
###補足情報(言語/FW/ツール等のバージョンなど)
より詳細な情報
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。