当前位置:网站首页>arcgis js 4. Add pictures to x map
arcgis js 4. Add pictures to x map
2022-07-02 12:13:00 【Ostrich5yw】
arcgis js 4.x edition , How to add pictures
problem : How to put custom pictures into arcgis In the layer of ?
Among the methods I found on the Internet , It is found that most methods only apply to 3.x edition , There is only one way to introduce customization BaseDynamicLayer The methods available , However, in this way , Unable to meet the needs of dynamically refreshing pictures .
resolvent
step 1: Or use BaseDynamicLayer Introduce pictures
var mainMap = new Map({
basemap:"satellite",
ground: "world-elevation",
});
// establish MapView To store various layers
var mainView = new MapView({
map:mainMap,
container:"viewDiv",
center:[110.3147025,37.5991070],
zoom:13,
});
var CustomImageOverlayLayer = BaseDynamicLayer.createSubclass({
properties: {
picUrl: null,
extent: null,
image: null,
canvas: null,
},
// Override the getImageUrl() method to generate URL
// to an image for a given extent, width, and height.
getImageUrl: function (extent, width, height) {
// new Image object , It can be understood as DOM
if (!this.image) {
this.image = new Image();
}
this.image.src = this.picUrl;
// establish canvas DOM Elements , And set its width and height to be the same as the picture
if (!this.canvas) {
this.canvas = canvas = document.createElement("canvas");
}
this.canvas.width = 2000;
this.canvas.height = 2000;
// The coordinates of the upper left corner convert the screen coordinates , In order to obtain canvas The starting point for drawing pictures
var mapPoint = {
x: this.extent.xmin,
y: this.extent.ymax,
spatialReference: {
wkid: 4326
}
};
var screenPoint = mainView.toScreen(mapPoint);
// according to extent Range calculation canvas Draw the width and height of the picture
// The lower left corner
var leftbottom = {
x: this.extent.xmin,
y: this.extent.ymin,
spatialReference: {
wkid: 4326
}
};
var screen_leftbottom = mainView.toScreen(leftbottom);
// Upper right corner
var righttop = {
x: this.extent.xmax,
y: this.extent.ymax,
spatialReference: {
wkid: 4326
}
};
var screen_righttop = mainView.toScreen(righttop);
this.canvas.getContext("2d").drawImage(this.image, screenPoint.x, screenPoint.y, Math.abs(screen_righttop.x - screen_leftbottom.x), Math.abs(screen_righttop.y - screen_leftbottom.y));
return this.canvas.toDataURL("image/png");
}
});
const temp = ["t=0.png", "t=180.png","t=360.png","t=540.png","t=1080.png","t=1260.png","t=1440.png","t=1620.png","t=1800.png","t=1980.png","t=2160.png","t=2340.png","t=2520.png","t=2880.png","t=3060.png","t=3420.png","t=3600.png"] // Name of the image to be traversed
var ImageOverlayLayer = new CustomImageOverlayLayer({
picUrl: "../images/changePic/"+temp[0], // Picture path
extent: {
xmin: 110.2237025, ymin: 37.5121070, xmax:110.4497025, ymax: 37.6551070} // Picture location ( Maximum and minimum longitude and latitude )
})
mainMap.add(ImageOverlayLayer, 0); // Put the picture layer into mainMap, And set it at the bottom
step 2( The key ): Realize the dynamic switching of pictures
function showTime()
{
ImageOverlayLayer.refresh()
}
setInterval(showTime, 1); // Set the layer to refresh automatically every second ( Very important )
for(var i = 1; i < 17; i++) {
(function (i) {
setTimeout(function () {
// Set the timer , Refresh the next picture every three seconds
ImageOverlayLayer.picUrl = "../images/changePic/"+temp[i] // Update the image path and refresh the layer
ImageOverlayLayer.refresh()
}, (i + 1) * 3000);
})(i)
}
thus , It can be realized in arcgis js 4.x, Dynamic switching of pictures 
边栏推荐
猜你喜欢

The blink code based on Arduino and esp8266 runs successfully (including error analysis)

Sort---

CDA data analysis -- Introduction and use of aarrr growth model

Take you ten days to easily finish the finale of go micro services (distributed transactions)

Map and set

自然语言处理系列(三)——LSTM

Discrimination of the interval of dichotomy question brushing record (Luogu question sheet)

Filtre de profondeur de la série svo2

Mysql database foundation

Natural language processing series (II) -- building character level language model using RNN
随机推荐
子线程获取Request
Log4j2
Test shift left and right
Larvel modify table fields
CDH存在隐患 : 该角色的进程使用的交换内存为xx兆字节。警告阈值:200字节
YYGH-BUG-05
YYGH-BUG-04
字符串回文hash 模板题 O(1)判字符串是否回文
Thesis translation: 2022_ PACDNN: A phase-aware composite deep neural network for speech enhancement
CDA data analysis -- common knowledge points induction of Excel data processing
Jenkins用户权限管理
二分刷题记录(洛谷题单)区间的甄别
Leetcode922 sort array by parity II
H5, add a mask layer to the page, which is similar to clicking the upper right corner to open it in the browser
Day12 control flow if switch while do While guessing numbers game
刷题---二叉树--2
Leetcode922 按奇偶排序数组 II
Full link voltage measurement
排序---
Intel 内部指令 --- AVX和AVX2学习笔记