svg insert shape string bug

not support custom areaProps attributes ???


const svg = document.querySelector(`[data-uuid="live_map_svg"]`); svg.insertAdjacentHTML(`beforeend`, svgPolygon); svgPolygon = `<polygon stroke="" fill="#DB524F" points="454.99798583984375 586.333984375 534.9979858398438 586.333984375 534.9979858398438 719.6680297851562 454.99798583984375 719.6680297851562" center='{"x":494.99798583984375,"y":653.0010070800781}' areaprops='{"id":10202,"activityEventId":2801,"ticketCategoryId":11201,"desc":"_贵宾区","name":"贵宾区","floor":0,"sort":0,"status":1} uuid="polygon_1583483461614_10045"></polygon>` // "<polygon stroke="" fill="#DB524F" points="454.99798583984375 586.333984375 534.9979858398438 586.333984375 534.9979858398438 719.6680297851562 454.99798583984375 719.6680297851562" center='{"x":494.99798583984375,"y":653.0010070800781}' areaprops='{"id":10202,"activityEventId":2801,"ticketCategoryId":11201,"desc":"_贵宾区","name":"贵宾区","floor":0,"sort":0,"status":1} uuid="polygon_1583483461614_10045"></polygon>" svg.insertAdjacentHTML(`beforeend`, svgPolygon); svgPolygon = `<polygon stroke="" fill="#DB524F" points="454.99798583984375 586.333984375 534.9979858398438 586.333984375 534.9979858398438 719.6680297851562 454.99798583984375 719.6680297851562" uuid="polygon_1583483461614_10045"></polygon>`
// "<polygon stroke="" fill="#DB524F" points="454.99798583984375 586.333984375 534.9979858398438 586.333984375 534.9979858398438 719.6680297851562 454.99798583984375 719.6680297851562" uuid="polygon_1583483461614_10045"></polygon>" svg.insertAdjacentHTML(`beforeend`, svgPolygon); svgPolygon = `<text x="494.99798583984375" y="653.0010070800781" fill="#000" uuid="area_1583483461614_10045">贵宾区</text>`
// "<text x="494.99798583984375" y="653.0010070800781" fill="#000" uuid="area_1583483461614_10045">贵宾区</text>" svg.insertAdjacentHTML(`beforeend`, svgPolygon);

solution

missing ' single quote bug ️

OK


const computePolygonCenterPoint = (points = []) => {
// 设置旋转的 origin,为 polygon 的中心,旋转偏移量
let [top, left, right, bottom] = ["", "", "", ""];
points.forEach(([x, y], i) => {
if (i === 0) {
top = y;
bottom = y;
left = x;
right = x;
} else {
top = Math.min(top, y);
bottom = Math.max(bottom, y);
left = Math.min(left, x);
right = Math.max(right, x);
}
});
const point = {
cx: (left + right) / 2,
cy: (top + bottom) / 2,
};
return point;
} const polygonGenerator = (feature = {}, uuid = ``, areaUuid, offsetFlag = false) => {
const {
properties: {
labelPoint,
fill,
stroke,
type,
// text === name / desc,
id,
activityEventId,
ticketCategoryId,
desc,
name,
floor,
sort,
status,
},
geometry: {
coordinates,
},
} = feature;
const points = coordinates.flat(3).join(` `);
const points_arr = coordinates[0];
let x = 0;
let y = 0;
if(!labelPoint) {
const {
cx,
cy,
} = computePolygonCenterPoint(points_arr);
x = cx;
y = cy;
} else {
const {
x: cx,
y: cy,
} = labelPoint;
x = cx;
y = cy;
}
// svg 绑定区域的 text 偏移量优化 ??? offsetFlag ? +number : -number
const xOffset = 20;
const yOffset = -10;
x = x - xOffset;
y = y - yOffset;
const center = JSON.stringify({
x,
y,
});
let result = ``;
// true && number !== boolean
// if (type === "section" && (name.length ? true : false)) {
if (type === "section" && name.length > 0) {
const ticketArea = {
id,
activityEventId,
ticketCategoryId,
desc,
name,
floor,
sort,
status,
};
const areaProps = JSON.stringify(ticketArea);
// areaprops areaProps auto convert to lowercase bug
result = `
<polygon stroke="${stroke || ''}" fill="${fill || polygonFillColor}" points="${points}" center='${center}' areaprops='${areaProps}' uuid="${uuid}"></polygon>
<text x="${x || ''}" y="${y || ''}" fill="${textFillColor}" uuid="${areaUuid}">${name}</text>
`;
} else {
result = `
<polygon stroke="${stroke || ''}" fill="${fill || polygonFillColor}" points="${points}" center='${center}' uuid="${uuid}"></polygon>
`;
}
return result.trim();
}

