You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
/**
* H5 静态资源转绝对 URL( 兼容 manifest publicPath: /h5walksz/)
* 注意:天地图 T.Icon 不支持 data:/blob:,标注图必须使用 http(s) 地址
*/
export function resolveH5AssetUrl ( path ) {
if ( ! path || typeof path !== 'string' ) return path
// data/blob 不能作为网络图片加载,交给 normalizeMarkerIconUrl 处理
if ( /^(https?:)/i . test ( path ) ) return path
let assetPath = path
if ( ! assetPath . startsWith ( '/' ) ) {
assetPath = '/' + assetPath
}
if ( typeof window === 'undefined' ) {
const base = ( typeof process !== 'undefined' && process . env && process . env . BASE _URL ) || '/h5walksz/'
return base . replace ( /\/$/ , '' ) + assetPath
}
let basePath = ''
if ( typeof process !== 'undefined' && process . env && process . env . BASE _URL ) {
basePath = process . env . BASE _URL . replace ( /\/$/ , '' )
}
if ( ! basePath ) {
const match = window . location . pathname . match ( /^\/(h5walksz)(?:\/|$)/ )
basePath = match ? '/' + match [ 1 ] : ''
}
return window . location . origin + basePath + assetPath
}
/** 默认地图标注图(固定 http 路径,避免 webpack 内联为 data:) */
export function getDefaultMarkerUrl ( ) {
return resolveH5AssetUrl ( '/static/home-marker.png' )
}
/**
* 标注图标 URL 规范化(天地图仅支持 http/https)
*/
export function normalizeMarkerIconUrl ( url ) {
if ( ! url || /^data:|^blob:/i . test ( url ) ) {
return getDefaultMarkerUrl ( )
}
if ( /^https?:\/\//i . test ( url ) ) {
return url
}
return resolveH5AssetUrl ( url )
}