Browse Source

[合并]合并代码

develop
陈鹏飞 5 years ago
parent
commit
765949a5e1
  1. 53
      src/app/ui/collection-tools/collection-tools.component.html
  2. 38
      src/app/ui/collection-tools/collection-tools.component.scss
  3. 203
      src/app/ui/collection-tools/collection-tools.component.ts
  4. 14
      src/app/ui/collection-tools/viewdetails.html
  5. 4
      src/app/ui/ui.module.ts
  6. 15
      src/app/working-area/working-area.component.html
  7. 372
      src/app/working-area/working-area.component.ts
  8. 1
      src/index.html

53
src/app/ui/collection-tools/collection-tools.component.html

@ -162,22 +162,56 @@
</div>
<!-- 素材属性 -->
<div class="assetsproperty">
<h3 style="text-align: center;font-weight: 900;">实景照片</h3>
<h3 style="text-align: center;font-weight: 900;">{{assetName}}</h3>
<p>宽度(像素)</p>
<input type="text" class="biginput">
<input type="text" class="biginput" [(ngModel)]="assetWidth" (input)="assetWidthIunput()">
<p>高度(像素)</p>
<input type="text" class="biginput">
<input type="text" class="biginput" [(ngModel)]="assetHeight" (input)="assetHeightIunput()">
<p>角度</p>
<div style="width: 100%;display: flex;vertical-align: top;height: 22px;">
<input type="number" class="smallinput" [(ngModel)]="sliderValue"
oninput="if(value>360)value=360;if(value<0)value=0;">
oninput="if(value>360)value=360;if(value<0)value=0;" (input)="assetAngleIunput()">
<mat-slider color="primary" min="0" max="360" step="1" style="bottom: 12px;left: 2px;width: 70%;"
[(ngModel)]="sliderValue"></mat-slider>
[(ngModel)]="sliderValue" (change)="assetAngleIunput()"></mat-slider>
</div>
<p>是否高亮</p>
<p style="margin-top: 4px;margin-bottom: 0px;">是否高亮</p>
<div>
<input type="checkbox"
style="width: 20px;height: 20px;vertical-align: middle;margin-left: 8px;"><span>选中高亮</span>
<input [(ngModel)]="isHighLight" type="checkbox" style="width: 18px;height: 18px;vertical-align: middle;margin-left: 9px;margin-right: 3px;">
<span style="font-size: 14px;">选中高亮</span>
</div>
<div *ngFor="let item of PropertyInfos;index as key ">
<!-- 单行文本 -->
<div *ngIf="item.PropertyType == 0">
<p>{{item.PropertyName}}</p>
<input type="text" class="biginput" [value]="item.PropertyValue">
</div>
<!-- 多行文本 -->
<div *ngIf="item.PropertyType == 1">
<p>{{item.PropertyName}}</p>
<textarea class="textarea" name="" id="" [value]="item.PropertyValue"></textarea>
</div>
<!-- 数值 -->
<div *ngIf="item.PropertyType == 2">
<p>{{item.PropertyName}}</p>
<input type="number" class="biginput" [value]="item.PropertyValue">
</div>
<!-- 图片数量 -->
<div *ngIf="item.PropertyType == 4">
<div style="position: relative;width: 100%;height: 21px;margin: 1px 0;">
<p style="width: 40%;display: inline-block;">{{item.PropertyName}}</p>
<span style="width: 26%;text-align:right;font-size: 13px;">{{imagesArr.length ? imagesArr.length : 0}} / {{item.PropertyValue}}</span>
<input type="file" style="width: 33%;position: absolute;right: 10px;top: 1px;opacity: 0;z-index: 100;cursor: pointer;">
<div style="width: 33%;height: 21px;line-height: 21px;text-align: center;position: absolute;right: 10px;top: 1px;z-index: 99;border: 1px solid rgb(208, 211, 214);border-radius: 2px;font-size: 13px;">添加</div>
</div>
<div style="position: relative;;width: 89%;border:1px solid rgb(208, 211, 214);height: 100px;margin: 6px auto;" class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide" style="text-align: center;" *ngFor="let img of imagesArr"><img (click)="lookImg()" [src]="img.PropertyValue + '?x-oss-process=image/resize,m_fixed,h_100,w_100'" alt=""></div>
</div>
<!-- 如果需要导航按钮 -->
<div class="swiper-button-next"></div>
<div class="swiper-button-prev"></div>
</div>
</div>
</div>
</div>
@ -189,6 +223,9 @@
<span style="user-select: none">消防要素</span>
</div>
</div>
<div class="firecategoriesTree">
<!-- 消防列表树写在这里 -->
</div>
</div>
</div>

