发布时间:2026/8/4 8:23:14
openlayers面要素渲染样式定制,包括纯色、图片、水平线、垂直线、正斜十字网格、正反斜线 实现的功能openlayers面要素渲染样式定制包括纯色、图片、水平线、垂直线、正斜十字网格、正反斜线。参考网络众多资源后进行了此次实现。附要素渲染属性选择的实现提供一个函数附到style对象上可忽略。上代码// config为面填充样式配置对象functiongetAConfigedPS(config){varpsnull;try{varstrokeOptions{color:(config.strokeColoropacityToHex(config.strokeOpacity||1))||#32C6D5,width:config.strokeWidth||2,opacity:config.strokeOpacity||1,// lineDash: [10, 5], // 虚线};if(config.strokeStyleconfig.strokeStyle!solid){if(config.dashArray){strokeOptions.lineDash(config.dashArray).split(,);}}varpolygonOptions{fill:newOLFill({color:(config.fillColoropacityToHex(config.fillOpacity||1))||#14e4bb,})};if(config.strokeEnabledconfig.strokeEnabled1){polygonOptions.strokenewOLStroke(strokeOptions);}console.log(config.fillStyle,config.fillStyle);//if(config.fillStyleconfig.fillStylesolid){//纯色填充console.log(polygonOptions,polygonOptions);psnewOLStyle(polygonOptions);}elseif(config.fillStyleconfig.fillStyleimage){//图片填充if(config.fillImageUrl){varcnvdocument.createElement(canvas);varctxcnv.getContext(2d);varimgnewImage();img.srcapiGetFileFullUrl(config.fillImageUrl);varfillnewOLFill({color:#ffff00});varimageFillOptions{fill:fill};if(config.strokeEnabledconfig.strokeEnabled1){imageFillOptions.strokenewOLStroke(strokeOptions);}psnewOLStyle(imageFillOptions);img.onloadfunction(){varpatternctx.createPattern(img,repeat);fill.setColor(pattern);};}else{psGetDefaultPointStyle();}}else{// 各类线条填充// 创建一个新的图案varcreateStripedPatternfunction(lineType){/* lineType: { label: 水平线, value: horizontal }, { label: 垂直线, value: vertical }, { label: 十字网格, value: cross }, { label: 正斜线, value: forward_diagonal }, { label: 反斜线, value: backward_diagonal }, { label: 斜十字网格, value: cross_diag }, */// 获取canvas元素和上下文varcanvasdocument.createElement(canvas);varctxcanvas.getContext(2d);ctx.fillStyle#FFFFFF66;ctx.fillRect(0,0,canvas.width,canvas.height);// 创建一个新的图案画布varpatternCanvasdocument.createElement(canvas);patternCanvas.width20;// 图案画布的宽度patternCanvas.height20;// 图案画布的高度varpCtxpatternCanvas.getContext(2d);pCtx.fillStyle#FFFFFF99;pCtx.fillRect(0,0,canvas.width,canvas.height);// 设置线条样式pCtx.strokeStyle#aaaaaa99;// 线条颜色pCtx.lineWidth1;// 线条宽度switch(lineType){casehorizontal:{// 水平线pCtx.beginPath();pCtx.moveTo(0,10);pCtx.lineTo(20,10);pCtx.stroke();break;}casevertical:{// 垂直线pCtx.beginPath();pCtx.moveTo(10,0);pCtx.lineTo(10,20);pCtx.stroke();break;}casecross:{// 十字网格pCtx.beginPath();pCtx.moveTo(10,2);pCtx.lineTo(10,18);pCtx.stroke();pCtx.beginPath();pCtx.moveTo(2,10);pCtx.lineTo(18,10);pCtx.stroke();break;}caseforward_diagonal:{// 正斜线pCtx.beginPath();pCtx.moveTo(0,20);pCtx.lineTo(20,0);pCtx.stroke();break;}casebackward_diagonal:{// 反斜线pCtx.beginPath();pCtx.moveTo(0,0);pCtx.lineTo(20,20);pCtx.stroke();break;}casecross_diag:{// 斜十字网格pCtx.beginPath();pCtx.moveTo(3,3);pCtx.lineTo(17,17);pCtx.stroke();pCtx.beginPath();pCtx.moveTo(3,17);pCtx.lineTo(17,3);pCtx.stroke();break;}default:{//斜方格pCtx.beginPath();pCtx.moveTo(0,0);pCtx.lineTo(20,20);pCtx.stroke();pCtx.beginPath();pCtx.moveTo(0,20);pCtx.lineTo(20,0);pCtx.stroke();break;}}// 使用createPattern创建重复的图案varpatternctx.createPattern(patternCanvas,repeat);console.log(patternpattern,pattern);returnpattern;}varlineFillOptions{// stroke: new OLStroke({// color: red,// lineDash: [5],// width: 2// }),fill:newOLFill({color:createStripedPattern(config.fillStyle)||#ffff00})};if(config.strokeEnabledconfig.strokeEnabled1){lineFillOptions.strokenewOLStroke(strokeOptions);}psnewOLStyle(lineFillOptions);}}catch(ex){console.log(GetConfigedPolylineSymbols ex 采用默认样式,ex);psGetDefaultPointStyle();}//只关注样式的请忽略这一段内容//适用的属性选择器config.categories示例/* [{ type: select, field: name, relation: 等于, value: 符号-鹊山水库 }, { type: logical, value: 或 }, { type: select, field: name, relation: 等于, value: 符号-鹊山水库 }] *///是否符合多条件function_filterFunction(attrs){//计算是否符合条件 符合返回truefunctionfilterVal(inValue,relation,compareValue){console.log(filterVal,inValue,relation,compareValue);varresultfalse;switch(relation){case等于:{result(inValuecompareValue);break;}case不等于:{result(inValue!compareValue);break;}case小于:{result(inValuecompareValue);break;}case小于等于:{result(inValuecompareValue);break;}case大于:{result(inValuecompareValue);break;}case大于等于:{result(inValuecompareValue);break;}case包含:{result((inValue).indexOf(compareValue)0);break;}case不包含:{result((inValue).indexOf(compareValue)0);break;}}returnresult;}if(config.categories(config.categories).length10){try{varcarrJSON.parse(config.categories);if(carrinstanceofArraycarr.length0){varcstr;for(vari0;icarr.length;i){varccarr[i];if(c.typec.typeselect){varvattrs[c.field];varrfilterVal(v,c.relation,c.value);cstr(r? 1 : 0 );}elseif(c.typec.typelogical){if(c.value且){cstr * ;}else{cstr ;}}}console.log(cstr,cstr);if(eval(cstr)1){returntrue;}else{returnfalse;}}else{returntrue;}}catch(ex){returntrue;}}else{returntrue;}}ps.filter_filterFunction;ps.xInfo{symbolConfig:config};returnps;}实现效果config对象示例{createBy:null,createTime:2026-08-03 16:04:59,updateBy:null,updateTime:2026-08-03 16:04:59,remark:null,id:b4a92e6b7d2a4583a0c63425de0edb40,layerId:f8666ad651e64f81be9b307ecc5e867b,categories:[{ \type\: \select\, \field\: \name\, \relation\: \等于\, \value\: \正斜线\ }],symbolName:正斜线,fillColor:#1890FF,fillOpacity:0,fillStyle:forward_diagonal,fillImageUrl:null,strokeEnabled:1,strokeColor:#1890FF,strokeWidth:2,strokeOpacity:0,strokeStyle:solid,dashArray:null,labelEnabled:1,highlightEnabled:1,highlightFillColor:#FF7A45,highlightFillOpacity:0.5,highlightStrokeColor:#FF4D4F,highlightStrokeWidth:3,extrusionEnabled:0,extrusionHeight:0,extrusionHeightField:null,extrusionTopColor:null,extrusionSideColor:null,minZoom:3,maxZoom:20,sort:1,status:0,zindex:5}

