Browse Source

[新增]测试导出gis图片

tangshan
邵佳豪 4 years ago
parent
commit
3ab068efe7
  1. 23
      package-lock.json
  2. 1
      package.json
  3. 3
      src/app/gis-management/gis-labeling/gis-labeling.component.html
  4. 40
      src/app/gis-management/gis-labeling/gis-labeling.component.ts
  5. 17
      src/app/plan-management/create-plan-online-five/create-plan-online-five.component.html
  6. 48
      src/app/plan-management/create-plan-online-five/create-plan-online-five.component.scss
  7. 31
      src/app/plan-management/create-plan-online-five/create-plan-online-five.component.ts
  8. 22
      src/assets/html2canvas.js
  9. 1
      src/index.html

23
package-lock.json generated

@ -6849,6 +6849,21 @@
"timsort": "^0.3.0"
}
},
"css-line-break": {
"version": "1.1.1",
"resolved": "https://registry.npm.taobao.org/css-line-break/download/css-line-break-1.1.1.tgz",
"integrity": "sha1-1em90peEAJnrBQPHMQ/TSSegJu8=",
"requires": {
"base64-arraybuffer": "^0.2.0"
},
"dependencies": {
"base64-arraybuffer": {
"version": "0.2.0",
"resolved": "https://registry.npm.taobao.org/base64-arraybuffer/download/base64-arraybuffer-0.2.0.tgz",
"integrity": "sha1-S5RPrAGRqlkHr+LYyZnMxXzoD0U="
}
}
},
"css-parse": {
"version": "2.0.0",
"resolved": "https://registry.npm.taobao.org/css-parse/download/css-parse-2.0.0.tgz",
@ -9364,6 +9379,14 @@
"integrity": "sha1-DfKTUfByEWNRXfueVUPl9u7VFi8=",
"dev": true
},
"html2canvas": {
"version": "1.0.0-rc.7",
"resolved": "https://registry.npm.taobao.org/html2canvas/download/html2canvas-1.0.0-rc.7.tgz",
"integrity": "sha1-cMFZzg5jlUqRFpUxiU0IrVYnrJg=",
"requires": {
"css-line-break": "1.1.1"
}
},
"http-cache-semantics": {
"version": "3.8.1",
"resolved": "https://registry.npm.taobao.org/http-cache-semantics/download/http-cache-semantics-3.8.1.tgz",

1
package.json

@ -34,6 +34,7 @@
"e-ngx-cesium": "^6.3.2",
"echarts": "^4.6.0",
"firebase": "^7.6.2",
"html2canvas": "^1.0.0-rc.7",
"ng-zorro-antd": "^9.3.0",
"ng2-file-upload": "^1.4.0",
"ngx-countdown": "^9.0.1",

3
src/app/gis-management/gis-labeling/gis-labeling.component.html

@ -1,5 +1,6 @@
<div class="content">
<!-- <button mat-button style="position: absolute;left: 50%;top: 0;z-index: 999;" (click)="createimg()">生成图片</button> -->
<div id="map"></div>
<div id="container" style="height: 100%;"></div>
<!-- 左上搜索框 -->
@ -280,3 +281,5 @@
</div>
<!-- 右上角 -->
</div>

40
src/app/gis-management/gis-labeling/gis-labeling.component.ts

@ -5,7 +5,8 @@ import { MatDialog, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dial
import { MatSnackBar, MatSnackBarConfig } from '@angular/material/snack-bar';
declare var AMap: any;
declare var QRCode: any;
declare var html2canvas: any;
// import html2canvas from 'html2canvas';
@Component({
selector: 'app-gis-labeling',
templateUrl: './gis-labeling.component.html',
@ -156,6 +157,43 @@ export class GisLabelingComponent implements OnInit {
})
}
//生成图片
canvasImg
createimg(){
// 使用html2canvas插件,将数据源中的数据转换成画布。
html2canvas(document.querySelector("#map"),{
useCORS: true, // 【重要】开启跨域配置,
allowTaint: true,//允许跨域图片
taintTest: false,//是否在渲染前测试图片
onrendered: function(canvas) {
var dataUrl = canvas.toDataURL("image/png");
}
}).then(canvas => {
// 修改生成的宽度
// canvas.style.width = "1000px";
console.log(canvas, "生成的画布文件");
this.canvasImg = canvas.toDataURL("image/png");
// console.log(this.canvasImg)
}).then(()=>{
this.downloadFile("导出图片", this.canvasImg);
})
}
downloadFile(filename, content) {
var base64Img = content;
var oA = document.createElement('a');
oA.href = base64Img;
oA.download = filename;
var event = document.createEvent('MouseEvents');
event.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
oA.dispatchEvent(event);
}
//构造重点单位checkbox控制器
buildUnits() {
const arr = this.keyUnitList.map(item => {

17
src/app/plan-management/create-plan-online-five/create-plan-online-five.component.html

@ -307,7 +307,22 @@
</div>
</div>
<div class="disposalPoint" *ngIf="item.groupName == '预案附件'">
处置要点
<div class="disposalPointItem" *ngFor="let i of item.attribute;let key = index">
<div class="disposalPointTitle">
<input type="text" placeholder="请输入分组名称" [(ngModel)]="i.name">
<mat-icon class="deleteItem" *ngIf="key != 0" (click)="deleteItem(item,key)">delete
</mat-icon>
</div>
<div class="disposalPointTextarea">
<textarea [(ngModel)]="i.cantent" style="resize: none;" placeholder="请填写自定义内容" name="" id="" cols="30" rows="10"></textarea>
</div>
</div>
<!-- 增加分组 -->
<div class="addDisposalPointItem">
<button mat-flat-button color="primary" (click)="addDisposalPointItem(item)">
增加分组
</button>
</div>
</div>
</div>
</div>

48
src/app/plan-management/create-plan-online-five/create-plan-online-five.component.scss

@ -410,6 +410,54 @@
margin: 10px 0;
}
}
.disposalPoint {
div {
width: 100%;
}
.disposalPointItem {
border: 1px solid #e8e9e9;
.disposalPointTitle {
height: 30px;
border-left: 1px solid #2196f3;
position: relative;
input {
width: 100%;
height: 100%;
background: #e8f4fe;
color: #2196f3;
border: 0;
box-sizing: border-box;
padding: 0 5px;
}
.deleteItem {
position: absolute;
right: 5px;
top: 3px;
cursor: pointer;
color: #292c2c;
}
.deleteItem:hover {
color: red;
}
}
.disposalPointTextarea {
textarea {
width: 100%;
height: 100%;
border: 0;
resize: none;
vertical-align: top;
box-sizing: border-box;
padding: 5px;
}
}
}
.addDisposalPointItem {
display: flex;
justify-content: center;
margin: 10px 0;
}
}
}
}
}

