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. 指令集架构 x86-64 x86架构的64位拓展,向后兼容于16位及32位的x86架构

    https://zh.wikipedia.org/wiki/X86 x86泛指一系列英特尔公司用于开发处理器的指令集架构,这类处理器最早为1978年面市的"Intel 8086"C ...

  2. Python学习【第6篇】:集合的定义和基本方法

    1.概念 (1)不同元素组成 例: s = {1,2,3,4,4,4,4,4,4}print(s)运行结果:{1, 2, 3, 4}因为是不同元素组成,因此去重了 (2)无序 例: s = {&quo ...

  3. STM32 定时器详细篇(基于HAL库)

    l  16位的向上.向下.向上/向下(中心对齐)计数模式,支持自动重装载 l  16位的预分频器 l  每个定时器都有多个独立通道,每个通道可用于 *  输入捕获 *  输出比较 *  PWM输出 * ...

  4. 圣诞快乐!OIer挂分小技巧

    OIer常犯错误 自己的错误 循环里套return 线段树求和 int 定义,下传 int 定义 cmp<,>号分不清 主观行为举动错误 踢电源线,注意安全(_Destiny) TLE 大 ...

  5. MySQL数据库的逻辑架构和存储引擎

    和其他数据库相比,MySQL数据库的架构与众不同,它的架构可以在多种不同的场景中应用并发挥良好的作用:主要体现在存储引擎上的架构上,插件式的存储引擎架构将查询处理和其他的系统任务以及数据存储提取相分离 ...

  6. Cisco动态路由(rip)

    接Cisco静态路由,讨论一下Cisco动态路由. 实验环境布置 命令布置动态路由 Router0: Router>enable Router#configure terminal Router ...

  7. SQL系列总结——基础篇(二)

           表达式:是符号与运算符的组合,一个常量,变量.列或标量函数就是一个简单的表达式,复杂的表达式由两个或更多的简单表达式通过运算符连接起来组成.运算符同样的遵循优先级的原则.作用,让SQL的 ...

  8. 关闭Linux - centos7的防火墙

    关闭Centos7的防火墙 在每台虚拟机上分别执行以下指令: systemctl stop firewalld.service #停止firewall systemctl disable firewa ...

  9. pytest测试框架+jenkins结合pytest+jenkins邮件通知配置

    刚刚做完一个项目,由于这是一个方案项目,而不是产品,所以各种准备很不充分,很多公司的能力不能复用,整个团队又都是新员工,而且有部分实习生,匆忙上马,今天对我的自动化框架做一个回溯 自动化测试框架的选择 ...

  10. mysql高级day1

    Mysql高级-day01 MySQL高级课程简介 序号 Day01 Day02 Day03 Day04 1 Linux系统安装MySQL 体系结构 应用优化 MySQL 常用工具 2 索引 存储引擎 ...