{"id":52721,"date":"2024-12-03T12:51:18","date_gmt":"2024-12-03T04:51:18","guid":{"rendered":"https:\/\/fwq.ai\/blog\/52721\/"},"modified":"2024-12-03T12:51:18","modified_gmt":"2024-12-03T04:51:18","slug":"openlayers-6-%e4%b8%ad%e5%a6%82%e4%bd%95%e8%8e%b7%e5%8f%96-postcompose-%e4%ba%8b%e4%bb%b6%e7%9a%84-vectorcontext%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/52721\/","title":{"rendered":"OpenLayers 6 \u4e2d\u5982\u4f55\u83b7\u53d6 postcompose \u4e8b\u4ef6\u7684 vectorContext\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>OpenLayers 6 \u4e2d\u5982\u4f55\u83b7\u53d6 postcompose \u4e8b\u4ef6\u7684 vectorContext\uff1f<\/h1>\n<p><span style=\"font-size: 15px\">\u6709\u5fd7\u8005\uff0c\u4e8b\u7adf\u6210\uff01\u5982\u679c\u4f60\u5728\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\uff0c\u90a3\u4e48\u672c\u6587<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aOpenLayers 6 \u4e2d\u5982\u4f55\u83b7\u53d6 postcompose \u4e8b\u4ef6\u7684 vectorContext\uff1f\u300b<\/span>\uff0c\u5c31\u5f88\u9002\u5408\u4f60\uff01\u6587\u7ae0\u8bb2\u89e3\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u5305\u62ec<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\uff0c\u82e5\u662f\u4f60\u5bf9\u672c\u6587\u611f\u5174\u8da3\uff0c\u6216\u8005\u662f\u60f3\u641e\u61c2\u5176\u4e2d\u67d0\u4e2a\u77e5\u8bc6\u70b9\uff0c\u5c31\u8bf7\u4f60\u7ee7\u7eed\u5f80\u4e0b\u770b\u5427~<\/span><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241122\/173228367767408d1da7302.jpg\" class=\"aligncenter\" title=\"OpenLayers 6 \u4e2d\u5982\u4f55\u83b7\u53d6 postcompose \u4e8b\u4ef6\u7684 vectorContext\uff1f\u63d2\u56fe\" alt=\"OpenLayers 6 \u4e2d\u5982\u4f55\u83b7\u53d6 postcompose \u4e8b\u4ef6\u7684 vectorContext\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>openlayers\u4e2dpostcompose\u4e8b\u4ef6event.vectorcontext\u83b7\u53d6\u4e0d\u5230\u7684\u89e3\u51b3\u529e\u6cd5<\/strong><\/p>\n<p>\u5728openlayers 3\u4e2d\uff0c\u901a\u8fc7map\u7684postcompose\u4e8b\u4ef6\u83b7\u53d6event.vectorcontext\u53ef\u80fd\u5931\u8d25\u3002\u8fd9\u662f\u56e0\u4e3a\u5728openlayers 6\u4e2d\uff0c\u8be5\u4e8b\u4ef6\u88ab\u66ff\u6362\u4e3apostrender\u4e8b\u4ef6\uff0c\u5e76\u4e14getvectorcontext\u51fd\u6570\u5df2\u88ab\u5f15\u5165\u4ee5\u8bbf\u95ee\u5373\u65f6\u77e2\u91cf\u6e32\u67d3api\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6cd5\uff1a<\/strong><\/p>\n<p>\u8981\u5728openlayers 6\u4e2d\u83b7\u53d6vectorcontext\uff0c\u8bf7\u4f7f\u7528\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<ol>\n<li>\u5bfc\u5165getvectorcontext\u51fd\u6570\uff1a<\/li>\n<\/ol>\n<pre>import {getvectorcontext} from 'ol\/render';<\/pre>\n<ol>\n<li>\u4f7f\u7528postrender\u4e8b\u4ef6\u76d1\u542c\u56fe\u5c42\uff1a<\/li>\n<\/ol>\n<pre>layer.on('postrender', function(event) {\n  const vectorContext = getVectorContext(event);\n  \/\/ \u4f7f\u7528vectorContext\u8fdb\u884c\u77e2\u91cf\u7ed8\u5236\n});<\/pre>\n<p>\u901a\u8fc7\u4f7f\u7528getvectorcontext\u51fd\u6570\uff0c\u53ef\u4ee5\u5728postrender\u4e8b\u4ef6\u4e2d\u8bbf\u95eevectorcontext\uff0c\u4ece\u800c\u5b9e\u73b0\u6240\u9700\u7684\u77e2\u91cf\u7ed8\u5236\u64cd\u4f5c\uff0c\u4f8b\u5982\u70b9\u4f4d\u95ea\u70c1\u6548\u679c\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u300aOpenLayers 6 \u4e2d\u5982\u4f55\u83b7\u53d6 postcompose \u4e8b\u4ef6\u7684 vectorContext\uff1f\u300b\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u5173\u4e8e\u7684\u8d44\u6599\u8bf7\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff01<\/p>\n<dl>\n<dt><\/dt>\n<dd>\n   \u5c0f\u7a0b\u5e8f\u4e2d\u5982\u4f55\u5236\u4f5c\u52a8\u6001\u4e0d\u89c4\u5219SVG\u6c34\u5854\u8fdb\u5ea6\u6761\uff1f\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>OpenLayers 6 \u4e2d\u5982\u4f55\u83b7\u53d6 postcompose \u4e8b\u4ef6\u7684 vectorContext\uff1f \u6709\u5fd7\u8005\uff0c\u4e8b\u7adf\u6210\uff01\u5982\u679c\u4f60\u5728\u5b66\u4e60\u6587\u7ae0\uff0c\u90a3\u4e48\u672c\u6587\u300aOpenLayers 6 \u4e2d\u5982\u4f55\u83b7\u53d6 postcompose \u4e8b\u4ef6\u7684 vectorContext\uff1f\u300b\uff0c\u5c31\u5f88\u9002\u5408\u4f60\uff01\u6587\u7ae0\u8bb2\u89e3\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u5305\u62ec\uff0c\u82e5\u662f\u4f60\u5bf9\u672c\u6587\u611f\u5174\u8da3\uff0c\u6216\u8005\u662f\u60f3\u641e\u61c2\u5176\u4e2d\u67d0\u4e2a\u77e5\u8bc6\u70b9\uff0c\u5c31\u8bf7\u4f60\u7ee7\u7eed\u5f80\u4e0b\u770b\u5427~ openlayers\u4e2dpostcompose\u4e8b\u4ef6event.vectorcontext\u83b7\u53d6\u4e0d\u5230\u7684\u89e3\u51b3\u529e\u6cd5 \u5728openlayers 3\u4e2d\uff0c\u901a\u8fc7map\u7684postcompose\u4e8b\u4ef6\u83b7\u53d6event.vectorcontext\u53ef\u80fd\u5931\u8d25\u3002\u8fd9\u662f\u56e0\u4e3a\u5728openlayers 6\u4e2d\uff0c\u8be5\u4e8b\u4ef6\u88ab\u66ff\u6362\u4e3apostrender\u4e8b\u4ef6\uff0c\u5e76\u4e14getvectorcontext\u51fd\u6570\u5df2\u88ab\u5f15\u5165\u4ee5\u8bbf\u95ee\u5373\u65f6\u77e2\u91cf\u6e32\u67d3api\u3002 \u89e3\u51b3\u65b9\u6cd5\uff1a \u8981\u5728openlayers 6\u4e2d\u83b7\u53d6vectorcontext\uff0c\u8bf7\u4f7f\u7528\u4ee5\u4e0b\u6b65\u9aa4\uff1a \u5bfc\u5165getvectorcontext\u51fd\u6570\uff1a import {getvectorcontext} from &#8216;ol\/render&#8217;; \u4f7f\u7528postrender\u4e8b\u4ef6\u76d1\u542c\u56fe\u5c42\uff1a layer.on(&#8216;postrender&#8217;, function(event) { const vectorContext = getVectorContext(event); \/\/ \u4f7f\u7528vectorContext\u8fdb\u884c\u77e2\u91cf\u7ed8\u5236 }); \u901a\u8fc7\u4f7f\u7528getvectorcontext\u51fd\u6570\uff0c\u53ef\u4ee5\u5728postrender\u4e8b\u4ef6\u4e2d\u8bbf\u95eevectorcontext\uff0c\u4ece\u800c\u5b9e\u73b0\u6240\u9700\u7684\u77e2\u91cf\u7ed8\u5236\u64cd\u4f5c\uff0c\u4f8b\u5982\u70b9\u4f4d\u95ea\u70c1\u6548\u679c\u3002 \u4ee5\u4e0a\u5c31\u662f\u300aOpenLayers 6 \u4e2d\u5982\u4f55\u83b7\u53d6 postcompose \u4e8b\u4ef6\u7684 vectorContext\uff1f\u300b\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u5173\u4e8e\u7684\u8d44\u6599\u8bf7\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff01 \u5c0f\u7a0b\u5e8f\u4e2d\u5982\u4f55\u5236\u4f5c\u52a8\u6001\u4e0d\u89c4\u5219SVG\u6c34\u5854\u8fdb\u5ea6\u6761\uff1f<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-52721","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52721","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=52721"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52721\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=52721"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=52721"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=52721"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}