相关新闻

2026/8/4 8:18:14

电子设计竞赛备赛指南:从知识积累到项目交付的工程化实践

最近和几个在校学生聊起电子设计竞赛,他们问得最多的问题不是“该学什么”,而是“怎么才能把学的东西用起来”。这让我想起自己第一次参加电赛时的状态:手里拿着一堆开发板、传感器、模块,文档看了不少,代码也抄了不少…

2026/8/4 8:18:14

构网型VSG-PMSM永磁直驱风力发电系统解析

1. 构网型VSG-PMSM永磁直驱风力发电系统概述 永磁直驱风力发电系统作为当前风电领域的主流技术路线之一,其核心优势在于省去了传统双馈机组中的齿轮箱结构,通过PMSM(永磁同步电机)直接与风机叶轮连接。这种结构大幅减少了机械传动…

2026/8/4 8:18:14

Python基础语法全解析:从入门到精通

1. Python语言基础语法元素解析 作为一名使用Python十余年的开发者,我经常被问到同一个问题:"怎样才能真正掌握Python的基础语法?"今天我们就来彻底拆解Python最核心的语法元素,这些是每个Python程序员必须内化的基本功…

2026/8/4 9:23:18

技术视角下的微信视频号内容生态分析与合规建模实践

在实际内容创作和社交媒体运营中,我们经常需要分析特定平台上的热门内容创作者,以理解其成功模式、内容策略和受众吸引力。微信视频号作为微信生态内重要的短视频内容平台,涌现了大量风格各异、内容优质的创作者,他们往往在特定垂…

