当前位置:网站首页>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 
边栏推荐
- MySQL indexes and transactions
- 史上最易懂的f-string教程,收藏這一篇就够了
- The differences and relationships among port, targetport, nodeport and containerport in kubenetes
- Take you ten days to easily finish the finale of go micro services (distributed transactions)
- Uniapp uni list item @click, uniapp uni list item jump with parameters
- drools决策表的简单使用
- (C语言)八进制转换十进制
- Yygh-9-make an appointment to place an order
- 刷题---二叉树--2
- String palindrome hash template question o (1) judge whether the string is palindrome
猜你喜欢

自然语言处理系列(一)——RNN基础

甜心教主:王心凌

jenkins 凭证管理

mysql表的增删改查(进阶)

Natural language processing series (III) -- LSTM

Sort---

Larvel modify table fields

测试左移和右移

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

Fresh, 2022 advanced Android interview must know 100 questions (interview questions + answer analysis)
随机推荐
Leetcode209 长度最小的子数组
Read the Flink source code and join Alibaba cloud Flink group..
Leetcode922 按奇偶排序数组 II
Log4j2
子线程获取Request
堆(优先级队列)
From scratch, develop a web office suite (3): mouse events
How does Premiere (PR) import the preset mogrt template?
Dynamic debugging of multi file program x32dbg
Discrimination of the interval of dichotomy question brushing record (Luogu question sheet)
史上最易懂的f-string教程,收藏这一篇就够了
(C language) octal conversion decimal
Filtre de profondeur de la série svo2
drools执行完某个规则后终止别的规则执行
[old horse of industrial control] detailed explanation of Siemens PLC TCP protocol
Yygh-9-make an appointment to place an order
Log4j2
H5, add a mask layer to the page, which is similar to clicking the upper right corner to open it in the browser
字符串回文hash 模板题 O(1)判字符串是否回文
Find the factorial of a positive integer within 16, that is, the class of n (0= < n < =16). Enter 1111 to exit.