gis多个图层地图用htmlcanvas截图获取不到

gis多个图层地图用htmlcanvas截图获取不到,第1张

找到两个前端就能解决的方法,最后因为各种原因采用了方法二。

        方法一:

                找到地图上的全部点,然后在canvas上面重绘一次。

html2canvas(this$refstarget, {

useCORS: true, // 如果截图的内容里有,可能会有跨域的情况,加上这个参数,解决文件跨域问题

})then((canvas) => {

let cans = canvasgetContext("2d");

//批量地图重新打点 加载

documentquerySelectorAll("#mapView_layers image")forEach((item) => {

var obj = item;

var x = itemgetAttribute("x");

var y = itemgetAttribute("y");

var itemWidth = itemgetAttribute("width");

var itemHeight = itemgetAttribute("height");

consolelog("item", item, x, y);

if (width == 8) {

cansdrawImage(obj, x, y, itemWidth, itemHeight);

} else {

cansdrawImage(

obj,

x ,

y - 1 - itemHeight / 2 ,

itemWidth,

itemHeight

);

}

});

//下面是截图代码

})

登录后复制

因为本身目标dom的position定位问题,最后打的点可能会出现偏移。

所以还要给html2canvas加几个属性: x , y , scrollX , scrollY。保险起见,再加上两个参数 width 和 height 。

本人是后面chrome测着没问题,但是给小伙伴测试的时候,他用的360浏览器还有个xx浏览器有点问题。干脆参数全加上。

screenShot() {

let canvasBox = this$refstarget;

//获取目标div位置;

var tPosition = canvasBoxgetBoundingClientRect();

consolelog("size", tPosition);

// 获取父级的宽高

const width = parseInt(windowgetComputedStyle(canvasBox)width);

const height = parseInt(windowgetComputedStyle(canvasBox)height);

html2canvas(this$refstarget, {

width: width,

height: height,

x: 0,

y: 0,

scrollY: -tPositiony,

scrollX: -tPositionx,

useCORS: true, // 如果截图的内容里有,可能会有跨域的情况,加上这个参数,解决文件跨域问题

})then((canvas) => {

})

}

登录后复制

要是项目的地图是不可移动的,基本到这里就可以了。

但是地图只要一挪动。。一个新的bug出现了。。。。。整个地图画线打点层的偏移量和截图之前不一样。。。。 截图后,画线层偏的比原地图还要远,打点却还在原位没动过。。

这个问题需要修正svg的偏移,然后这个标注点绘制的时候也要加上一个偏移量。

地图偏移的bug后面再讲。

         方法二:(最后采用)

                把svg中所有的<image>的href路径转换为base64编码格式。简单方便,不用考虑位置什么的问题,就是有些浏览器里面加载慢。。。setTimeout有时候要设置大一点。。

screenShot() {

let canvasBox = this$refstarget;

//获取目标div位置;

var tPosition = canvasBoxgetBoundingClientRect();

consolelog("size", tPosition);

// 获取父级的宽高

const width = parseInt(windowgetComputedStyle(canvasBox)width);

const height = parseInt(windowgetComputedStyle(canvasBox)height);

//---------------------

//解决svg 内部image加载不了的问题,把image改为base64,配合setTimeout html2canvas使用

documentquerySelectorAll("#mapView_layers image")forEach((item) => {

consolelog("item", item);

var img = itemgetAttribute("xlink:href");

consolelog("href", img);

var image = new Image();

imagecrossOrigin = "";

imagesrc = img;

imageonload = () => {

var base64 = getBase64Image(image);

itemsetAttribute("xlink:href", base64); //更改href属性

};

});

//地址转为base64编码

function getBase64Image(img) {

var canvas = documentcreateElement("canvas");

canvaswidth = imgwidth;

canvasheight = imgheight;

var ctx = canvasgetContext("2d");

ctxdrawImage(img, 0, 0, imgwidth, imgheight);

var ext = imgsrcsubstring(imgsrclastIndexOf("") + 1)toLowerCase();

var dataURL = canvastoDataURL("image/" + ext);

return dataURL;

}

setTimeout(() => {

html2canvas(this$refstarget, {

width: width,

height: height,

x: 0,

y: 0,

scrollY: -tPositiony,

scrollX: -tPositionx,

useCORS: true, // 如果截图的内容里有,可能会有跨域的情况,加上这个参数,解决文件跨域问题

})then((canvas) => {

})

}, 200);

}

登录后复制

1、首先需要打开ArcMap软件,点击“添加数据”工具图标。

2、在d出的对话框中选择准备的数据图层

3、然后就看到数据图层显示在了视图区域内。

4、在arcMap菜单栏中选择“选择”——“按属性选择”选项,d出“按属性选择对话框”。

5、在“按属性选择”对话框中,字段列表中选择“GB”,单击“获取唯一值”按钮,在下方的文本框中输入  "GB" = 420101  单击确定。

6、在视图区域内,可以看到选择的要素已经高度显示。在左侧列表右键单击图层,选择下拉菜单 “数据”——“导出数据”。

7、在d出的导出数据对话框中,上面的红框区域都选择默认,下方的红框选择你想导出的路径,并命名图层,点击确定。

8、在视图区域中,把原图层前面的勾选项去掉,就看到导出的数据图层的显示。

以上就是关于gis多个图层地图用htmlcanvas截图获取不到全部的内容,包括:gis多个图层地图用htmlcanvas截图获取不到、在arcgis中如何把通过属性选择的要素提取保存、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/9340157.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-27
下一篇2023-04-27

发表评论

登录后才能评论

评论列表(0条)

    保存