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. 9.5 自定义包和可见性 go mod

    the-way-to-go_ZH_CN/09.5.md at master · Unknwon/the-way-to-go_ZH_CN https://github.com/Unknwon/the-w ...

  2. OPC UA 统一架构) (一)

    OPC UA 一 .OPC UA简介 OPC UA(OPC Unified Architecture)是下一代OPC统一体系架构,是一种基于服务的.跨越平台的解决方案. OPC UA具有如下特点: 1 ...

  3. 关于MongoDB的简单理解(二)--Java篇

    一.声明 本文依赖于 MongoDB JVM DRIVERS 4.1 版本编写. 本文案例依赖于 Maven 项目管理工具. 二.本文主要讲解哪些内容? 如何连接到MongoDB 通过TLS/SSL连 ...

  4. loj10018数的划分

    题目描述 将整数 n 分成 k 份,且每份不能为空,问有多少种不同的分法.当 n=7,k=3 时,下面三种分法被认为是相同的:1 1 5;1 5 1 ;5 1 1 输入格式 一行两个数 n ,k . ...

  5. luogu p3369

    题目描述您需要写一种数据结构(可参考题目标题),来维护一些数,其中需要提供以下操作: 插入x数删除x数(若有多个相同的数,因只删除一个)查询x数的排名(排名定义为比当前数小的数的个数+1.若有多个相同 ...

  6. vulnhub靶场之AI-WEB1.0渗透记录

    在本机电脑上自行搭建了一个练手的靶场,下面是记录渗透过程 目录 一.确认靶机ip 二.端口&目录扫描 三.查看敏感目录 四.sql注入 五.get shell 六.系统提权 确认靶机ip ka ...

  7. java 石头剪子布游戏

    源代码 StoneGame.java 1 import java.io.BufferedReader; 2 import java.io.IOException; 3 import java.io.I ...

  8. 弱网测试之Fidder

    是用Fidder可以模拟若罔测试. 1.Fiider设置 fiddler中选中Rules->Cutomize Rules,在文件中搜索关键字:m_SimulateModem: 修改m_Simul ...

  9. Pytest(17)运行未提交的git(pytest-picked)

    前言 我们每天写完自动化用例后都会提交到 git 仓库,随着用例的增多,为了保证仓库代码的干净,当有用例新增的时候,我们希望只运行新增的未提交 git 仓库的用例.pytest-picked 插件可以 ...

  10. 在Android用vulkan完成蓝绿幕扣像

    效果图(1080P处理) 因为摄像头开启自动曝光,画面变动时,亮度变化导致扣像在转动时如上. 源码地址vulkan_extratest 这个demo主要测试二点,一是测试ndk camera集成效果, ...