zrender & svg
zrender & svg
window.prompt
double click
https://codepen.io/xgqfrms/pen/jOEGNvw

// https://cdn.xgqfrms.xyz/svg/zrender/zrender.min.js
window.onload = () => {
const log = console.log;
const default_pts = {
renderer: 'canavs',// 渲染方式,支持:'canavs'、'svg'、'vml'
devicePixelRatio: 2, // 画布大小与容器大小之比,仅当 renderer 为 'canvas' 时有效。
width: 'auto',// 画布宽度,设为 'auto' 则根据 devicePixelRatio 与容器宽度自动计算。
height: 'auto', // 画布高度,设为 'auto' 则根据 devicePixelRatio 与容器高度自动计算。
};
const opts = {
renderer: 'svg',
width: 400,
height: 400,// 画布大小
};
const zr = zrender.init(document.getElementById('app'), opts);
// log(`zr`, zr);
const version = zrender.version;
log(`zr version`, version);
// version 4.1.2
let w = zr.getWidth();
let h = zr.getHeight();
log(`w / h`, w, h);
let text = null;
const boundingRect = new zrender.Rect({
shape: {
r: 0,
// r: 1,
// r: 10,
// r: [1],
// cx: 0,
// cy: 0,
x: 100,
y: 100,
// x: 0,
// y: 0,
width: 200,
height: 200,
},
style: {
fill: '#0f0',
// fill: 'none',
stroke: '#666',
},
color: "abc",
});
// boundingRect.on(`click`, function(e) {
// // log(`click e`, e);
// log(`click this`, this,);
// log(`click this.color`, this.color);
// this.color = "xyz";
// log(`click new this.color`, this.color);
// // boundingRect
// }, boundingRect);
boundingRect.on(`dblclick`, function(e) {
// log(`click e`, e);
log(`dblclick this`, this);
// log(`dblclick this.style`, this.style);
let rect = this.getBoundingRect();
log(`dblclick rect\n%c ${JSON.stringify(rect, null, 4)}`, `color: #0f0`);
const x = rect.width / 2 + rect.x;
const y = rect.height / 2 + rect.y;
log(`x, y`, x, y);
// let msg = window.confirm(`请输入选区的名称?`);
let msg = window.prompt(`请输入选区的名称?`);
// prompt([string message], [string defaultValue]);
if(text){
zr.remove(text);
// zr.clear(text);
}
log(`text`, text);
text = new zrender.Text({
style: {
text: msg || 'A 区',
textAlign: 'center',
textVerticalAlign: 'middle',
fontSize: 18,
fontFamily: 'Lato',
fontWeight: 'bolder',
textFill: '#f0f',
blend: 'lighten',
},
position: [x, y],
});
log(`text`, text);
zr.add(text);
}, boundingRect);
// boundingRect.on(`click`, (e) => {
// // log(`click e`, e);
// log(`click this`, this);
// this bind bug
// log(`click this`, boundingRect);
// // boundingRect
// }, boundingRect);
zr.add(boundingRect);
};
zrender & svg的更多相关文章
- ZRender源码分析6:Shape对象详解之路径
开始 说到这里,就不得不提SVG的路径操作了,因为ZRender完全的模拟了SVG原生的path元素的用法,很是强大. 关于SVG的Path,请看这里: Path (英文版) 或者 [MDN]SVG教 ...
- WebGIS中使用ZRender实现前端动态播放轨迹特效的方案
文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/ 1.背景 项目中需要在地图上以时间轴方式播放人员.车辆在地图上的历史行进 ...
- 轨迹系列4——WebGIS中使用ZRender实现轨迹前端动态播放特效
文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/ 1.背景 项目中需要在地图上以时间轴方式播放人员.车辆在地图上的历史行进 ...
- Zrender:实现波浪纹效果
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- how to change svg polygon size by update it's points in js
how to change svg polygon size by update it's points in js matrixTransform https://stackoverflow.com ...
- 【Web动画】SVG 实现复杂线条动画
在上一篇文章中,我们初步实现了一些利用基本图形就能完成的线条动画: [Web动画]SVG 线条动画入门 当然,事物都是朝着熵增焓减的方向发展的,复杂线条也肯定比有序线条要多. 很多时候,我们无法人工去 ...
- 【Web动画】SVG 线条动画入门
通常我们说的 Web 动画,包含了三大类. CSS3 动画 javascript 动画(canvas) html 动画(SVG) 个人认为 3 种动画各有优劣,实际应用中根据掌握情况作出取舍,本文讨论 ...
- SVG:textPath深入理解
SVG的文本可以沿着一条自定义的Path来排布,比如曲线.圆形等等,使用方式如下所示(来源MDN): <svg viewBox="0 0 1000 300" xmlns=&q ...
- SVG:linearGradient渐变在直线上失效的问题解决方案
SVG开发里有个较为少见的问题. 对x1=x2或者y1=y2的直线(line以及path),比如: <path d="M200,10 200,100" stroke=&quo ...
随机推荐
- 使用“2”个参数调用“SetData”时发生异常:“程序集“
使用"2"个参数调用"SetData"时发生异常:"程序集"Microsoft.VisualStudio.ProjectSystem.VS. ...
- bzoj2654(loj20069)
2654: tree Time Limit: 30 Sec Memory Limit: 512 MB Description 给你一个无向带权连通图,每条边是黑色或白色.让你求一棵最小权的恰好有ne ...
- flutter--Dart基础语法(二)流程控制、函数、异常
一.前言 Flutter 是 Google 开源的 UI 工具包,帮助开发者通过一套代码库高效构建多平台精美应用,Flutter 开源.免费,拥有宽松的开源协议,支持移动.Web.桌面和嵌入式平台. ...
- Spring Boot 两种多数据源配置:JdbcTemplate、Spring-data-jpa
多数据源配置 JdbcTemplate支持 Spring-data-jpa支持 多数据源配置 创建一个Spring配置类,定义两个DataSource用来读取application.propertie ...
- SpringMvc获取getbean
import org.apache.commons.lang3.Validate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; i ...
- hbase Master is initializing
重装hbase后导致出险问题:hbase(main):007:0> create 'test_t2','f1' ERROR: org.apache.hadoop.hbase.PleaseHold ...
- CF-1332 F. Independent Set
F. Independent Set 题意 一颗 n 个节点的树,求出每个\(edge-induced~subgraph\)的独立集个数之和. \(edge-induced~subgraph\)含义是 ...
- Codeforces Round #579 (Div. 3) E. Boxers (贪心)
题意:给你一组数,每个数都可以进行一次加一减一,问最后最多能有多少不同的数. 题解:我们可以用桶存每个数的次数,然后枚举\([1,150001]\)来求对答案的贡献,然后贪心,这里我们不用担心其他乱七 ...
- Codeforces Round #547 (Div. 3) E. Superhero Battle (数学)
题意:有一个HP为\(h\)的大怪兽,你需要轮流进行\(i\)次操作.每次可以使\(h+=d_i\)(\(d_i\)有正有负),当第\(n\)次操作完成后,再从第一次开始,问能否使得怪兽的HP变为\( ...
- Codeforces Round #501 (Div. 3) B. Obtaining the String (思维,字符串)
题意:有两个字符串\(S\)和\(T\),判断\(T\)是否能由\(S\)通过交换某位置的相邻字符得到,如果满足,输出交换次数及每次交换的位置,否则输出\(-1\). 题解:首先判断不满足的情况,只有 ...