38
src/app/ui/collection-tools/collection-tools.component.scss

@ -111,6 +111,7 @@
//右边操作栏
.title{
width: 100%;
height: 35px;
background-color: #464646;
div{
@ -129,8 +130,10 @@
}
//右侧属性
.property{
display: flex;
flex-flow: column;
.siteproperty{
height: 100%;
p{
@ -154,10 +157,12 @@
}
}
.assetsproperty{
overflow-y: auto;
height: 100%;
p{
color: #9c9fa5;
margin:1px 0 3px 8px;
font-size: 14px;
}
input{
height: 18px;
@ -172,5 +177,36 @@
width: 19%;
margin-left: 8px;
}
.textarea{
display: block;
width: 88%;
height: 50px;
margin: 0 auto;
}
.swiper-button-next{
right: 6px;
}
.swiper-button-next:after{
font-size: 20px;
}
.swiper-button-prev{
left: 6px;
}
.swiper-button-prev:after{
font-size: 20px;
}
}
}
//右侧消防要素
.firecategories{
display: flex;
flex-flow: column;
.firecategoriesTree{
overflow-y: auto;
height: 100%;
}
}
div:focus {
outline: none;
}

203
src/app/ui/collection-tools/collection-tools.component.ts

@ -3,6 +3,9 @@ import { HttpClient, HttpHeaders } from '@angular/common/http';
import { MatDialog, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { MatSnackBar, MatSnackBarConfig } from '@angular/material/snack-bar';
import {leftFunctionalDomainComponent,editPlaneFigureComponent} from './leftFunctionalDomain'
import Swiper from 'swiper';
@Component({
selector: 'app-collection-tools',
@ -20,12 +23,172 @@ export class CollectionToolsComponent implements OnInit {
beforeOneCheckedBuilding:any = {name:"总平面图"}; //当前点击选择的建筑
checkedBuildingIndex:number = -1 //当前点击选择的建筑index
isEditPat:boolean = true //当前是否是编辑模式
sliderValue:String = "30"//滑竿的值
proObject = {
"Id": "6856647621407145995",
"Name": "实景照片",
"Angle": 104.0,
"Color": "#FFFFFFFF",
"Point": {
"x": -45.2675133,
"y": 26.3694324
},
"Width": 66,
"Border": {
"w": 0.0,
"x": 0.0,
"y": 0.0,
"z": 0.0
},
"Height": 66,
"Enabled": true,
"FloorId": "5e902b399f45957cf4387616",
"DrawMode": 0,
"FillMode": 1,
"GameMode": 0,
"ImageUrl": "/api/Objects/PlanPlatform/5e7c13e9bb3cf106508afafc.png",
"CompanyId": null,
"FixedSize": true,
"FloorName": null,
"Thickness": 0,
"BuildingId": null,
"MultiPoint": null,
"TemplateId": "5e7c13ef61550e2754d461c8",
"FireElementId": "5e796f040814180f1c1ecaf5",
"PropertyInfos": [{
"Tag": "",
"Order": 0,
"Enabled": true,
"Visible": true,
"Required": false,
"RuleName": "",
"RuleValue": "",
"PhysicalUnit": "",
"PropertyName": "名称/编号",
"PropertyType": 0,
"PropertyValue": "99999"
}, {
"Tag": "",
"Order": 0,
"Enabled": true,
"Visible": true,
"Required": false,
"RuleName": "",
"RuleValue": "",
"PhysicalUnit": "张",
"PropertyName": "图片",
"PropertyType": 4,
"PropertyValue": "5"
}, {
"Tag": null,
"Order": 0,
"Enabled": false,
"Visible": false,
"Required": false,
"RuleName": null,
"RuleValue": null,
"PhysicalUnit": null,
"PropertyName": "图片",
"PropertyType": 3,
"PropertyValue": "/api/Objects/WebPlan2D/5e8ed394aaca5f7c102530ad/5f27b4c15ba53b1bc0ae312e.png"
}, {
"Tag": null,
"Order": 0,
"Enabled": false,
"Visible": false,
"Required": false,
"RuleName": null,
"RuleValue": null,
"PhysicalUnit": null,
"PropertyName": "图片",
"PropertyType": 3,
"PropertyValue": "/api/Objects/PlanPlatform/5e7c0ff1bb3cf106508afaed.png"
}],
"IsFromBuilding": false,
"InteractiveMode": 0
}
assetName:String//素材名称
assetWidth:number//素材宽度
assetHeight:number//素材高度
sliderValue:number = 0//滑竿的值
isHighLight:boolean = false//是否高亮选择框
PropertyInfos = [] //去除图片链接真正用于循环的内容
imagesArr = [] //属性中的图片链接集合
clickedIndex //点击图片的索引值
//传入素材对象,设置右侧属性栏内容
setAssetsProperty(obj){
let _this = this
this.assetName = obj.Name
this.assetWidth = obj.Width
this.assetHeight = obj.Height
this.sliderValue = obj.Angle
obj.PropertyInfos.forEach(item => {
if(item.PropertyType == 3){ //如果是图片链接类型
this.imagesArr.push(item)
}else{
this.PropertyInfos.push(item)
}
})
//如果存在图片则加载轮播图
if(this.imagesArr.length){
setTimeout(() => {
var mySwiper = new Swiper('.swiper-container',{
loop: false,
grabCursor: true,
// 如果需要前进后退按钮
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
},
on:{
click: function(){
_this.clickedIndex = this.clickedIndex
},
}
});
}, 0);
}
}
//素材宽度输入框改变
assetWidthIunput(){
this.proObject.Width = this.assetWidth
}
//素材高度输入框改变
assetHeightIunput(){
this.proObject.Height = this.assetHeight
}
//素材角度输入框改变
assetAngleIunput(){
this.proObject.Angle = this.sliderValue
}
//素材是否高亮改变
assetHighLightIunput(){
}
//查看图片详情
lookImg(){
const dialogRef = this.dialog.open(ViewDetails, {//调用open方法打开对话框并且携带参数过去
data: {imagesArr:this.imagesArr,index:this.clickedIndex}
});
}
ngOnInit(): void {
this.getAllLibrary()
this.getSitePlan()
this.getAllBuildings()
this.setAssetsProperty(this.proObject) //测试
}
//点击基本信息名称
@ -138,7 +301,6 @@ export class CollectionToolsComponent implements OnInit {
}
//陈鹏飞↓↓↓
//陈鹏飞↓↓↓
//陈鹏飞↓↓↓
@ -422,4 +584,41 @@ export class EditBuilding {
this.dialogRef.close("修改失败");
})
}
}
//查看图片大图
//查看图片大图和视频
@Component({
selector: 'viewdetails',
templateUrl: './viewdetails.html',
styleUrls: ['./collection-tools.component.scss']
})
export class ViewDetails {
// myControl = new FormControl();
//注入MatDialogRef,可以用来关闭对话框
//要访问对话框组件中的数据,必须使用MAT_DIALOG_DATA注入令牌
constructor(private http: HttpClient,public dialogRef: MatDialogRef<ViewDetails>,@Inject(MAT_DIALOG_DATA) public data) {}
imagesArr = this.data.imagesArr
onNoClick(): void {
this.dialogRef.close();
}
ngOnInit(): void {
setTimeout(() => {
var mySwiper = new Swiper('.swiper-container',{
loop: false,
grabCursor: true,
initialSlide :this.data.index,//默认索引
// 如果需要前进后退按钮
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
}
//其他设置
});
}, 0);
}
closeDialog(){
this.dialogRef.close();
}
}

