当前位置:网站首页>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
边栏推荐
- CDH6之Sqoop添加数据库驱动
- SparkContext: Error initializing SparkContext解决方法
- 高德地图测试用例
- LeetCode—<动态规划专项>剑指 Offer 19、49、60
- Differences between nodes and sharding in ES cluster
- (C语言)八进制转换十进制
- 寻找二叉树中任意两个数的公共祖先
- From scratch, develop a web office suite (3): mouse events
- FastDateFormat为什么线程安全
- Addition, deletion, modification and query of MySQL table (Advanced)
猜你喜欢
Larvel modify table fields
Read the Flink source code and join Alibaba cloud Flink group..
How does Premiere (PR) import the preset mogrt template?
AI中台技术调研
CDH6之Sqoop添加数据库驱动
mysql索引和事务
SVO2系列之深度濾波DepthFilter
Lekao: contents of the provisions on the responsibility of units for fire safety in the fire protection law
CDA数据分析——AARRR增长模型的介绍、使用
Tas (file d'attente prioritaire)
随机推荐
GGPlot Examples Best Reference
mysql数据库基础
初始JDBC 编程
Input a three digit number and output its single digit, ten digit and hundred digit.
CDA数据分析——AARRR增长模型的介绍、使用
B high and beautiful code snippet sharing image generation
甜心教主:王心凌
ORB-SLAM2不同线程间的数据共享与传递
Heap (priority queue)
[C language] convert decimal numbers to binary numbers
MSI announced that its motherboard products will cancel all paper accessories
How does Premiere (PR) import the preset mogrt template?
LeetCode—<动态规划专项>剑指 Offer 19、49、60
子线程获取Request
全链路压测
Fastdateformat why thread safe
Leetcode209 长度最小的子数组
Test shift left and right
From scratch, develop a web office suite (3): mouse events
drools执行完某个规则后终止别的规则执行