2026/8/4 9:23:18

运行时Hook技术原理与多语言攻防实践

1. 运行时Hook技术基础回顾在进入实战对抗环节前,有必要先梳理清楚Hook技术的基本原理。Hook的本质是通过修改程序执行流程,在目标函数执行前后插入自定义代码。不同语言实现方式各有特点:Java:主要通过Java Agent的Instrumentati…

2026/8/4 9:23:18

STM32与ESP8266串口通信实战:AT指令驱动设计与物联网应用

1. 项目概述:为什么STM32ESP8266是“学到就是赚到”?如果你手头有一块STM32开发板,又想让你的项目“连上网”,那么ESP8266几乎是你绕不开的一个选择。这不是什么高深莫测的玄学,而是无数嵌入式开发者用真金白银和时间验…

2026/8/4 9:23:17

FreeRTOS任务创建与删除:从概念到实战的嵌入式多任务开发指南

1. 项目概述:从“裸奔”到“多任务协作”的飞跃在嵌入式开发的早期阶段,或者说在资源极其受限的单片机项目中,我们常常采用一种被称为“前后台系统”或“超级循环”的架构。程序在一个无限循环里,依次检查各种标志位、处理传感器数…

2026/8/4 9:18:17

AI代码生成与逆向工程:如何用Codex类工具复活25年老游戏

1. 先搞清楚 Codex 能做什么,以及它和运行老游戏的关系 看到“Codex 成功运行 25 年老游戏”这个标题,很多人的第一反应可能是:Codex 是一个能直接运行老游戏的模拟器或平台。但如果你顺着“codex安装”、“codex使用教程”这些热词去搜索&am…

2026/8/3 21:14:30

如何用免费工具突破游戏窗口限制:SRWE完整使用指南

如何用免费工具突破游戏窗口限制:SRWE完整使用指南 【免费下载链接】SRWE Simple Runtime Window Editor 项目地址: https://gitcode.com/gh_mirrors/sr/SRWE 你是否遇到过这样的困扰?想为心爱的游戏截图,却发现游戏不支持自定义分辨率…

2026/8/4 0:02:01

dealsea是什么?跨境卖家必知的美国deal站入门指南

说实话,第一次听说美国这个老牌折扣网站的跨境卖家,十个有八个会问同一个问题:这个平台到底是干嘛的?我见过一个做家居出口的朋友,他在亚马逊上月销二十万美金,却从来没用过它。我给他看了首页——一屏一屏…

2026/8/3 22:40:58

实测才敢推 AI论文网站 2026最新测评与推荐

2026年真正好用的AI论文网站,核心看生成的论文质量、低AI味、格式正确、学术适配四大指标。综合实测,千笔AI、ThouPen、豆包、DeepSeek、Grammarly 是当前最值得推荐的梯队,覆盖从免费到付费、从中文到英文、从文科到理工的全场景需求。一、综…

2026/8/3 13:26:41

2026必备!AI论文网站测评:最新推荐与深度对比

2026年真正好用的AI论文网站,核心看生成的论文质量、低AI味、格式正确、学术适配四大指标。综合实测,千笔AI、ThouPen、豆包、DeepSeek、Grammarly 是当前最值得推荐的梯队,覆盖从免费到付费、从中文到英文、从文科到理工的全场景需求。 一、…

2026/8/3 16:43:13

摆脱论文困扰!盘点2026年全网爆红的的AI论文写作工具

一天写完毕业论文在2026年已不再是天方夜谭。2026年最炸裂、实测能大幅提速的AI论文写作工具,覆盖选题构思、文献整理、内容生成、格式排版等核心场景,真正帮你高效搞定论文难题。 一、全流程王者:一站式搞定论文全链路(一天定稿首…