下記のようなHTMLコードを使った場合に、
HTML
1<!DOCTYPE html> 2<html> 3<head> 4<meta charset="utf-8" /> 5<meta name="viewport" content="width=device-width, initial-scale=1"> 6<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.css" /> 7<style> 8html { width: 100%; height: 100%; } 9body { width: 100%; height: 100%; margin: 0; } 10#map { width: 100%; height: 100%; } 11</style> 12</head> 13<body> 14<div id="map"></div> 15<script src="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.js"></script> 16<script> 17//即時関数 18(function(){ 19 "use strict"; 20 //地図の設定 21 var map = L.map('map').setView( 22 [30.3748331, 130.9574997], 23 14 24 ); 25 //地図タイルの設定 26 L.tileLayer( 27 'http://{s}.tile.osm.org/{z}/{x}/{y}.png', 28 { attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors' } 29 ).addTo(map); 30 //markerとpopupの設定 31 L.marker( 32 [30.3748331, 130.9574997], 33 { title: "marker-title" } 34 ) 35// 以下のコメント部分を有効化してurlなどを指定すればマーカーイメージの変更が可能 36// .setIcon(L.icon({ 37// iconUrl: "http://placehold.jp/cc9999/993333/32x32.png", 38// iconAnchor: [16, 16], 39// popupAnchor: [0,-16] 40// })) 41 .addTo(map) 42 .bindPopup("<h3>test</h3><p>hogehoge</p>") 43 .openPopup(); 44}()); 45</script> 46</body> 47</html>
以下のような感じで、ボタンをクリックした際に、マーカーなどを追加したいと考えています。
HTML
1<input type="Button" onclick="Maker_Add(lat,lon)"/> 2<script type="text/javascript"> 3 function Maker_Add(lat,lon){ 4 var map = L.map('map'); //※1 5 //mapに対して、マーカー(ピン)を追加する処理。 6 //引数の座標を用いて 7 } 8</script>
※1の
javascriipt
1 var map = L.map('map');
の部分で、描画中のmapを取得したいのですが、
initializeが動いて、うまくいきません。
ボタンで、マーカーなどを追加することは可能でしょうか。
また、描画済みの地図を取得するコードはどんな具合にやればよいでしょうか。
ご教授をお願いします。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。