当前位置:网站首页>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 !
边栏推荐
- 在.NET 6.0中配置WebHostBuilder
- 分布式网络通信框架:本地服务怎么发布成RPC服务
- The problem of accessing certsrv after configuring ADCs
- Why does new public chain Aptos meet market expectations?
- JS判断数据类型 Object.prototype.toString.call和typeof
- Sublime install plug-ins
- Applet record
- 编写一个在bash / shell 和 PowerShell中均可运行的脚本
- [MySQL database] a collection of basic MySQL operations - the basis of seeing (adding, deleting, modifying, and querying)
- R language ggplot2 visualization: align the legend title to the middle of the legend box in ggplot2 (default left alignment, align legend title to middle of legend)
猜你喜欢
Qt随手笔记(三)在vs中使用QtCharts画折线图
I finished watching this video on my knees at station B
Fuzzy PID control of motor speed
2021年山东省中职组“网络空间安全”B模块windows渗透(解析)
[MySQL database] a collection of basic MySQL operations - the basis of seeing (adding, deleting, modifying, and querying)
论文笔记(SESSION-BASED RECOMMENDATIONS WITHRECURRENT NEURAL NETWORKS)
在Blazor 中自定义权限验证
Solve NPM -v sudden failure and no response
2019 ICPC Asia Yinchuan regional (water problem solution)
Applet record
随机推荐
(二)面扫描仪与机械臂的手眼标定(眼在手外:九点标定)
js 表格自动循环滚动,鼠标移入暂停
MQTT X CLI 正式发布:强大易用的 MQTT 5.0 命令行工具
开发转测试:从0开始的6年自动化之路...
学习笔记之常用数组api 改变原数组和不改变原数组的有哪些?
WARNING: [pool www] server reached pm. max_ children setting (5), consider raising it
Fiddler packet capturing tool for mobile packet capturing
CSV data file settings of JMeter configuration components
[datawhale] [machine learning] Diabetes genetic risk detection challenge
EOJ 2020 January race E-number transformation
面试突击68:为什么 TCP 需要 3 次握手?
QT随手笔记(六)——更新界面、截图、文件对话框
Use of tabbarcontroller
解决ProxyError: Conda cannot proceed due to an error in your proxy configuration.
万字详解“用知识图谱驱动企业业绩增长”
m进制数str转n进制数
PHP one-time request lifecycle
Sublime install plug-ins
服务器、客户端双认证(2)
Node memory overflow and V8 garbage collection mechanism