| 1965 | } |
| 1966 | |
| 1967 | function getL7Layer(l, sourceInfo) { |
| 1968 | const typeRule = { |
| 1969 | [MSLayerType.line]: 'LineLayer', |
| 1970 | [MSLayerType.point]: 'PointLayer', |
| 1971 | [MSLayerType.polygon]: 'PolygonLayer', |
| 1972 | [MSLayerType.heatmap]: 'HeatmapLayer' |
| 1973 | }; |
| 1974 | const source = l.source || {}; |
| 1975 | // 解决L7结构化数据监听click事件会返回多个features问题 |
| 1976 | let promoteId = sourceInfo.promoteId; |
| 1977 | if (!promoteId) { |
| 1978 | promoteId = sourceInfo.tiles && sourceInfo.tiles[0].includes('/structureddata/') ? 'smpid' : undefined; |
| 1979 | } |
| 1980 | const layer = new L7Layer({ |
| 1981 | type: typeRule[l.type], |
| 1982 | options: { |
| 1983 | ...l.options, |
| 1984 | layerID: (l.options || {}).name, |
| 1985 | featureId: promoteId |
| 1986 | } |
| 1987 | }); |
| 1988 | // getL7Layer返回原生antv l7 layer的实例 |
| 1989 | const l7Layer = layer.getL7Layer(); |
| 1990 | // 调用原生antv l7 layer的方法,构建图层 |
| 1991 | const sourceOptions = {}; |
| 1992 | const shape = l.shape || {}; |
| 1993 | if (source.parser) { |
| 1994 | sourceOptions.parser = l.source.parser; |
| 1995 | } |
| 1996 | if (source.transforms) { |
| 1997 | sourceOptions.transforms = l.source.transforms; |
| 1998 | } |
| 1999 | l7Layer.source(source.data, sourceOptions); |
| 2000 | |
| 2001 | shape.field ? l7Layer.shape(shape.field, shape.values) : l7Layer.shape(shape.values); |
| 2002 | if (l.texture) { |
| 2003 | l7Layer.texture(l.texture.values); |
| 2004 | } |
| 2005 | if (l.size) { |
| 2006 | l.size.field ? l7Layer.size(l.size.field, l.size.values) : l7Layer.size(l.size.values); |
| 2007 | } |
| 2008 | if (l.color) { |
| 2009 | l.color.field ? l7Layer.color(l.color.field, l.color.values) : l7Layer.color(l.color.values); |
| 2010 | } |
| 2011 | if (l.style) { |
| 2012 | l7Layer.style(l.style); |
| 2013 | } |
| 2014 | if (l.animate) { |
| 2015 | l7Layer.animate(l.animate); |
| 2016 | } |
| 2017 | if (l.filter) { |
| 2018 | const refresh = debounce(function () { |
| 2019 | layer.reRender(); |
| 2020 | }, 500); |
| 2021 | l7Layer.filter(l.filter.field, (...args) => { |
| 2022 | const result = l.filter.values(...args); |
| 2023 | if (result) { |
| 2024 | refresh(); |