jquery - jQuery mapael 动态绘图
问题描述
我搜索了该网站,但没有找到。我正在通过谷歌分析获取数据。我正在尝试创建动态图。我在哪里做错了?非常感谢各位帮手。
json数据的坐标是正确的。
我为此地图创建的代码:
function initMap(arr) {
var $map = $('#map'),
state;
$map.mapael({
map: {
name: "turkey",
defaultArea: {
attrs: {
fill: '#242424',
stroke: Sing.colors['body-bg'],
},
attrsHover: {
fill: '#e9ebf6',
animDuration: 100
},
tooltip: {
content: function() {
return '<strong>' + state + '</strong>';
}
},
eventHandlers: {
mouseover: function(e, id) {
state = id;
}
}
},
defaultPlot: {
size: 17,
attrs: {
fill: Sing.colors['brand-warning'],
stroke: Sing.colors['white'],
"stroke-width": 0,
"stroke-linejoin": "round"
},
attrsHover: {
"stroke-width": 1,
animDuration: 100
}
},
zoom: {
enabled: true,
step: 0.75
}
},
plots: {
arr
}
});
console.log(arr);
//ie svg height fix
function _fixMapHeight() {
$map.find('svg').css('height', function() {
return $(this).attr('height') + 'px';
});
}
_fixMapHeight();
SingApp.onResize(function() {
setTimeout(function() {
_fixMapHeight();
}, 100)
});
}
这是我发送的 json 数据:
"e0" : {latitude:39.9334, longitude: 32.8597, tooltip: { content : "Ankara"} },"e1" : {latitude:41.0082, longitude: 28.9784, tooltip: { content : "Istanbul"} },"e2" : {latitude:38.4237, longitude: 27.1428, tooltip: { content : "Izmir"} },"e3" : {latitude:38.4237, longitude: 27.1428, tooltip: { content : "Izmir"} },"e4" : {latitude:38.4237, longitude: 27.1428, tooltip: { content : "Izmir"} },"e5" : {latitude:38.4237, longitude: 27.1428, tooltip: { content : "Izmir"} },"e6" : {latitude:54.3081, longitude: 9.6607, tooltip: { content : "Rendsburg"} }
当我使用这个例子时,我没有任何问题。
'paris' : {
latitude : 48.86,
longitude: 2.3444
},
'lyon' : {
type: "circle",
size:50,
latitude :45.758888888889,
longitude: 4.8413888888889,
value : 700000,
href : "http://fr.wikipedia.org/wiki/Lyon",
tooltip: {content : "<span style=\"font-weight:bold;\">City :</span> Lyon"},
text : {content : "Lyon"}
},
'rennes' : {
type :"square",
size :20,
latitude : 48.114166666667,
longitude: -1.6808333333333,
tooltip: {content : "<span style=\"font-weight:bold;\">City :</span> Rennes"},
text : {content : "Rennes"},
href : "http://fr.wikipedia.org/wiki/Rennes"
}
解决方案
我以这种方式解决了我的问题。
var updatedOptions = {'areas' : {}, 'plots' : {}};
eval('var newPlots={' + data.slice(0, -1) + '}');
$(".mapael").trigger('update', [updatedOptions, newPlots]);
推荐阅读
- python - 将 SED 命令转换为 linux 命令
- windows - 在 Windows 10 上使用空格的目录中运行包时出现问题
- clojure - 如何在 Clojure 中模拟来自自定义 IP 地址的请求?
- reactjs - 将 React 与 KeyCloak 一起使用 - 你真的需要存储 JWT 吗?
- javascript - 将字符串数组转换为具有一个属性的对象数组?
- c++ - Lua嵌入C++,如何处理用户值
- multiplayer - Raft 与 CRDT 在协作编辑方面如何比较?
- c - 当 char 数据类型在 scanf 中获取带有 %d 的整数值时会发生什么?
- r - 如何更改R中点的大小
- cucumber - Cucumber 无法正确生成步骤