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的更多相关文章

  1. ZRender源码分析6:Shape对象详解之路径

    开始 说到这里,就不得不提SVG的路径操作了,因为ZRender完全的模拟了SVG原生的path元素的用法,很是强大. 关于SVG的Path,请看这里: Path (英文版) 或者 [MDN]SVG教 ...

  2. WebGIS中使用ZRender实现前端动态播放轨迹特效的方案

    文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/ 1.背景 项目中需要在地图上以时间轴方式播放人员.车辆在地图上的历史行进 ...

  3. 轨迹系列4——WebGIS中使用ZRender实现轨迹前端动态播放特效

    文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/ 1.背景 项目中需要在地图上以时间轴方式播放人员.车辆在地图上的历史行进 ...

  4. Zrender:实现波浪纹效果

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  5. 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 ...

  6. 【Web动画】SVG 实现复杂线条动画

    在上一篇文章中,我们初步实现了一些利用基本图形就能完成的线条动画: [Web动画]SVG 线条动画入门 当然,事物都是朝着熵增焓减的方向发展的,复杂线条也肯定比有序线条要多. 很多时候,我们无法人工去 ...

  7. 【Web动画】SVG 线条动画入门

    通常我们说的 Web 动画,包含了三大类. CSS3 动画 javascript 动画(canvas) html 动画(SVG) 个人认为 3 种动画各有优劣,实际应用中根据掌握情况作出取舍,本文讨论 ...

  8. SVG:textPath深入理解

    SVG的文本可以沿着一条自定义的Path来排布,比如曲线.圆形等等,使用方式如下所示(来源MDN): <svg viewBox="0 0 1000 300" xmlns=&q ...

  9. SVG:linearGradient渐变在直线上失效的问题解决方案

    SVG开发里有个较为少见的问题. 对x1=x2或者y1=y2的直线(line以及path),比如: <path d="M200,10 200,100" stroke=&quo ...

随机推荐

  1. 第八届“图灵杯”NEUQ-ACM程序设计竞赛个人赛(同步赛)

    传送门 B-小宝的幸运数组 题目描述 对于小宝来说,如果一个数组的总和能够整除他的幸运数字k,就是他的幸运数组,而其他数组小宝都很讨厌.现在有一个长度为n的数组,小宝想知道这个数组的子数组中,最长的幸 ...

  2. Django(图书管理系统)#转

    自己虽然实现了, 但是写的太LOW了,为了不误导大家,推荐一篇好的博客 https://www.cnblogs.com/alice-bj/p/9114084.html

  3. 从问题入手,深入了解JavaScript中原型与原型链

    从问题入手,深入了解JavaScript中原型与原型链 前言 开篇之前,我想提出3个问题: 新建一个不添加任何属性的对象为何能调用toString方法? 如何让拥有相同构造函数的不同对象都具备相同的行 ...

  4. js实现购物车左滑删除

    使用 js 和jquery动画实现购物车左滑,请引入jquery库,不然会报错哦! 首页编写页面,注意布局,滑动分成两部分,商品图片和信息放在一个布局,删除和移入收藏放在一起. 其中js用到了 tou ...

  5. 【LA 3487】Duopoly(图论--网络流最小割 经典题)

    题意:C公司有一些资源,每种只有1个,有A.B两个公司分别对其中一些资源进行分组竞标,每组竞标对一些资源出一个总价.问C公司的最大收益. 解法:最小割.将A公司的竞标与源点相连,B公司的与汇点相连,边 ...

  6. Educational Codeforces Round 97 (Rated for Div. 2) D. Minimal Height Tree (贪心)

    题意:有一个从根节点\(BFS\)得来的序列(每次\(bfs\)子节点的时候保证是升序放入队列的),现在让你还原树(没必要和之前相同),问能构造出的最小的树的深度. 题解:不看根节点,我们从第二个位置 ...

  7. Codeforces Round #669 (Div. 2) C. Chocolate Bunny (交互,构造)

    题意:有一个长度为\(n\)的隐藏序列,你最多可以询问\(2n\)次,每次可以询问\(i\)和\(j\)位置上\(p[i]\ mod\ p[j]\)的结果,询问的格式是\(?\ x\ y\),如果已经 ...

  8. windows 系统下安装kibana和sense

    目前最新版本已经不需要安装sense了,而是使用Dev Tools工具: 下面进行下载和安装kibana. 点击下载:https://artifacts.elastic.co/downloads/ki ...

  9. 连接MongoDb数据库 -- Python

    1.安装完mongoDb数据库后,如果需要我们的Python程序和MongoDb数据库进行交互,需要安装pymongo模块: 安装方式:采用pip install pymongo的方式 Microso ...

  10. Nginx基础 - 通用优化配置文件

    [root@localhost ~]# vim /etc/nginx/nginx.conf user nginx; worker_processes auto; worker_cpu_affinity ...