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. 【实战】ZooKeeper 实战

    1. 前言 这篇文章简单给演示一下 ZooKeeper 常见命令的使用以及 ZooKeeper Java客户端 Curator 的基本使用.介绍到的内容都是最基本的操作,能满足日常工作的基本需要. 如 ...

  2. java.lang.IllegalStateException Unable to find a @SpringBootConfiguration错误解决方案

    问题描述:java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @Co ...

  3. jQuery——通过Ajax发送数据

    Ajax(Asynchronous JavaScript and XML,异步JavaScript和XML),一个Ajax解决方案涉及如下技术: JavaScript:处理与用户及其他浏览器相关事件的 ...

  4. c++复习笔记(2)

    1. 类与对象 类的声明与结构,数据成员和成员函数. 成员函数可以在类外被定义.但是必须在类内声明. 封装:protect--允许类成员和派生类成员访问. 构造函数之外,还有一种初始化类成员的方法:参 ...

  5. OpenStack (neutron 网络服务)

    neutron介绍 提供 OpenStack 虚拟网络服务,也是 OpenStack 重要的核心模块之一,该模块最开始是 Nova 的一部分,叫 nova-network,后来从 Nova 中分离出来 ...

  6. SpringMVC系列(一)核心:处理请求流程

    http://blog.csdn.net/zhaolijing2012/article/details/41596803

  7. UML——RUP(Rational Unified Process)

    一.宏观导图 二.论细节 RUP(Rational Unified Process)统一软件过程,是指要达到一个指定的目标而采取的一些系列有序的步骤,其目的是高效.准时地提交一个满足业务需求的软件产品 ...

  8. CCF-最优配餐(BFS)

    最优配餐   问题描述 栋栋最近开了一家餐饮连锁店,提供外卖服务.随着连锁店越来越多,怎么合理的给客户送餐成为了一个急需解决的问题.栋栋的连锁店所在的区域可以看成是一个n×n的方格图(如下图所示),方 ...

  9. Java 复习整理day03

    变量或者是常量, 只能用来存储一个数据, 例如: 存储一个整数, 小数或者字符串等. 如果需要同时存储多个同类型的数据, 用变量或者常量来实现的话, 非常的繁琐. 针对于 这种情况, 我们就可以通过数 ...

  10. 爬虫入门到放弃系列02:html网页如何解析

    前言 上一篇文章讲了爬虫的概念,本篇文章主要来讲述一下如何来解析爬虫请求的网页内容. 一个简单的爬虫程序主要分为两个部分,请求部分和解析部分.请求部分基本一行代码就可以搞定,所以主要来讲述一下解析部分 ...