我实际上正在制作一张传单地图,它根据区域名称的长度来显示不同颜色的区域。 我有功能样式,返回一个特定的样式,并采用功能(从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/
更多推荐
发布评论