提交 53f26e58 作者: test

feat: 优化 buildGeoJSONSourceDataUrl 自动过滤空值参数

包含:空字符串、null、undefined 和 空对象
上级 7c0d0c99
import type mapboxgl from 'mapbox-gl' import type mapboxgl from 'mapbox-gl'
import qs from 'qs' import qs from 'qs'
import { isEmpty, isNull, isObject, isString, isUndefined, omitBy } from 'lodash-es'
import type { GeoJSONSourceDataUrlParams, MapboxConfig, MapboxInstance } from './index' import type { GeoJSONSourceDataUrlParams, MapboxConfig, MapboxInstance } from './index'
import { API_URL, API_URL_PREFIX } from '/@/utils/net' import { API_URL, API_URL_PREFIX } from '/@/utils/net'
import { isProdMode } from '@/utils/env' import { isProdMode } from '@/utils/env'
...@@ -87,6 +88,16 @@ export function buildGeoJSONSourceDataUrl(config: GeoJSONSourceDataUrlParams | s ...@@ -87,6 +88,16 @@ export function buildGeoJSONSourceDataUrl(config: GeoJSONSourceDataUrlParams | s
const url = typeof config === 'string' ? config : config.url const url = typeof config === 'string' ? config : config.url
const params = typeof config === 'string' ? defaultParams : { ...defaultParams, ...config.params } const params = typeof config === 'string' ? defaultParams : { ...defaultParams, ...config.params }
const query = qs.stringify(params, { addQueryPrefix: true }) const query = qs.stringify(
omitBy(
params,
(value) =>
isNull(value) ||
isUndefined(value) ||
(isString(value) && isEmpty(value)) ||
(isObject(value) && isEmpty(value)),
),
{ addQueryPrefix: true },
)
return `${baseURL}${url}${query}` return `${baseURL}${url}${query}`
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论