当前位置:网站首页>Vectortilelayer replacement style
Vectortilelayer replacement style
2022-07-26 09:53:00 【Zhou Xiaotiao】
Problem description :
Base map ( Vector slice layer url) unchanged , But you need to add different style Form the effect of animation rotation .
It's not difficult to change the style of the layer , Find the corresponding feature, Use feature.setStyle That's all right. . But the problem I encountered in the project was that I couldn't get feature, Or get feature Unavailable ( As soon as my colleague came across the use of feature.setStyle Not in effect , Finally, the reason was not found , Finally, add layers of different styles each time you change the style , Then add a pile of layers, Resulting in a very large map ).
This article is about no feature How to change the style when ——layer.setStyle
Code details :
// prop: Used for splicing url Of
// layerId: Layers id, Unique identification
// geom: Used to change different style
loadRainForcastLayer(prop, layerId,geom) {
let levelJson = JSON.parse(geom);
// style and setStyle Methods will appear this Point to different problems , So first put it forward
let that = this
// Find all in the map layer, Judge whether the layer to be added already exists
this.getLayers().forEach((layer) => {
if (layer.getProperties().id&&layer.getProperties().id == layerId) {
this.rainForcastLayer = layer;
}
});
// If the layer exists , Change the style directly
if (this.rainForcastLayer) {
this.rainForcastLayer.setVisible(true);
this.rainForcastLayer.setStyle(function(feature,res){
let id = feature.get("id");
// Down here adopt id Get the style of the layer Color ↓
let number=levelJson[id]?levelJson[id]:0
let level=that.getLevel(number)
let text=String(number)==0?"":String(number)
let color=conf.mapViewer.Predicforeca[level]
// From here up adopt id Get the style of the layer Color ↑
let vectorTileStyle = new Style({
stroke: new Stroke({
color: "rgba(255,255,255,0)",
width: 2,
}),
fill: new Fill({
color: color
}),
text: new Text({
// Text style
font: '12px Calibri,sans-serif',
fill: new Fill({
color: '#000'
}),
stroke: new Stroke({
color: '#000',
width: 1,
}),
// Pay attention to this text Can only be string Format , So the previous conversion
text:text
}),
});
return vectorTileStyle
})
return;
}
let style = "";
// Start splicing here url, If there is a complete available url You can skip this paragraph ↓
var gridsetName = "EPSG:4326";
var gridNames = [
"EPSG:4326:0",
"EPSG:4326:1",
"EPSG:4326:2",
"EPSG:4326:3",
"EPSG:4326:4",
"EPSG:4326:5",
"EPSG:4326:6",
"EPSG:4326:7",
"EPSG:4326:8",
"EPSG:4326:9",
"EPSG:4326:10",
"EPSG:4326:11",
"EPSG:4326:12",
"EPSG:4326:13",
"EPSG:4326:14",
"EPSG:4326:15",
"EPSG:4326:16",
"EPSG:4326:17",
"EPSG:4326:18",
];
let format = "application/vnd.mapbox-vector-tile";
var resolutions = [0.703125, 0.3515625, 0.17578125, 0.087890625, 0.0439453125, 0.02197265625, 0.010986328125, 0.0054931640625, 0.00274658203125, 0.001373291015625, 6.866455078125E-4, 3.4332275390625E-4, 1.71661376953125E-4, 8.58306884765625E-5, 4.291534423828125E-5, 2.1457672119140625E-5, 1.0728836059570312E-5, 5.364418029785156E-6, 2.682209014892578E-6, 1.341104507446289E-6, 6.705522537231445E-7, 3.3527612686157227E-7];
let vectorTileParams = {
REQUEST: "GetTile",
SERVICE: "WMTS",
VERSION: "1.0.0",
LAYER: prop.layer,
STYLE: style,
TILEMATRIX: gridsetName + ":{z}",
TILEMATRIXSET: gridsetName,
FORMAT: format,
TILECOL: "{x}",
TILEROW: "{y}",
};
var projection = new Projection({
code: "EPSG:4326",
units: "degrees",
axisOrientation: "neu",
});
let baseUrl = ipConfig.geoServer + "/gwc/service/wmts";
let url = baseUrl + "?";
for (var param in vectorTileParams) {
url = url + param + "=" + vectorTileParams[param] + "&";
}
// End the splicing here url, If there is a complete available url You can skip this paragraph ↑
// Add this layer for the first time
this.rainForcastLayer = new VectorTileLayer({
style: function(feature){
let id = feature.get("id");
let number=levelJson[id]?levelJson[id]:0;
let level=that.getLevel(number)
let text=String(number)==0?"":String(number)
let color=conf.mapViewer.Predicforeca[level]
let styles=new Style({
stroke: new Stroke({
color: "rgba(255,255,255,0)",
width: 2,
}),
fill: new Fill({
color: color
}),
text: new Text({
// Text style
font: '12px Calibri,sans-serif',
stroke: new Stroke({
color: '#000',
width: 1,
}),
fill: new Fill({
color: '#000'
}),
text:text
})
})
return styles;
},
zIndex: ZINDEXCONSTANT.NINECLASSLAYER,
id: layerId,
projection: projection,
maxResolution: 350,
source: new VectorTileSource({
projection: projection,
tileGrid: new WMTSTileGrid({
tileSize: [256, 256],
origin: [-180.0, 90.0],
resolutions: resolutions,
matrixIds: gridNames,
}),
format: new MVT(),
url: url,
wrapX: true,
tilePixelRatio: 1,
}),
});
this.addLayer(this.rainForcastLayer);
}
The method of map operation is written , Then set a timer directly when animating :
play(){
this.timeInterval = setInterval(() => {
if (this.currentRowIndex < this.forecastList.length - 1) {
this.currentRowIndex++;
} else {
this.currentRowIndex = 0;
}
this.levelJson=JSON.parse(this.forecastList[this.currentRowIndex].predicProduct)
this.loadRainForcastLayer(
{
key: 'layer-rainForcast',
layer:"meteo_qpf:QPF",
title: ' Rainfall forecast ',
},
"layer-rainForcast",
this.forecastList[this.currentRowIndex].predicProduct
);
}, 3000);}
Then when it stops :
stop(){
// Hide the corresponding layer
this.rainForcastLayer && this.rainForcastLayer.setVisible(false);
// Clear timer
clearInterval(this.timeInterval)
}
Then the function can be completed !
边栏推荐
- (2) Hand eye calibration of face scanner and manipulator (eye out of hand: nine point calibration)
- 苹果独占鳌头,三星大举复兴,国产手机在高端市场颗粒无收
- Interpretation of the standard of software programming level examination for teenagers_ second level
- MySQL的逻辑架构
- 官方颁发的SSL证书与自签名证书结合实现网站双向认证
- SSG framework Gatsby accesses the database and displays it on the page
- Show default image when wechat applet image cannot be displayed
- EOJ 2020 January race E-number transformation
- 阿里云技术专家郝晨栋:云上可观测能力——问题的发现与定位实践
- Keeping alive to realize MySQL automatic failover
猜你喜欢

