gpt4 book ai didi

javascript - 单击 AmCharts 的自定义标记时触发 Javascript 函数

转载 作者:行者123 更新时间:2023-11-29 23:55:57 27 4
gpt4 key购买 nike

我正在尝试使用具有自定义 HTML 标记的 AmChart 世界地图(就像这个例子:https://www.amcharts.com/demos/custom-html-elements-map-markers/)

我的代码如下,我添加了我希望基于 AmChart 网站上的另一个示例的有效点击监听器。

var map;
map = AmCharts.makeChart( "chartdiv", {
"type": "map",
"theme": "black",
"projection": "miller",

"imagesSettings": {
"rollOverColor": "#42adca",
"rollOverScale": 3,
"selectedScale": 3,
"selectedColor": "#42adca",
"color": "#42adca"
},

"areasSettings": {
"unlistedAreasColor": "#42adca"
},

"dataProvider": {
"map": "worldLow",
"images": [ {
"zoomLevel": 5,
"scale": 0.5,
"title": "San Jose, CA",
"latitude": 37.3382,
"longitude": -121.8863,
"click": 'test()'
}, {
"zoomLevel": 5,
"scale": 0.5,
"title": "Dulles, VA",
"latitude": 38.9559,
"longitude": -77.4478
}, {
"zoomLevel": 5,
"scale": 0.5,
"title": "London, UK",
"latitude": 51.5074,
"longitude": 0.1278
}, {
"zoomLevel": 5,
"scale": 0.5,
"title": "Denver, CO",
"latitude": 39.7392,
"longitude": -104.9903
}, {
"zoomLevel": 5,
"scale": 0.5,
"title": "Miami, FL",
"latitude": 25.7617,
"longitude": -80.1918
}, {
"zoomLevel": 5,
"scale": 0.5,
"title": "Los Angeles, CA",
"latitude": 34.0522,
"longitude": -118.2437
}, {
"zoomLevel": 5,
"scale": 0.5,
"title": "New York, NY",
"latitude": 40.7128,
"longitude": -74.0059
}, {
"zoomLevel": 5,
"scale": 0.5,
"title": "Chicago, IL",
"latitude": 41.8781,
"longitude": -87.6298
} ]
},
"listeners": [{
"event": "clickMapObject",
"method": function(event) {
console.log(event.mapObject.title);
}
}]
} );

但是,console.log 不会触发。单击 map 不会执行任何操作。我可以设置 URL,但我想指定一个 JS 函数。

任何指针都会很棒。

最佳答案

发布后不久,我找到了答案。

'url' 参数就像一个常规的 href,因此,这是有效的:

"dataProvider": {
"map": "worldLow",
"images": [ {
"zoomLevel": 5,
"scale": 0.5,
"title": "San Jose, CA",
"latitude": 37.3382,
"longitude": -121.8863,
"url": 'javascript:test()'
}, {
"zoomLevel": 5,
"scale": 0.5,
"title": "Dulles, VA",
"latitude": 38.9559,
"longitude": -77.4478
}, {

注意 "url": 'javascript:test()'

关于javascript - 单击 AmCharts 的自定义标记时触发 Javascript 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41705367/

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