(layerInfo, features, addToMap = true)
| 2334 | } |
| 2335 | |
| 2336 | _createHeatLayer(layerInfo, features, addToMap = true) { |
| 2337 | const { minzoom, maxzoom } = layerInfo; |
| 2338 | const style = layerInfo.themeSetting; |
| 2339 | const layerOption = { |
| 2340 | gradient: style.colors.slice(), |
| 2341 | radius: parseInt(style.radius) |
| 2342 | }; |
| 2343 | // 自定义颜色 |
| 2344 | const customSettings = style.customSettings; |
| 2345 | for (const i in customSettings) { |
| 2346 | layerOption.gradient[i] = customSettings[i]; |
| 2347 | } |
| 2348 | const color = ['interpolate', ['linear'], ['heatmap-density']]; |
| 2349 | const step = [0.1, 0.3, 0.5, 0.7, 1]; |
| 2350 | layerOption.gradient.forEach((item, index) => { |
| 2351 | color.push(step[index]); |
| 2352 | if (index === 0) { |
| 2353 | item = Util.hexToRgba(item, 0); |
| 2354 | } |
| 2355 | if (index === 1) { |
| 2356 | item = Util.hexToRgba(item, 0.5); |
| 2357 | } |
| 2358 | color.push(item); |
| 2359 | }); |
| 2360 | // 图例相关 |
| 2361 | this._initLegendConfigInfo(layerInfo, color); |
| 2362 | |
| 2363 | const paint = { |
| 2364 | 'heatmap-color': color, |
| 2365 | 'heatmap-radius': style.radius * 3, |
| 2366 | 'heatmap-intensity': 2.8 |
| 2367 | }; |
| 2368 | |
| 2369 | if (style.weight && features.length >= 4) { |
| 2370 | const weight = []; |
| 2371 | features.forEach((item) => { |
| 2372 | item.properties[style.weight] = +item.properties[style.weight]; |
| 2373 | weight.push(item.properties[style.weight]); |
| 2374 | }); |
| 2375 | const max = ArrayStatistic.getMax(weight); |
| 2376 | const min = ArrayStatistic.getMin(weight); |
| 2377 | paint['heatmap-weight'] = ['interpolate', ['linear'], ['get', style.weight], min, 0, max, 1]; |
| 2378 | } |
| 2379 | this._addLayer({ |
| 2380 | id: layerInfo.layerID, |
| 2381 | type: 'heatmap', |
| 2382 | source: { |
| 2383 | type: 'geojson', |
| 2384 | data: { |
| 2385 | type: 'FeatureCollection', |
| 2386 | features: features |
| 2387 | } |
| 2388 | }, |
| 2389 | paint: paint, |
| 2390 | layout: { |
| 2391 | visibility: layerInfo.visible |
| 2392 | }, |
| 2393 | minzoom: minzoom || 0, |
no test coverage detected