QT handy notes (III) use qtcharts to draw a line chart in VS

苹果独占鳌头,三星大举复兴,国产手机在高端市场颗粒无收

B站这个视频我是跪着看完的

Development to testing: a six-year road to automation starting from 0

一种分布式深度学习编程新范式:Global Tensor

Docker configuring MySQL Cluster
![[MySQL database] a collection of basic MySQL operations - the basis of seeing (adding, deleting, modifying, and querying)](/img/a7/b3bb6f584dff0eb9b49e81e5b9dade.png)
[MySQL database] a collection of basic MySQL operations - the basis of seeing (adding, deleting, modifying, and querying)

Xiaobai makes a wave of deep copy and shallow copy

The diagram of user login verification process is well written!

Solve proxyerror: CONDA cannot proceed due to an error in your proxy configuration
随机推荐
Node memory overflow and V8 garbage collection mechanism
Modern medicine in the era of "Internet +"
高斯消元求解矩阵的逆(gauss)
[fluorescent character effect]
Development to testing: a six-year road to automation starting from 0
面试突击68:为什么 TCP 需要 3 次握手?
POJ 1012 Joseph
R语言ggpubr包ggsummarystats函数可视化分组箱图(自定义分组颜色)并在X轴标签下方添加分组对应的统计值(样本数N、中位数median、四分位数的间距iqr、统计值的色彩和分组图色匹配
Azkaban【基础知识 01】核心概念+特点+Web界面+架构+Job类型(一篇即可入门Azkaban工作流调度系统)
2021 windows penetration of "Cyberspace Security" B module of Shandong secondary vocational group (analysis)
Tableviewcell highly adaptive
在Blazor 中自定义权限验证
asp. Net using redis cache
Wechat applet development
解决npm -v突然失效 无反应
Interview shock 68: why does TCP need three handshakes?
Flutter Event 派发
antd TreeSelect获取父节点的值
Unstoppable, pure domestic PCs have been in place, and the monopoly of the U.S. software and hardware system has been officially broken
Logical architecture of MySQL