javascript - polymer 点覆盖点击

标签 javascript google-maps polymer

按照本指南我可以正确运行项目,现在我想为绘制的点添加一个事件。这是我的代码:

<!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 从未被触发。

如何为 map 上的每个点绑定(bind)和事件?

最佳答案

clickHandler 需要成为 dom-bind 模板的一部分(就像您使用 setPointSize 所做的那样)。更改此:

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

对此:

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

关于javascript - polymer 点覆盖点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40226660/

相关文章:

javascript - 使用 jsPDF 创建的 pdf 中的重复内容

javascript - 如何访问 Thunderbird 消息撰写窗口中的消息内容?

javascript - Mapbox 不再与 Leaflet 一起使用

dart - bwu_datagrid polymer 1:div内的高度为100%

javascript - polymer Javascript。在点击事件时无法将数据传递到其他 polymer 元素而不调用 polymer 元素

javascript - 无论起点如何,如何检查视频是否连续播放 30 秒?

javascript - 等待递归函数时获取未定义的结果

android - 谷歌地图 REST API

javascript - 谷歌地图现在显示标记是我添加自定义图标

polymer - 如何在 Polymer2 中使用带有数据绑定(bind)的插槽注入(inject)模板