雨林笔记-前端个人技术记录 - TS
type: channel
link: https://www.mqllin.cn/category/TS/
items: arcgis 坐标转换
items: Arcgis Draw 绘制图形
items: Laya常用方法封装

arcgis 坐标转换
type: item
date: 2021-04-23T08:16:00+08:00
description: Cgcs2000ToWgs84(lng, lat, wkid): Point { return projection.project(new Point({ longitude: parseFloat(lng), latitude: parseFloat(lat), spatialReference: {wkid} }), {wkid: 4326}) as Point; }

Arcgis Draw 绘制图形
type: item
date: 2021-04-20T15:01:00+08:00
description: 记录一下draw的绘图方法 HTML+JS代码保存过程中格式化出现了问题，手动恢复格式后可能会出现不对的地方，切记不可直接复制粘贴。更多的是参考思路。// 绑定面按钮绘制事件 const; drawAreaButton = document.getElementById('query-area-button'); drawAreaButton; . onclick = () => { if (that.showPolyline) { that.stateService.map.remove(that.stateService.map.findLayerById('polygon')); that.showAreaDataTree = false; that.showPolyline = false; } else { this.stateService.activeTool$.next('query-area-button'); that.enableCreateArea(draw, that.stateService.view); } }; // ==================绘图方法=========================== // /** * 开始监听画线 */ enableCreateLine(draw, view): void { const action = draw.create('polyline', {mode: 'click'}); let graphicsLayer = view.map.findLayerById('polyline') as GraphicsLayer; if (!graphicsLayer) { graphicsLayer = new GraphicsLayer({title: 'polyline', id: 'polyline', listMode: 'hide',}); view.map.add(graphicsLayer); } // 获取焦点 view.focus(); // 顶点添加事件 action.on('vertex-add', (event) => { this.createPolyline(event, graphicsLayer); }); // 顶点移除事件 action.on('vertex-remove', (event) => { this.createPolyline(event, graphicsLayer); }); // 鼠标移动事件 action.on('cursor-update', (event) => { this.createPolyline(event, graphicsLayer); }); // 绘制完成事件 action.on('draw-complete', (event) => { this.createPolyline(event, graphicsLayer); }); } /** * 开始监听画面 绘制多边形 */ enableCreateArea(draw, view): void { const action = draw.create('polygon', { mode: 'click'// 点击方式加点 }); let graphicsLayer = view.map.findLayerById('polygon') as GraphicsLayer; if (!graphicsLayer) { graphicsLayer = new GraphicsLayer({title: '多边形区域查询', id: 'polygon', listMode: 'hide',}); view.map.add(graphicsLayer); } // 获取焦点 view.focus(); // 顶点添加事件 action.on('vertex-add', (event) => { this.createPolygon(event, graphicsLayer); }); // 顶点移除事件 action.on('vertex-remove', (event) => { this.createPolygon(event, graphicsLayer); }); // 鼠标移动事件 action.on('cursor-update', (event) => { this.createPolygon(event, graphicsLayer); }); // 绘制完成事件 action.on('draw-complete', (event) => { this.showPolyline = true; this.c…

Laya常用方法封装
type: item
date: 2020-10-21T13:50:00+08:00
description: 1.随机数（TS脚本） Laya内已有随机数方法以0~1取值为基准，拓展后，任意正整数区间，代码如下 /** * 随机数 * @param min 最小数 * @param max 最大数 */ private randomNumber(min: any, max: any): any { return Math.floor( parseInt( Math.random() * (max - min + 1) + min, 10) ); } 2.复制到粘贴板（JS脚本） 将文本在鼠标或手机复制到粘贴板，代码如下 CopyUrl: function (url) { const t = document.createElement('textarea'); t.value = url; t.style.visibility = true; // 加入文档流中 document.body.appendChild(t); // 选中textarea的内容，并拷贝到剪切板 t.select(); document.execCommand('copy'); // 删除隐藏的textarea t.parentElement.removeChild(t); }