31
src/app/plan-management/create-plan-online-five/create-plan-online-five.component.ts

@ -133,6 +133,11 @@ export class CreatePlanOnlineFiveComponent implements OnInit {
element.attribute = [{ name: '', imgArr: [] }]
}
}
if (element.groupName == '预案附件') {
if (!element.attribute) {
element.attribute = [{ name: '', content: '' }]
}
}
});
})
}
@ -142,17 +147,13 @@ export class CreatePlanOnlineFiveComponent implements OnInit {
addkeyImgItem(item) {
item.attribute.push({ name: '', imgArr: [] })
}
//处置要点增加分组
addDisposalPointItem(item) {
item.attribute.push({ name: '', content: '' })
}
//通过左侧查看实景图
gallery
lookkeyImgItemLeft(key1, key2,i) {
// setTimeout(() => {
// if (document.getElementById('viewerjs')) {
// this.gallery = new Viewer(document.getElementById('viewerjs'), {
// url: 'data-original'
// });
// console.log('这个号甲就',document.getElementById('viewerjs'))
// }
// }, 0);
let dom = document.getElementById(`viewerjs`)
let pObjs = dom.childNodes;
let node = document.createElement("img")
@ -179,9 +180,9 @@ export class CreatePlanOnlineFiveComponent implements OnInit {
}
});
}
//重点图示删除指定分组
//重点图示,处置要点删除指定分组
deleteItem(item, key) {
let isDelete = window.confirm('确定要删除该分组吗?分组下上传的图片将一同被删除!')
let isDelete = window.confirm('确定要删除该分组吗?分组下内容将一同被删除!')
if (isDelete) {
item.attribute.splice(key, 1)
}
@ -351,16 +352,6 @@ export class CreatePlanOnlineFiveComponent implements OnInit {
}
export interface unitData {
name: string,
organizationName: number,
buildingTypes: buildingTypes[]
}
export interface buildingTypes {
id: string,
name: string,
}
//查看预案
@Component({

22
src/assets/html2canvas.js

File diff suppressed because one or more lines are too long

1
src/index.html

@ -26,5 +26,6 @@
<script src="http://10.81.73.39:8000/webapi/ui/1.1/main.js"></script> -->
<script src="https://webapi.amap.com/maps?v=2.0&key=e4b359dc7b03f9418b7497f807131346&plugin=AMap.Driving,AMap.MouseTool,AMap.RangingTool"></script>
<script src="https://webapi.amap.com/ui/1.1/main.js"></script>
<script src="/assets/html2canvas.js"></script>
</html>

Loading…
Cancel
Save