
お世話になっております。
初心者質問で申し訳ございません。
前提
kintoneの一覧画面で日付フォームとボタンを設置し、
ボタンをクリックすると、
日付フォームに入力された日でkintoneに登録された、複数レコードの住所に
ピンを打った地図が別ウィンドウで表示されます。
地図はGooglemapが表示されます。
GooglemapAPIを用いて実装しております。
実現したいこと
表示された地図から動かそうとするも、クリックがきかない。
矢印キーでしか移動できない。
発生している問題・エラーメッセージ
エラーは出ておりません。
該当のソースコード
JavaScript
1// 日付フォーム、ボタン設置 2(function () { 3 "use strict"; 4 kintone.events.on('app.record.index.show', function (event) { 5 var ele = document.getElementById("memo"); 6 // 日付入力欄 要素ノードを作る 7 var mapDate = document.createElement('input'); 8 mapDate.type = 'date'; 9 mapDate.id = 'mapDate'; 10 // ボタン 要素ノードを作る 11 var mapBtn = document.createElement('input'); 12 mapBtn.type = 'button'; 13 mapBtn.id = 'mapBtn'; 14 mapBtn.value = 'map'; 15 var parenteles = document.getElementsByClassName("calendar-menu-gaia"); 16 var parentele = parenteles[0]; 17 parentele.insertBefore(mapBtn, ele.nextSibling); 18 parentele.insertBefore(mapDate, ele.nextSibling); 19 20 //ボタンクリックのイベント 21 var myWindow; 22 document.getElementById('mapBtn').onclick = function () { 23 //日付フォームの日付を取得 24 var date = document.getElementById("mapDate").value; 25 var lat = []; 26 var lng = []; 27 var recno = []; 28 var day = []; 29 var rec, i; 30 // レコード情報を取得します 31 rec = event['records']; 32 let recs = Object.keys(rec); 33 // 一覧に表示されているすべてのレコードの緯度・経度と名前を配列に格納します 34 for (i = 0; i < recs.length; i += 1) { 35 let index = recs[i]; 36 for (let j = 0; j < rec[index].length; j += 1) { 37 if (rec[index][j].lat.value !== undefined && rec[index][j].lng.value !== undefined) { 38 if (rec[index][j].lat.value.length > 0 && rec[index][j].lng.value.length > 0) { 39 lat.push(parseFloat(rec[index][j].lat.value)); // 緯度 40 lng.push(parseFloat(rec[index][j].lng.value)); // 経度 41 recno.push(rec[index][j].name.value); // 名前 42 day.push(rec[index][j].day.value); // 宅配日 43 } 44 } 45 } 46 } 47 // 新規ウィンドウ起動 48 myWindow = window.open("", "myWindow", "width=600px,height=600px"); 49 myWindow.document.write("<div id='map' style='width:100%;height:100%'></div>"); 50 51 var point = new google.maps.LatLng(lat[0], lng[0]); 52 // 地図の表示の設定(中心の位置、ズームサイズ等)を設定します 53 var opts = { 54 zoom: 15, 55 center: point, 56 mapTypeId: google.maps.MapTypeId.ROADMAP, 57 scaleControl: true, 58 clickable: true 59 }; 60 // 地図の要素を定義します 61 var map = new google.maps.Map(myWindow.document.getElementById('map'), opts); 62 var marker = []; 63 var m_latlng = []; 64 var dayLat = []; 65 var dayLng = []; 66 67 // 緯度・経度をもとに、地図にポインタを打ち込みます 68 for (i = 0; i < lat.length; i += 1) { 69 if (isNaN(lat[i]) === false && isNaN(lng[i]) === false) { 70 if (date === day[i]) { 71 m_latlng[i] = new google.maps.LatLng(lat[i], lng[i]); 72 dayLat.push(lat[i]); 73 dayLng.push(lng[i]); 74 marker[i] = new google.maps.Marker({ 75 position: m_latlng[i], 76 map: map, 77 // ポインタのアイコンは Google Charts を使用します 78 icon: 'https://chart.googleapis.com/chart?chst=d_bubble_text_small&chld=edge_bc|' + recno[i] + '|FF8060|000000' 79 }); 80 } 81 } 82 } 83 // マーカーがすべて表示するよう調整 84 map.fitBounds(new google.maps.LatLngBounds( 85 // sw 86 { 87 lat: Math.min(...dayLat), 88 lng: Math.min(...dayLng) 89 }, 90 // ne 91 { 92 lat: Math.max(...dayLat), 93 lng: Math.max(...dayLng) 94 } 95 )); 96 97 // 「position: relative」を外さないと地図が表示されないがラグが必要のため1秒後に実行 98 setTimeout(() => { 99 myWindow.document.getElementById('map').style.position = ""; 100 }, 1500); 101 } 102 }); 103})();
原因をご教授いただければ幸いです。
以上、よろしくお願いいたします。




あなたの回答
tips
プレビュー