gpt4 book ai didi

javascript - polymer 点覆盖点击

转载 作者:行者123 更新时间:2023-12-02 14:03:21 25 4
gpt4 key购买 nike

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

<!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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com