js br不生效_前端标注工具-AILabel.js

AILabel.js 是一个用于前端图片缩放、平移和矢量数据、文本、标注展示的工具。提供了npm和github资源,支持无极缩放、平移、多种标注形式,并提供丰富的示例和事件监听功能。
摘要由CSDN通过智能技术生成

# AILabel.js

背景:在前端开发过程中难免遇到针对图片的缩放平移;以及在图片上进行矢量数据、文本、标注的展示;如果你有上面的任何需求,恭喜你,找到组织了....<br/>

在此背景下,AILabel.js出生了

### 相关资料

npm下载地址:[ailabel](ailabel)<br/>

github地址: [dingyang9642/AILabel](dingyang9642/AILabel)

求star<br/>

api文档(待补充): [AILabel](https://dingyang9642.github.io/AILabel/#/)<br/>

加入qq群:378301400

### 背景-功能

> 1. 解决图片浏览(无极缩放、平移)

> 2. 矢量数据、文本、标注展示

> 3. 矢量数据绘制、编辑

> 4. 标注形式:矩形、多边形、涂抹、折线、打点、文本text、标注marker

### 示例图

![point.gif](https://upload-images.jianshu.io/upload_images/13919825-6572e82c68c254cf.gif?imageMogr2/auto-orient/strip%7CimageView2/2/w/300)

![polyline.gif](https://upload-images.jianshu.io/upload_images/13919825-1c9c39b8bce61ade.gif?imageMogr2/auto-orient/strip%7CimageView2/2/w/300)

![rect.gif](https://upload-images.jianshu.io/upload_images/13919825-7e401820b25707f7.gif?imageMogr2/auto-orient/strip%7CimageView2/2/w/300)

![polygon.gif](https://upload-images.jianshu.io/upload_images/13919825-6a36b7f28aa44e9c.gif?imageMogr2/auto-orient/strip%7CimageView2/2/w/300)

![mask.gif](https://upload-images.jianshu.io/upload_images/13919825-572b11e9f2ab86d4.gif?imageMogr2/auto-orient/strip%7CimageView2/2/w/300)

### 示例Demo

[- 要素](Document)<br/>

[- 注记](Document)<br/>

[- 文本](Document)<br/>

[- 绘制编辑](Document)<br/>

[- 矩形编辑](Document)<br/>

[- 要素hover](Document)<br/>

[- 图像&缩略图&比例尺](Document)<br/>

### get started

htmlcssjs部分

```javascript

// 样式声明

<style>

#hello-map {

width: 500px; // 必须

height: 400px; // 必须

position: relative; // 必须

border: 1px solid red;

cursor: pointer;

}

</style>

// 容器声明

<div id="hello-map"></div>

// js声明-容器声明(参数:zoom: 缩放比; {cx: cy:}:初始中心点位置;zoomMax、zoomMin:缩放的比例限制)

const gMap = new AILabel.Map('hello-map', {zoom: 1080, cx: 0, cy: 0, zoomMax: 650 * 10, zoomMin: 650 / 10, autoPan: true, drawZoom: true});

// 图片层实例添加

const gImageLayer = new AILabel.Layer.Image('img', '../../imgs/demo.jpeg', {w: 1080, h: 720}, {zIndex: 1});

gMap.addLayer(gImageLayer);

***至此、已完成首个简单的hello-map的使用***

```

### 矢量数据(Feture)展示

```javascript

// 常用样式声明

const gFetureStyle = new AILabel.Style({strokeColor: '#0000FF'});

// 矢量层实例添加

let gFeatureLayer = new AILabel.Layer.Feature('featureLayer', {zIndex: 2, transparent: true});

gMap.addLayer(gFeatureLayer);

// 矢量要素实例添加

const fea = new AILabel.Feature.Polygon('id', [

{x: 10, y: 10},

{x: 50, y: 10},

{x: 40, y: 50},

{x: 20, y: 60},

{x: 10, y: 10}

], {name: '中国'}, gFetureStyle);

gFeatureLayer.addFeature(fea);

```

### 文本数据(Text)展示

```javascript

// 常用样式声明

const gTextStyle = new AILabel.Style({strokeColor: '#0000FF'});

// 文本层实例添加

let gTextLayer = new AILabel.Layer.Text('textLayer', {zIndex: 2});

gMap.addLayer(gTextLayer);

// 文本要素实例添加

const text = new AILabel.Text('id', {

pos: {x: 100, y: 100},

offset: {x: 0, y: 0},

width: 100,

text: '中国'

}, gTextStyle);

gTextLayer.addText(text);

```

### 标注数据(Marker)展示

```javascript

// 不需要声明markerLayer标注图层,有且只有一个markerLayer,可通过gMap.mLayer来获取

// marker对象实例添加

const marker = new AILabel.Marker('name-中国', {

src: './marker.png',

x: 0,

y: 0,

offset: {x: -32, y: -32}

});

// 注册监听事件删除标注

marker.regEvent('click', function () {

gMap.mLayer.removeMarker(this);

});

gMap.mLayer.addMarker(marker);

```

### 各类事件监听(mouse、hover、boundsChanged、resize等各类事件)

```javascript

// mouseDown:wxy => {}

// mouseMove:wxy => {}

// geometryEditing:(type, feature, newPoints) => {}

// geometryEditDone:(type, feature, newPoints) => {}

// geometryDrawDone:(type, points) => {}

// geometryRemove: (type, feature) => {} 【目前只针对点数据】

// featureHover:feature => {}

// featureSelected:feature => {}

// featureStatusReset:() => {}

// boundsChanged() => {}

// resize() => {}

gMap.events.on('mouseDown', xy => {console.log('xy');});

gMap.events.on('boundsChanged', () => {console.log('boundsChanged');});

gMap.events.on('featureHover', feature => {console.log(feature);});

...

```

### 矢量数据绘制、编辑(点、线、面、涂抹Mask)

```

// 常用样式声明

const gFetureStyle = new AILabel.Style({strokeColor: '#0000FF'});

// 设置当前操作模式为‘drawRect’, 浏览状态对应mode为'pan'

gMap.setMode('drawRect', gFetureStyle);

// 矢量层实例添加

let gFeatureLayer = new AILabel.Layer.Feature('featureLayer', {zIndex: 2, transparent: true});

gMap.addLayer(gFeatureLayer);

// 绘制完成事件监听

gMap.events.on('geometryDrawDone', function (type, points) {

// 生成元素唯一标志(时间戳)

const timestamp = new Date().getTime();

// 元素添加展示

let fea = new AILabel.Feature.Polygon(`feature-${timestamp}`, points, {

name: '中国'

}, gFetureStyle);

gFeatureLayer.addFeature(fea);

});

// 因为自带编辑功能,故需要以下代码

gMap.events.on('geometryEditDone', (type, activeFeature, points) => {

activeFeature.update({points});

activeFeature.show();

});

```

如有其他需要,加入qq群:378301400

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值