2016-10-24 5 views
0

このガイドの後、プロジェクトを正しく実行できるようになりました。次に、描画されたポイントのイベントを追加します。だから、これは私のコードです:ポリマーのポイントオーバーレイをクリック

<!doctype html> 

<html> 
<head> 
    <title>PolymerVizCodelab</title> 

    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"> 
    <meta name="mobile-web-app-capable" content="yes"> 
    <meta name="apple-mobile-web-app-capable" content="yes"> 

    <script src="bower_components/webcomponentsjs/webcomponents-lite.min.js"></script> 

    <link rel="import" href="bower_components/google-map/google-map.html"> 
    <link rel="import" href="bower_components/point-overlay/point-overlay.html"> 
    <link rel="import" href="bower_components/paper-card/paper-card.html"> 
    <link rel="import" href="bower_components/paper-slider/paper-slider.html"> 
    <link rel="import" href="bower_components/iron-ajax/iron-ajax.html"> 

    <link rel="stylesheet" href="styles.css"> 
</head> 

<body unresolved> 
    <template is="dom-bind" id="t"> 
    <google-map map="{{map}}" latitude="38.6" longitude="-95.8" zoom="5" 
     styles='[{"stylers":[{"saturation":-85}]},{"featureType":"water","stylers":[{"lightness":-20}]}]' 
     on-google-map-ready="setPointSize" 
     on-zoom-changed="setPointSize"> 
    </google-map> 
    <point-overlay on-click="clickHandler" map="[[map]]" uniforms="{{uniforms}}" data="{{data}}" id="p"> 
    </point-overlay> 
    <iron-ajax auto handle-as="json" 
     url="bower_components/point-overlay/tornadoes-1950-2014.json" 
     last-response="{{data}}"> 
    </iron-ajax> 

    <!-- <paper-card elevation="2"> 
     <paper-slider min="5" max="100" value="30"></paper-slider> 
    </paper-card> --> 
    </template> 

    <script> 
    var t = document.querySelector('#t'); 
    t.setPointSize = function(e) { 
     this.uniforms.pointSize = Math.exp(0.3 * this.map.getZoom()); 
     this.notifyPath('uniforms.pointSize', this.uniforms.pointSize); 
    }; 
    function clickHandler(e) { 
     console.log("click"); 
    } 
    </script> 
</body> 
</html> 

しかしclickHandlerは解雇されることはありません。

マップ上の各ポイントをバインドしてイベントを発生させるにはどうすればよいですか?

答えて

1

clickHandlerは、setPointSizeで行ったように、dom-bindテンプレートの一部である必要があります。これに

function clickHandler(e) { 
    console.log("click"); 
} 

:これを変更

t.clickHandler = function(e) { 
    console.log("click"); 
}; 
+0

私はその機能を変更したが、それは何も表示されません。 'point-overlay'は、クリックやピッキングのためのメソッドを持つ必要はありませんか? – FacundoGFlores

1

残念ながらpoint-overlayはほかに、Googleマップ上にデータを視覚化するためにpoint-overlayで使用されCanvasLayerマップ層がトリガーにマウスイベントを防止し、任意のイベントを公開しません。イベントリスナー。

しかし、以下に示すようにpolymer-webgl-visualization componentに印加されるいくつかの変更とそれがacomplishedすることができる:

canvas-layer.jsファイルで:

1)オーバーレイ要素にイベントリスナーをトリガするマウスイベントを防止する行をコメントは(CanvasLayer ):

canvas.style.pointerEvents = 'none'; 

変更point-overlay要素(point-overlay.htmlファイル)

ファイル内

var me = this; 
google.maps.event.addDomListener(this.overlay.canvas, 'click', function() { 
    me.fire('overlay-click'); 
}); 

そして最後に:

2)は、canvas要素のためのclickイベントハンドラ紹介)overlayMouseTarget

this.overlay.setPaneName("overlayMouseTarget"); 

3にマップペインを設定

4)clickHandlerイベントハンドラ

を登録
<point-overlay on-overlay-click="clickHandler" map="[[map]]" uniforms="{{uniforms}}" data="{{data}}" id="p"> 
</point-overlay> 

どこ

var t = document.querySelector('#t'); 
t.clickHandler = function(e) { 
    console.log('clicked'); 
}; 

Working example

+1

こんにちは私はあなたのアプローチが好きでしたが、地図のどこかをクリックするとアラートが表示されますが、ポイントをクリックしたときだけ必要です – FacundoGFlores

関連する問題