svg insert shape string bug的更多相关文章

  1. invalid comparison: java.util.ArrayList and java.lang.String——bug解决办法

    今天碰到个问题,解决了很久才搞定,来记录下,希望可以帮助到大家 贴错误源码: 这是一个根据list集合的查找数据的 sql,在接收list的时候加了判断 list != ‘ ’ “”,引起了集合与St ...

  2. JavaScript对SVG进行操作的相关技术

    原文地址:http://www.ibm.com/developerworks/cn/xml/x-svgscript/   本文主要介绍在 SVG 中通过编程实现动态操作 SVG 图像的知识. SVG ...

  3. LeetCode 全解(bug free 训练)

    1.Two Sum Given an array of integers, return indices of the two numbers such that they add up to a s ...

  4. leetcode bug free

    ---不包含jiuzhang ladders中出现过的题.如出现多个方法,则最后一个方法是最优解. 目录: 1 String 2 Two pointers 3 Array 4 DFS &&am ...

  5. how to export svg form web page in js

    how to export svg form web page in js https://stackoverflow.com/questions/2483919/how-to-save-svg-ca ...

  6. Codeforces 710F String Set Quries

    题意 维护一个字符串的集合\(D\), 支持3种操作: 插入一个字符串\(s\) 删除一个字符串\(s\) 查询一个字符串\(s\)在\(D\)中作为子串出现的次数 强制在线 解法 AC自动机+二进制 ...

  7. 主要由顶点容器构成的平面图形类(Shape)——(第一次作业Draw类定义升级)

    // https://github.com/orocos/orocos_kinematics_dynamics/blob/master/orocos_kdl/src/frames.hpp // Vec ...

  8. Lua自己实现string.split功能

    local function split(str, d) --str是需要查分的对象 d是分界符 local lst = { } local n = string.len(str)--长度 local ...

  9. String、StringBuffer、StringBuilder源码解读

    序 好长时间没有认真写博客了,过去的一年挺忙的.负责过数据库.线上运维环境.写代码.Code review等等东西挺多. 学习了不少多方面的东西,不过还是需要回归实际.加强内功,方能扛鼎. 去年学习M ...

随机推荐

  1. WPF排版布局经验总结(干货)简短不疲倦

    本文不过多讲述wpf的基础布局控件,本文只记录WPF排版的技巧,这是个人的总结,不能符合所有情况,如果有何不对的地方,请评论指正,谢谢. 1.区域划分 在接手一个界面的时候,先纵观全局,将眼见的区域划 ...

  2. Python学习【第5篇】:数据类型和变量总结

    字符串,数字,列表,元组,字典 可变不可变 1.可变:列表 如: p.p1 { margin: 0; font: 11px Menlo; color: rgba(0, 0, 0, 1); backgr ...

  3. 查看Linux用的桌面是GNOME、KDE或者其他(转)

    http://superuser.com/questions/96151/how-do-i-check-whether-i-am-using-kde-or-gnome 1) pgrep -l &quo ...

  4. 利用PWM脉宽调制实现呼吸灯

    1.设计目标 完成一个呼吸灯,从亮到灭的时间为2秒,从灭到亮的时间为2秒,以此不断往复. 2.设计步骤 2.1设计分析 利用PWM(脉冲宽度调制)实现led灯亮度的变化,只需要改变占空比就可以实现,具 ...

  5. 关于cnblogs至github上blog的搬迁

    由于同学的强烈抗议(由于网页太卡,而且还有bug),所以在今天完成了github上blog的搭建,并且有了良好的阅读环境; Leceue

  6. hdu5627 Clarke and MST (并查集)

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission ...

  7. 动态链接库(DLL)的创建和使用

    最近想做个记录日志的C++库,方便后续使用.想着使用动态库,正好没用过,学习下.概念这里不赘述.学习过程中碰到的几点,记录下来.学习是个渐进的过程,本文也是一个逐渐完善的过程. 一.Static Li ...

  8. CF1474-B. Different Divisors

    CF1474-B. Different Divisors 题意: 题目给出你一个\(d\),要求你找出一个数字\(y\),找到的\(y\)至少有四个整数因子并且任意两个因子之间的差至少为\(d\). ...

  9. word2vector代码实践

    引子 在上次的 <word2vector论文笔记>中大致介绍了两种词向量训练方法的原理及优劣,这篇咱们以skip-gram算法为例来代码实践一把. 当前教程参考:A Word2Vec Ke ...

  10. 实战交付一套dubbo微服务到k8s集群(2)之Jenkins部署

    Jenkins官网:https://www.jenkins.io/zh/ Jenkins 2.190.3 镜像地址:docker pull jenkins/jenkins:2.190.3 1.下载Je ...