svg insert shape string bug
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的更多相关文章
- invalid comparison: java.util.ArrayList and java.lang.String——bug解决办法
今天碰到个问题,解决了很久才搞定,来记录下,希望可以帮助到大家 贴错误源码: 这是一个根据list集合的查找数据的 sql,在接收list的时候加了判断 list != ‘ ’ “”,引起了集合与St ...
- JavaScript对SVG进行操作的相关技术
原文地址:http://www.ibm.com/developerworks/cn/xml/x-svgscript/ 本文主要介绍在 SVG 中通过编程实现动态操作 SVG 图像的知识. SVG ...
- 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 ...
- leetcode bug free
---不包含jiuzhang ladders中出现过的题.如出现多个方法,则最后一个方法是最优解. 目录: 1 String 2 Two pointers 3 Array 4 DFS &&am ...
- 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 ...
- Codeforces 710F String Set Quries
题意 维护一个字符串的集合\(D\), 支持3种操作: 插入一个字符串\(s\) 删除一个字符串\(s\) 查询一个字符串\(s\)在\(D\)中作为子串出现的次数 强制在线 解法 AC自动机+二进制 ...
- 主要由顶点容器构成的平面图形类(Shape)——(第一次作业Draw类定义升级)
// https://github.com/orocos/orocos_kinematics_dynamics/blob/master/orocos_kdl/src/frames.hpp // Vec ...
- Lua自己实现string.split功能
local function split(str, d) --str是需要查分的对象 d是分界符 local lst = { } local n = string.len(str)--长度 local ...
- String、StringBuffer、StringBuilder源码解读
序 好长时间没有认真写博客了,过去的一年挺忙的.负责过数据库.线上运维环境.写代码.Code review等等东西挺多. 学习了不少多方面的东西,不过还是需要回归实际.加强内功,方能扛鼎. 去年学习M ...
随机推荐
- spring restTemplate 进行http请求的工具类封装
本文为博主原创,未经允许不得转载: 1.对常用调用的方法进行封装: import org.springframework.http.HttpHeaders; import com.alibaba.fa ...
- Quartz 定时任务调度
一.在Quartz.NET中quartz.properties的配置文件,忽略不修改,考虑下面: var props = new NameValueCollection { { "quart ...
- PIGS_POJ1149
PIGS Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 20253 Accepted: 9252 Description ...
- Spring听课笔记(tg)
0. 地址:https://www.bilibili.com/video/av21335209 1.综述,Spring主要的复习要点集中在以下几点 -- Spring的整体结构,Maven依赖(环境搭 ...
- Go - 实现项目内链路追踪
为什么项目内需要链路追踪?当一个请求中,请求了多个服务单元,如果请求出现了错误或异常,很难去定位是哪个服务出了问题,这时就需要链路追踪. 从图中可以清晰的看出他们之间的调用关系,通过一个例子说明下链路 ...
- 排查 Linux 系统运行速度慢
排查 Linux 系统运行速度慢 一.检查CPU信息 二.使用top检查cpu负载 三.iotop进行检查 四.检查启动的服务 五.free检查闲置内存空间 一.检查CPU信息 在 Linux 系统中 ...
- 误删eth1或者 eth0
不小心把机房,eth1删除了,过2天还演示,折腾一下午.... 首先eth1存在地方是2块./etc/sysconfig/network-scripts/下 /et/sysconfig/network ...
- 31-1.解决service iptables save出错
CentOS 7.x开始,CentOS开始使用systemd服务来代替daemon,原来管理系统启动和管理系统服务的相关命令全部由systemctl命令来代替.service命令只保留下了极少部分使用 ...
- Flink-v1.12官方网站翻译-P007-Data Pipelines & ETL
数据管道和ETL 对于Apache Flink来说,一个非常常见的用例是实现ETL(提取.转换.加载)管道,从一个或多个源中获取数据,进行一些转换和/或丰富,然后将结果存储在某个地方.在这一节中,我们 ...
- 一文入门Linux下gdb调试(一)
作者:良知犹存 转载授权以及围观:欢迎添加微信号:Conscience_Remains 总述 在window下我们习惯了IDE的各种调试按钮,说实话确实挺方便的,但到了Linux下,没有那么多的IDE ...