14
src/app/ui/collection-tools/viewdetails.html

@ -0,0 +1,14 @@
<div style="position: relative;width: 1400px;height: 800px;line-height: 800px;" class="swiper-container">
<div style="position: absolute;right: -2px;top: -392px;cursor: pointer;z-index: 999;width: 24px;height: 24px;" (click)="closeDialog()">
<span><mat-icon>clear</mat-icon></span>
</div>
<div class="swiper-wrapper">
<div class="swiper-slide" style="text-align: center;" *ngFor="let img of imagesArr">
<img style="max-width: 96%;max-height: 100%;" [src]="img.PropertyValue" alt="">
</div>
</div>
<!-- 如果需要导航按钮 -->
<div class="swiper-button-next"></div>
<div class="swiper-button-prev"></div>
</div>

4
src/app/ui/ui.module.ts

@ -95,12 +95,12 @@ import { ImgsDataDetail } from './fire-fighting-device/addGrouping.component';
import { KeySiteImgs } from './key-site/keysiteimgs.component';
import { KeyImgDetail } from './key-site/keyimgdetail.component';
import { LookMaster } from './basicinfo/lookmaster.component';
import { CollectionToolsComponent, CreateBuilding, EditBuilding } from './collection-tools/collection-tools.component';
import { CollectionToolsComponent, CreateBuilding, EditBuilding, ViewDetails } from './collection-tools/collection-tools.component';
import { WorkingAreaComponent } from '../working-area/working-area.component';
import {leftFunctionalDomainComponent,editPlaneFigureComponent} from './collection-tools/leftFunctionalDomain'
@NgModule({
declarations: [UiComponent, CardComponent, StepperComponent, TabgroupComponent, ProgressComponent, SnackbarComponent, PersonaldataComponent, UserdataComponent, ChangepasswordComponent, OrganizationComponent, UnittypeComponent, AuthorityComponent, RoleComponent, UsermanagementComponent, IsnoPipe, ConfirmpswDirective, DialogOverviewExampleDialog, CreateAuthority, CreateRole, EditRole, TimePipe, CreateNewUser, EditNewUser, allRoles, SharePower, CreateOrganization, EditOrganization, seeInformation, EditUser, editorialUnit, FireProtectionElementsComponent, Establish, EditingFireControl, FireFightingTemplateComponent, NavmenusComponent, CreateMenus, EditMenus, NewFireFighting, EditFireClassification, MaterialBankComponent, UnitInformationComponent, AddMatLibrary, EditMatLibrary, attributeComponent, AddOriginalCopy, addAttributeComponent, editAttribute, EditOriginalCopy, SelectOriginalCopy, EditUnitInfo, AddUnitInfo, AddGroups, EditGroup, BasicinfoComponent, PlanComponent, AllaroundComponent, FireFightingDeviceComponent, KeySiteComponent, FunctionDivisionComponent, RealisticPictureComponent, UploadingCADComponent, AddHouseInfo, ImgDetails, ImagesData, ImgsDataDetail, KeySiteImgs, KeyImgDetail, addPartition, addPartitionAttribute, previewImg, addRealPicture, editRealPicture, readFile, editFile, LookMaster, previewBigImg, CollectionToolsComponent, WorkingAreaComponent,CreateBuilding,EditBuilding,leftFunctionalDomainComponent,editPlaneFigureComponent
declarations: [UiComponent, CardComponent, StepperComponent, TabgroupComponent, ProgressComponent, SnackbarComponent, PersonaldataComponent, UserdataComponent, ChangepasswordComponent, OrganizationComponent, UnittypeComponent, AuthorityComponent, RoleComponent, UsermanagementComponent, IsnoPipe, ConfirmpswDirective, DialogOverviewExampleDialog, CreateAuthority, CreateRole, EditRole, TimePipe, CreateNewUser, EditNewUser, allRoles, SharePower, CreateOrganization, EditOrganization, seeInformation, EditUser, editorialUnit, FireProtectionElementsComponent, Establish, EditingFireControl, FireFightingTemplateComponent, NavmenusComponent, CreateMenus, EditMenus, NewFireFighting, EditFireClassification, MaterialBankComponent, UnitInformationComponent, AddMatLibrary, EditMatLibrary, attributeComponent, AddOriginalCopy, addAttributeComponent, editAttribute, EditOriginalCopy, SelectOriginalCopy, EditUnitInfo, AddUnitInfo, AddGroups, EditGroup, BasicinfoComponent, PlanComponent, AllaroundComponent, FireFightingDeviceComponent, KeySiteComponent, FunctionDivisionComponent, RealisticPictureComponent, UploadingCADComponent, AddHouseInfo, ImgDetails, ImagesData, ImgsDataDetail, KeySiteImgs, KeyImgDetail, addPartition, addPartitionAttribute, previewImg, addRealPicture, editRealPicture, readFile, editFile, LookMaster, previewBigImg, CollectionToolsComponent, WorkingAreaComponent,CreateBuilding,EditBuilding,leftFunctionalDomainComponent,editPlaneFigureComponent,ViewDetails
],
imports: [

15
src/app/working-area/working-area.component.html

@ -1,14 +1 @@
<div #content style="width:100%;height:100%;" (mousewheel)='mouseWheelHandel($event)'>
<button
(click)="this.replaceBackgroundImage('https://qntemp3.bejson.com/upload/72681686638249940.jpg?imageView2/0/w/0/h/0/format/webp')">替换背景图</button>
<button
(click)="this.createSinglePointIcon('https://qntemp3.bejson.com/upload/72681686638249940.jpg?imageView2/0/w/100/h/100/format/webp')">创建图标</button>
<button
(click)="this.replaceBackgroundImage('https://qntemp3.bejson.com/upload/72681686638249940.jpg?imageView2/0/w/0/h/0/format/webp')">创建多边形</button>
<button
(click)="this.replaceBackgroundImage('https://qntemp3.bejson.com/upload/72681686638249940.jpg?imageView2/0/w/0/h/0/format/webp')">创建多点连线</button>
<button
(click)="this.replaceBackgroundImage('https://qntemp3.bejson.com/upload/72681686638249940.jpg?imageView2/0/w/0/h/0/format/webp')">取消创建</button>
<button (click)="this.setBackgroundImageVisible(false)">隐藏背景图</button>
<button (click)="this.setBackgroundImageVisible(true)">显示背景图</button>
</div>
<div #content style="width:100%;height:100%;" (mousewheel)='this.mouseWheelHandel($event)'></div>

372
src/app/working-area/working-area.component.ts

@ -20,165 +20,169 @@ export class WorkingAreaComponent implements OnInit, AfterViewInit {
loader = PIXI.Loader.shared;
// 根目录
backgroundImage: PIXI.Sprite;
// 影子
shadow = new PIXI.Sprite();
// 影子圆形
shadowCircle = new PIXI.Graphics();
// 单点图标影子
singlePointIconShadow = new PIXI.Sprite();
// 线图标影子
lineIconShadow = new PIXI.Graphics();
// 圆形影子
circleShadow = new PIXI.Graphics();
// 鼠标位置
mousePosition;
// 初始化
mousePosition: PIXI.Point;
/// 绘画模式
paintMode: PaintMode;
ngOnInit(): void {
}
// 页面初始化之后
ngAfterViewInit(): void {
setTimeout(() => {
this.init();
this.createCanvas();
}, 0);
}
// 鼠标滑动事件
mouseWheelHandel(event) {
/// <summary>
/// 鼠标滑动事件
/// <summary>
public mouseWheelHandel(event) {
const delX = this.mousePosition.x - this.backgroundImage.position.x;
const delY = this.mousePosition.y - this.backgroundImage.position.y;
const scaleX = delX / this.backgroundImage.width;
const scaleY = delY / this.backgroundImage.height;
const pivot = this.backgroundImage.toLocal(this.mousePosition);
const delta = Math.max(-1, Math.min(1, (event.wheelDelta || -event.detail)));
if (delta > 0) {
if (this.backgroundImage.scale.x >= 32) {
this.backgroundImage.scale.x = 32;
return;
}
this.backgroundImage.pivot.set(pivot.x, pivot.y);
this.backgroundImage.scale.x += this.backgroundImage.scale.x * 0.1;
this.backgroundImage.scale.y += this.backgroundImage.scale.y * 0.1;
this.backgroundImage.anchor.x += scaleX;
this.backgroundImage.anchor.y += scaleY;
this.backgroundImage.position.x += delX;
this.backgroundImage.position.y += delY;
this.backgroundImage.children.forEach(item => {
console.log(item.position);
});
} else if (delta < 0) {
if (this.backgroundImage.scale.x <= 0.1) {
this.backgroundImage.scale.y = 0.1;
return;
}
this.backgroundImage.pivot.set(pivot.x, pivot.y);
this.backgroundImage.scale.x -= this.backgroundImage.scale.x * 0.1;
this.backgroundImage.scale.y -= this.backgroundImage.scale.y * 0.1;
this.backgroundImage.anchor.x += scaleX;
this.backgroundImage.anchor.y += scaleY;
this.backgroundImage.position.x += delX;
this.backgroundImage.position.y += delY;
this.backgroundImage.children.forEach(item => {
console.log(item.position);
});
}
}
// 测试按钮
init() {
this.createCanvas();
this.createBackgroundImage('https://qntemp3.bejson.com/upload/24797865631586900.jpg?imageView2/0/w/0/h/0/format/webp');
this.createShadowIcon('https://qntemp3.bejson.com/upload/24797865631586900.jpg?imageView2/0/w/100/h/100/format/webp');
this.setShadowVisible(false);
}
// 创建画布
createCanvas(): void {
/// <summary>
/// 创建画布
/// <summary>
private createCanvas(): void {
this.app = new PIXI.Application({
width: this.content.nativeElement.clientWidth,
height: this.content.nativeElement.clientHeight,
antialias: true,
transparent: false,
resolution: 1,
backgroundColor: 0x1099bb
backgroundColor: 0x1099bb// 0xffffff
});
this.content.nativeElement.appendChild(this.app.view);
this.createBackgroundImage();
this.createSinglePointIconShadow();
this.createLineIconShadow();
this.app.ticker.add((delta) => {
this.mousePosition = this.app.renderer.plugins.interaction.mouse.global;
this.shadow.position = this.mousePosition;
this.shadowCircle.position = this.mousePosition;
});
}
// setIcon() {
// const defaultIcon = 'url(\'assets/images/avatar.jpg\'),auto';
// this.app.renderer.plugins.interaction.cursorStyles.default = defaultIcon;
// }
// // 加载资源
// LoadAsset(name: string, path: string) {
// this.loader.onProgress.add(() => {
// console.log(this.loader.progress);
// }); // called once per loaded/errored file
// this.loader.onError.add(() => { }); // called once per errored file
// this.loader.onLoad.add(() => { }); // called once per loaded file
// this.loader.onComplete.add(() => {
// alert('aaaaaaaa');
// }); // called once when the queued resources all load.
// this.loader.add(name, path);
// }
this.singlePointIconShadow.position = this.mousePosition;
this.circleShadow.position = this.mousePosition;
// 创建单点图标
createSprite(source: string, x: number, y: number, width: number, height: number, alpha: number): PIXI.Sprite {
const sprite = PIXI.Sprite.from(source);
sprite.x = x;
sprite.y = y;
sprite.width = width;
sprite.height = height;
sprite.alpha = alpha;
sprite.anchor.set(0.5);
sprite.interactive = true;
sprite.buttonMode = true;
sprite
.on('pointerdown', this.onDragStart)
.on('pointerup', this.onDragEnd)
.on('pointerupoutside', this.onDragEnd)
.on('pointermove', this.onDragMove);
this.app.stage.addChild(sprite);
sprite.setParent(this.backgroundImage);
return sprite;
}
// 拖动开始
onDragStart(event) {
event.currentTarget.data = event.data;
event.currentTarget.alpha = 0.5;
event.currentTarget.dragging = true;
}
// 拖动结束
onDragEnd(event) {
event.currentTarget.alpha = 1;
event.currentTarget.dragging = false;
event.currentTarget.data = null;
// this.lineIconShadow.clear();
// this.lineIconShadow.lineStyle(1, 0xffd900, 1);
// this.lineIconShadow.lineTo(100, 100);
});
}
// 拖动移动
onDragMove(event) {
if (event.currentTarget.dragging) {
/// <summary>
/// 创建单点图标
/// <summary>
private createSinglePointIcon(source: PIXI.Texture, x: number, y: number, width: number, height: number, alpha: number): PIXI.Sprite {
const singlePointIcon = new PIXI.Sprite(source);
singlePointIcon.x = x;
singlePointIcon.y = y;
singlePointIcon.width = width;
singlePointIcon.height = height;
singlePointIcon.alpha = alpha;
singlePointIcon.anchor.set(0.5);
singlePointIcon.interactive = true;
singlePointIcon
.on('mousedown', event => {
event.stopPropagation();
console.log(event);
event.currentTarget.data = event.data;
event.currentTarget.alpha = 0.5;
event.currentTarget.dragging = true;
})
.on('mouseup', event => {
event.currentTarget.alpha = 1;
event.currentTarget.dragging = false;
event.currentTarget.data = null;
})
.on('mouseupoutside', event => {
event.currentTarget.alpha = 1;
event.currentTarget.dragging = false;
event.currentTarget.data = null;
})
.on('mousemove', event => {
if (event.currentTarget.dragging) {
const newPosition = event.currentTarget.data.getLocalPosition(event.currentTarget.parent);
event.currentTarget.x = newPosition.x;
event.currentTarget.y = newPosition.y;
}
})
.on('rightclick', event => {
});
this.backgroundImage.addChild(singlePointIcon);
return singlePointIcon;
}
// 加载精灵图
SetupSprite(name: string) {
const sprite = new PIXI.Sprite(
this.loader.resources[name].texture
);
}
// 画圆
DrawCircle(x: number): void {
this.shadowCircle.beginFill(0xFFCC5A);
this.shadowCircle.drawCircle(0, 0, x);
this.app.stage.addChild(this.shadowCircle);
/// <>
/// 多点连线
/// <>
private createLineIcon(source: PIXI.Texture, x: number, y: number, points: PIXI.Point[]) {
const container = new PIXI.Container();
container.x = x;
container.y = y;
points.forEach(item => {
const icon = new PIXI.TilingSprite(source, 100, 64);
icon.anchor.set(0, 0.5);
icon.x = item.x;
icon.y = item.y;
container.addChild(icon);
const iconPoint = new PIXI.Graphics();
iconPoint.lineStyle(0);
iconPoint.beginFill(0xFFFF0B, 1);
iconPoint.drawCircle(item.x, item.y, 15);
iconPoint.endFill();
container.addChild(iconPoint);
});
this.backgroundImage.addChild(container);
}
// 创建背景图
createBackgroundImage(source: string): void {
this.backgroundImage = PIXI.Sprite.from(source);
/// <summary>
/// 创建背景图
/// <summary>
private createBackgroundImage(): void {
this.backgroundImage = PIXI.Sprite.from('assets/images/noImg.png');
this.backgroundImage.anchor.set(0.5);
this.backgroundImage.x = this.app.view.width / 2;
this.backgroundImage.y = this.app.view.height / 2;
this.backgroundImage.interactive = true;
this.backgroundImage.name = 'background';
this.backgroundImage
.on('pointerdown', event => {
if (!event.currentTarget.dragging) {
.on('mousedown', event => {
if (!event.currentTarget.dragging && event.currentTarget.name === this.backgroundImage.name) {
event.currentTarget.data = event.data;
// this.oldGroup = this.parentGroup;
// this.parentGroup = dragGroup;
@ -188,22 +192,36 @@ export class WorkingAreaComponent implements OnInit, AfterViewInit {
event.currentTarget.dragPoint = event.data.getLocalPosition(event.currentTarget.parent);
event.currentTarget.dragPoint.x -= event.currentTarget.x;
event.currentTarget.dragPoint.y -= event.currentTarget.y;
// tslint:disable-next-line: max-line-length
// 点击背景创建图标
const pos = this.backgroundImage.toLocal(this.mousePosition);
switch (this.paintMode) {
case PaintMode.PaintEnd:
console.log(this.backgroundImage.toLocal(this.mousePosition));
break;
case PaintMode.SinglePointIcon:
this.createSinglePointIcon(this.singlePointIconShadow.texture, pos.x, pos.y, 32, 32, 1);
break;
case PaintMode.LineIcon:
// tslint:disable-next-line: max-line-length
this.createLineIcon(this.singlePointIconShadow.texture, pos.x, pos.y, [new PIXI.Point(0, 0), new PIXI.Point(100, 0), new PIXI.Point(100, 100)]);
break;
case PaintMode.PolygonIcon:
break;
}
}
})
.on('pointerup', event => {
if (event.currentTarget.dragging) {
.on('mouseup', event => {
if (event.currentTarget.dragging && event.currentTarget.name === this.backgroundImage.name) {
event.currentTarget.dragging = false;
// this.parentGroup = this.oldGroup;
// event.currentTarget.scale.x /= 1.1;
// event.currentTarget.scale.y /= 1.1;
event.currentTarget.data = null;
console.log('创建图片');
// tslint:disable-next-line: max-line-length
this.createSprite('https://qntemp3.bejson.com/upload/72681686638249940.jpg?imageView2/0/w/100/h/100/format/webp', this.mousePosition.x, this.mousePosition.y, 64, 64, 1);
}
})
.on('pointerupoutside', event => {
if (event.currentTarget.dragging) {
.on('mouseupoutside', event => {
if (event.currentTarget.dragging && event.currentTarget.name === this.backgroundImage.name) {
event.currentTarget.dragging = false;
// this.parentGroup = this.oldGroup;
// event.currentTarget.scale.x /= 1.1;
@ -211,53 +229,115 @@ export class WorkingAreaComponent implements OnInit, AfterViewInit {
event.currentTarget.data = null;
}
})
.on('pointermove', event => {
if (event.currentTarget.dragging) {
.on('mousemove', event => {
if (event.currentTarget.dragging && event.currentTarget.name === this.backgroundImage.name) {
const newPosition = event.currentTarget.data.getLocalPosition(event.currentTarget.parent);
event.currentTarget.x = newPosition.x - event.currentTarget.dragPoint.x;
event.currentTarget.y = newPosition.y - event.currentTarget.dragPoint.y;
}
}).on('rightclick', event => {
event.stopPropagation();
this.cancelPaint();
});
this.app.stage.addChild(this.backgroundImage);
}
addShadow(obj) {
const graphics = new PIXI.Graphics();
// Circle
graphics.lineStyle(0);
graphics.beginFill(0xDE3249, 1);
graphics.drawCircle(100, 250, 50);
graphics.endFill();
obj.addChild(graphics);
}
// 设置背景显示状态
setBackgroundImageVisible(value: boolean): void {
this.backgroundImage.visible = value;
}
// 替换背景图
replaceBackgroundImage(source: string): void {
/// <summary>
/// 替换背景图
/// 参数{source:string} 可以是一个url地址,也可以是本地assets下的一个图片路径
/// <summary>
public changeBackgroundImage(source: string): void {
this.backgroundImage.texture = PIXI.Texture.from(source);
this.backgroundImage.visible = true;
}
/// <summary>
/// 创建单点图标影子
/// <summary>
private createSinglePointIconShadow(): void {
this.singlePointIconShadow = PIXI.Sprite.from('assets/images/noImg.png');
this.singlePointIconShadow.width = 32;
this.singlePointIconShadow.height = 32;
this.singlePointIconShadow.alpha = 0.5;
this.singlePointIconShadow.anchor.set(0.5);
this.singlePointIconShadow.visible = false;
this.app.stage.addChild(this.singlePointIconShadow);
}
// 创建影子图标
createShadowIcon(source: string): void {
this.shadow = PIXI.Sprite.from(source);
this.shadow.alpha = 0.5;
this.shadow.anchor.set(0.5);
this.app.stage.addChild(this.shadow);
/// <summary>
/// 改变单点图标影子
/// <summary>
private changeSinglePointIconShadow(source: string): void {
this.singlePointIconShadow.texture = PIXI.Texture.from(source);
this.singlePointIconShadow.visible = true;
}
// 设置影子图标显示状态
setShadowVisible(value: boolean): void {
this.shadow.visible = value;
/// <>
/// 创建线图标影子
/// <>
private createLineIconShadow() {
this.app.stage.addChild(this.lineIconShadow);
}
// 替换影子图片
replaceShadow(source: string): void {
this.shadow.texture = PIXI.Texture.from(source);
/// <summary>
/// 开始绘画单点图标
/// <summary>
public beginPaintSinglePointIcon(source: string): void {
this.cancelPaint();
this.paintMode = PaintMode.SinglePointIcon;
this.changeSinglePointIconShadow(source);
}
// 创建单点图标
createSinglePointIcon(source: string): void {
this.DrawCircle(5);
// this.setShadowVisible(true);
// this.addShadow(this.shadow);
// this.replaceShadow(source);
// 开始绘画多边形
public beginPaintPolygonIcon(source: string): void {
this.cancelPaint();
this.paintMode = PaintMode.PolygonIcon;
}
// 开始绘画线
public beginPaintLineIcon(source: string): void {
this.cancelPaint();
this.paintMode = PaintMode.LineIcon;
this.changeSinglePointIconShadow(source);
// this.lineIconShadow.lineStyle(1, 0xffd900, 1);
}
/// <summary>
/// 取消绘画
/// <summary>
private cancelPaint(): void {
switch (this.paintMode) {
case PaintMode.PaintEnd:
break;
case PaintMode.SinglePointIcon:
this.paintMode = PaintMode.PaintEnd;
this.singlePointIconShadow.visible = false;
break;
case PaintMode.LineIcon:
this.paintMode = PaintMode.PaintEnd;
this.singlePointIconShadow.visible = false;
break;
case PaintMode.PolygonIcon:
this.paintMode = PaintMode.PaintEnd;
break;
}
}
/// <summary>
/// 画圆
/// <summary>
paintShadowCircle(x: number): void {
this.circleShadow.beginFill(0xFFCC5A);
this.circleShadow.drawCircle(0, 0, x);
this.app.stage.addChild(this.circleShadow);
}
/// <summary>
/// 取消画圆
/// <summary>
cancelPaintShadowCircle(): void {
this.app.stage.removeChild(this.circleShadow);
}
}
/// <summary>
/// 绘制模式
/// <summary>
enum PaintMode {
SinglePointIcon,
LineIcon,
PaintingLineIcon,
PolygonIcon,
PaintEnd,
}

1
src/index.html

@ -6,7 +6,6 @@
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<!-- <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"> -->
<link href='./assets/icon/material-icons.css' rel="stylesheet">
</head>
<body>

Loading…
Cancel
Save