单张样式功能取2个参数(Leaflet styling function to take 2 parameters)

编程入门 行业动态 更新时间:2024-10-17 00:21:04
单张样式功能取2个参数(Leaflet styling function to take 2 parameters)

我实际上正在制作一张传单地图,它根据区域名称的长度来显示不同颜色的区域。 我有功能样式,返回一个特定的样式,并采用功能(从json地图)作为输入。

var geojson = L.geoJson(data,{style: styling}).addTo(map); function styling(feature) { return { fillColor: getColor(feature.properties.NAME.length), weight: 2, opacity: 1, color: 'white', dashArray: '3', fillOpacity: 0.7 }; }

我实际上正在寻找的是将另一个参数传递给函数样式,但我不知道如何实现这一点。 因为自动检索第一个参数,我应该做样式(第二参数)吗?

I'm actually working on a leaflet map that dispays regions in different colors accordings to the lenght of the name of the region. I have the function stylings that returns a specific styling and that takes feature (from json map) as input.

var geojson = L.geoJson(data,{style: styling}).addTo(map); function styling(feature) { return { fillColor: getColor(feature.properties.NAME.length), weight: 2, opacity: 1, color: 'white', dashArray: '3', fillOpacity: 0.7 }; }

What I'm actually looking for is passing another parameter to the function styling, but I don't know how to achieve this. shall I do something like styling (,2nd Parameter) since the first parameter is retrieved automatically ?

最满意答案

只需使用一个用第二个参数调用“样式”功能的函数。

var geojson = L.geoJson(data,{style: function(feature){styling(feature, "hello")}}).addTo(map);

示例: https : //jsfiddle.net/70jryouy/1/

Just use a function that recall the "styling" function with the second parameter.

var geojson = L.geoJson(data,{style: function(feature){styling(feature, "hello")}}).addTo(map);

Example: https://jsfiddle.net/70jryouy/1/

更多推荐

本文发布于:2023-08-06 14:26:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1450298.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:样式   参数   功能   Leaflet   function

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!