Polyline: dblclick
dblclickはPolylineクラスのイベントです。ポリラインをダブルクリックした時に発火します。
引数
PolyMouseEvent
コールバック関数には引数でPolyMouseEventオブジェクトが渡される。
デモ
ポリラインをダブルクリックする度にイベントが発火するのを確認して下さい。
var polyline = new google.maps.Polyline( {
map: map ,
path: [
new google.maps.LatLng( 35.794507, 139.790788 ) ,
new google.maps.LatLng( 35.794007, 139.791788 ) ,
] ,
strokeWeight: 12 ,
editable: true ,
} ) ;
// Event
polyline.addListener( "dblclick", function ( argument ) {
console.log( argument ) ;
} ) ;
サンプルコード
設定例
// イベントの設定 (基本)
var listener = google.maps.event.addListener( polyline, "dblclick", callbackFunc ) ;
// イベントの設定 (ショートカット版)
var listener = polyline.addListener( "dblclick", callbackFunc ) ;
// イベントの設定 (1度だけ発火)
google.maps.event.addListenerOnce( polyline, "dblclick", callbackFunc ) ;
// トリガーで任意のタイミングで発火
google.maps.event.trigger( polyline, "dblclick" ) ;
// イベントの解除 (リスナー変数で指定)
google.maps.event.removeListener( listener ) ;
// イベントの解除 (インスタンスとイベント名で指定)
google.maps.event.clearListeners( polyline, "dblclick" ) ;
HTML
<!DOCTYPE html>
<html>
<head>
<style>
#map-canvas {
width: 600px ;
height: 600px ;
}
</style>
</head>
<body>
<div id="map-canvas"></div>
<p><textarea id="count">0</textarea></p>
<p><textarea id="argument"></textarea></p>
<script src="//maps.googleapis.com/maps/api/js?key={APIキー}"></script>
<script>
var mapDiv = document.getElementById( "map-canvas" ) ;
var countElement = document.getElementById( "count" ) ;
var argumentElement = document.getElementById( "argument" ) ;
// Map
var map = new google.maps.Map( mapDiv, {
center: new google.maps.LatLng( 35, 139 ) ,
zoom: 18 ,
} ) ;
// Polyline
var polyline = new google.maps.Polyline( {
map: map ,
path: [
new google.maps.LatLng( 35.794507, 139.790788 ) ,
new google.maps.LatLng( 35.794007, 139.791788 ) ,
] ,
strokeWeight: 12 ,
editable: true ,
} ) ;
// fit bounds
var latLngBounds = new google.maps.LatLngBounds() ;
polyline.getPath().forEach( function ( latLng ) {
latLngBounds.extend( latLng ) ;
} ) ;
map.fitBounds( latLngBounds ) ;
// Event
polyline.addListener( "dblclick", function ( argument ) {
countElement.value = Number( countElement.value ) + 1 ;
try{ argument = typeof argument == "object" ? JSON.stringify( argument ) : argument ; }catch(e){}
argumentElement.value = argument ;
console.log( argument ) ;
} ) ;
</script>
</body>
</html>