gpt4 book ai didi

javascript - 矢量 map 中不同端口的不同样式

转载 作者:行者123 更新时间:2023-11-30 16:42:15 25 4
gpt4 key购买 nike

大家好,这是我的 JavaScript 代码,用于为矢量 map 制作 ip 标记以显示在线 ip..

所有 ips 都有 3 个不同的端口,例如:ip1:1020 或 ip2:5050 或 ip3:6969

我可以从 ip.txt 文件中读取的 ips 格式如下:

{"relays":[{
"or_addresses":["2.176.82.122:1020"],"latitude":35.6961059570313,"longitude":51.423095703125},
{"or_addresses":["2.177.37.250:5050"],"latitude":35.6961059570313,"longitude":51.423095703125},
{"or_addresses":["2.178.57.250:6969"],"latitude":35.6961059570313,"longitude":51.423095703125},
{"or_addresses":["2.18.5.20:5050"],"latitude":35.6961059570313,"longitude":51.423095703125},
{"or_addresses":["2.78.7.25:1020"],"latitude":35.6961059570313,"longitude":51.423095703125}
]}

这是我的主要脚本

<script>
$(document).ready(function(){
$('#worldmap').vectorMap({
map: 'world_mill_en',
scaleColors: ['#C8EEFF', '#0071A4'],
normalizeFunction: 'polynomial',
hoverOpacity: 0.7,
hoverColor: false,
markerStyle: {
initial: {
fill: '#cc6600',
stroke: '#222222',
r: 2
}
},
backgroundColor: '#CCC',
markers: [
]
});

map = $('#worldmap').vectorMap('get', 'mapObject');
$.getJSON('http://127.0.0.1/bantools/ip/ip.txt', function(data){
$.each(data.relays, function(idx, relay)
{
map.addMarker(relay.or_addresses[0], {'latLng' : [relay.latitude, relay.longitude], "name" : relay.or_addresses[0]});
});
});
});
</script>

我的问题是如何为不同的端口制作不同的样式????!我的意思是我想对 port = 1020 使用这种样式:

markerStyle: {
initial: {
fill: '#cc6600',
stroke: '#222222',
r: 2
}
}

对于 port = 5050 我想使用这种风格:

markerStyle: {
initial: {
fill: '#aaa',
stroke: '#bbb',
r: 2
}
}

对于其他端口...

最佳答案

http://jsbin.com/womoqa/edit?js,output

$(function(){
$('#world-map-markers').vectorMap({
map: 'world_mill_en',
scaleColors: ['#C8EEFF', '#0071A4'],
normalizeFunction: 'polynomial',
hoverOpacity: 0.7,
hoverColor: false,
backgroundColor: '#383f47',
markers: [
{latLng: [41.90, 12.45], name: 'Vatican City',
style: {
fill: '#cc6600',
stroke: '#222222',
r: 5
}},
{latLng: [17.11, -61.85], name: 'Antigua and Barbuda',
style: {
fill: '#ff0000',
stroke: '#222222',
r: 8
}},
{latLng: [0.33, 6.73], name: 'São Tomé and Príncipe',
style:{
fill: '#F8E23B',
stroke: '#383f47'
}}
]
});
});
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-1.11.3.js"></script>
<script src="http://jvectormap.com/js/jquery-jvectormap-2.0.2.min.js"></script>
<script src="http://jvectormap.com/js/jquery-jvectormap-world-mill-en.js"></script>
<link rel="stylesheet" href="http://jvectormap.com/css/jquery-jvectormap-2.0.2.css">
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<div id="world-map-markers" style="width: 720px; height: 400px"></div>
</body>
</html>

关于javascript - 矢量 map 中不同端口的不同样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31773927/

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