# Class: Service

Service 服务类.

# Table of contents

# Constructors

# Properties

# Methods

# Constructors

# constructor

+ new Service(url: string, token?: string, req?: IRequest): Service

构造函数

# Parameters
Name Type Description
url string 服务地址
token? string 访问凭证
req? IRequest 请求的方法实现(默认内部实现)

Returns: Service

# Properties

# accessToken

accessToken: string= ""

访问凭证


# serverUrl

serverUrl: string= ""

服务器地址

# Methods

# addAccessKey

addAccessKey(key: string): Set<string>

增加访问key

# Parameters
Name Type Description
key string key值

Returns: Set<string>


# addSecretKey

addSecretKey(key: string): Set<string>

增加秘钥key

# Parameters
Name Type Description
key string key值

Returns: Set<string>


# baseUrl

baseUrl(): string

服务根地址

Returns: string


# blankTileUrl

blankTileUrl(): string

空白瓦片地址

Returns: string


# checkFileHasUpload

checkFileHasUpload(filemd5: string): Promise<any>

检查文件是否上传过

# Parameters
Name Type Description
filemd5 string 文件md5值

Returns: Promise<any>


# clearCache

clearCache(prefix?: string): Promise<{}>

清空服务器缓存数据

# Parameters
Name Type Default value Description
prefix string "" key前缀

Returns: Promise<{}>


# cmdClearMapCache

cmdClearMapCache(mapid: string, version: string): Promise<any>

清空地图的几何和瓦片缓存数据

# Parameters
Name Type Description
mapid string 地图ID
version string 版本号

Returns: Promise<any>


# cmdClearTileCache

cmdClearTileCache(mapid: string, version: string): Promise<any>

清空地图的瓦片缓存数据

# Parameters
Name Type Description
mapid string 地图ID
version string 版本号

Returns: Promise<any>


# cmdCreateEntitiesGeomData

cmdCreateEntitiesGeomData(param: ICreateEntitiesGeomData, cb?: (point: [number, number]) => undefined | null | [number, number]): Promise<any>

获取创建实体的几何数据

# Parameters
Name Type Description
param ICreateEntitiesGeomData 参数
cb? (point: [number, number]) => undefined | null | [number, number] 结果中每个点的处理回调。如果返回空的话,则用默认处理方法

Returns: Promise<any>


# cmdDeleteCache

cmdDeleteCache(param: IDeleteCache): Promise<any>

删除地图缓存

# Parameters
Name Type Description
param IDeleteCache 缓存接口

Returns: Promise<any>


# cmdDeleteMap

cmdDeleteMap(mapid: string, version: string, retainVersionMaxCount?: number): Promise<any>

删除地图

# Parameters
Name Type Description
mapid string 地图ID
version string 版本号,如删除所有版本,输入"*"号
retainVersionMaxCount? number 删除所有版本时,保留的最新的版本总数。如总共有10个版本,retainVersionMaxCount为3时,会保存最新的3个版本,其余的都会删除

Returns: Promise<any>


# cmdDeleteStyle

cmdDeleteStyle(param: IDeleteStyle): Promise<any>

删除地图样式

# Parameters
Name Type Description
param IDeleteStyle 样式接口

Returns: Promise<any>


# cmdGetAccessKey

cmdGetAccessKey(mapid: string, key: string): Promise<any>

获取地图的AccessKey,获取之前请确保已成功打开了地图

# Parameters
Name Type Description
mapid string 地图ID
key string secretKey秘钥和超级管理员superKey

Returns: Promise<any>


# cmdGetDrawBounds

cmdGetDrawBounds(mapid?: string, version?: string): Promise<null | GeoBounds>

获取图形中有数据的范围区域

# Parameters
Name Type Description
mapid? string 地图id
version? string 版本号

Returns: Promise<null | GeoBounds>


# cmdMapDiff

cmdMapDiff(param: IMapDiff): Promise<any>

比较地图不同

# Parameters
Name Type Description
param IMapDiff 组合参数

Returns: Promise<any>


# cmdRenameMap

cmdRenameMap(oldMapID: string, newMapID: string): Promise<any>

地图ID重命名

# Parameters
Name Type Description
oldMapID string 旧地图ID
newMapID string 新地图ID

Returns: Promise<any>


# cmdResetAccessKey

cmdResetAccessKey(mapid: string, key: string): Promise<any>

重置地图的AccessKey,获取之前请确保已成功打开了地图

# Parameters
Name Type Description
mapid string 地图ID
key string secretKey秘钥和超级管理员superKey

Returns: Promise<any>


# cmdRunStatus

cmdRunStatus(bDetail?: boolean): Promise<any>

获取当前运行状态

# Parameters
Name Type Description
bDetail? boolean 是否需要细节 (默认false)

Returns: Promise<any>


# cmdSetMapPassword

cmdSetMapPassword(mapid: string, key: string, newKey: string): Promise<any>

重置地图的密码,如果之前有密码,则是修改密码。如果之前没有密码,则是把此地图设置了密码保护。如果设置密码为空,则取消对此地图的密码保护。

# Parameters
Name Type Description
mapid string 地图ID
key string 旧的secretKey秘钥和超级管理员superKey
newKey string 新的secretKey秘钥

Returns: Promise<any>


# cmdSliceLayer

cmdSliceLayer(param: ISliceLayer): Promise<any>

对图层进行切片缓存

# Parameters
Name Type
param ISliceLayer

Returns: Promise<any>


# cmdSwitchLayers

cmdSwitchLayers(visibleLayers: string[]): Promise<any>

切换图层

# Parameters
Name Type Description
visibleLayers string[] 让可见的图层列表数组

Returns: Promise<any>


# cmdTransform

cmdTransform(srs: string, crs: string, points: GeoPoint | GeoPoint[], fourParameter?: string | string[]): Promise<any>

坐标转换

# Parameters
Name Type Description
srs string 源坐标系名称,如 EPSG:4326
crs string 目标坐标系名称,如 EPSG:3857
points GeoPoint | GeoPoint[] 要转换的坐标
fourParameter? string | string[] 四参数(x偏移,y偏移,缩放,旋转弧度),可选,对坐标最后进行修正

Returns: Promise<any>


# cmdUpdateStyle

cmdUpdateStyle(param: IUpdateStyle): Promise<any>

更新样式

# Parameters
Name Type Description
param IUpdateStyle 样式参数

Returns: Promise<any>

Example:

const res = svc.cmdUpdateStyle({
    name: "style1",
    layeron: [0,1,2,4,5,6,7,8,9],
    layeroff: "",
    clipbounds: "",
    backcolor: 0,
    lineweight:[1,1,0]
    expression: "gOutColorRed := gInColorGreen;gOutColorGreen := gInColorBlue;gOutColorBlue := gInColorRed;gOutColorAlpha := gInColorAlpha;"
});
1
2
3
4
5
6
7
8
9

# composeNewMap

composeNewMap(param: IComposeNewMap | IComposeNewMap[]): Promise<any>

组合成新地图

# Parameters
Name Type Description
param IComposeNewMap | IComposeNewMap[] 组合参数

Returns: Promise<any>


# conditionQueryFeature

conditionQueryFeature(param: IConditionQueryFeatures, cb?: (point: [number, number]) => undefined | null | [number, number]): Promise<any>

条件查询实体

# Parameters
Name Type Description
param IConditionQueryFeatures 参数
cb? (point: [number, number]) => undefined | null | [number, number] 结果中每个点的处理回调。如果返回空的话,则用默认处理方法

Returns: Promise<any>


# createStyle

createStyle(style: IMapStyleParam, mapid?: string, version?: string, isGeomLayer?: boolean): Promise<any>

获取样式图层名

# Parameters
Name Type Description
style IMapStyleParam 样式参数
mapid? string 地图ID
version? string 版本号,为空,则获取最新的;
isGeomLayer? boolean 几何渲染图层优先(默认true)

Returns: Promise<any>


# currentMapParam

currentMapParam(): null | IOpenMapResponse

当前地图参数

Returns: null | IOpenMapResponse


# deleteCustomData

deleteCustomData(key: string | string[], isPrefix?: boolean): Promise<any>

删除用户自定义数据

# Parameters
Name Type Description
key string | string[] 键名,如果是数组的话,可以查询
isPrefix? boolean 是否删除所有前缀为key的所有键值,默认false

Returns: Promise<any>


# execCommand

execCommand(cmdname: string, param?: Record<string, any>, mapid?: string, version?: string, useGet?: boolean): Promise<any>

执行命令

# Parameters
Name Type
cmdname string
param? Record<string, any>
mapid? string
version? string
useGet? boolean

Returns: Promise<any>


# exprQueryFeature

exprQueryFeature(param: IExprQueryFeatures, cb?: (point: [number, number]) => undefined | null | [number, number]): Promise<any>

表达式查询实体

# Parameters
Name Type Description
param IExprQueryFeatures 参数
cb? (point: [number, number]) => undefined | null | [number, number] 结果中每个点的处理回调。如果返回空的话,则用默认处理方法

Returns: Promise<any>


# fileMd5

fileMd5(file: File): Promise<any>

获取文件的Md5值

# Parameters
Name Type
file File

Returns: Promise<any>


# getConstData

getConstData(): Promise<any>

获取服务后台常量设置

Returns: Promise<any>


# getCurWorkspaceName

getCurWorkspaceName(): string

获取当前的工作区名称

Returns: string


# getCustomData

getCustomData(key: string | string[]): Promise<any>

获取用户自定义数据

# Parameters
Name Type Description
key string | string[] 键名,如果是数组的话,可以查询

Returns: Promise<any>


# getCustomDataKeysByPrefix

getCustomDataKeysByPrefix(prefix: string): Promise<any>

通过前缀获取用户自定义数据的键值

# Parameters
Name Type Description
prefix string 键名前缀

Returns: Promise<any>


# getFontsCapacity

getFontsCapacity(): Promise<{}>

得到所有矢量字体名称

Returns: Promise<{}>


# getMapLayers

getMapLayers(): IMapLayer[]

得到地图图层集合,调用前请确保地图已打开,否则会抛异常

Returns: IMapLayer[]


# getSliceCacheZoom

getSliceCacheZoom(param: ISliceCacheZoom): Promise<any>

获取已缓存的切片级别

# Parameters
Name Type Description
param ISliceCacheZoom 参数

Returns: Promise<any>


# getStyleLayerName

getStyleLayerName(mapid: string, version?: string, isGeomLayer?: boolean, name?: string): Promise<any>

获取样式图层名

# Parameters
Name Type Description
mapid string 地图ID
version? string 版本号,为空,则获取最新的;
isGeomLayer? boolean 几何渲染图层优先(默认true)
name? string 有名称时,根据名称来查找;

Returns: Promise<any>


# getWorkspaces

getWorkspaces(): Promise<any>

获取所有工作区(如果不是root权限的token获取非公开的工作区名称将返回空)

Returns: Promise<any>


# glyphsUrl

glyphsUrl(): string

字体地址

Returns: string


# listMaps

listMaps(mapid?: string | string[] | { curPage: number ; mapIds?: string[] ; pageCount: number }, version?: string): Promise<any>

获取所有地图信息

# Parameters
Name Type Default value Description
mapid string | string[] | { curPage: number ; mapIds?: string[] ; pageCount: number } "_" 地图ID,为空,则获取所有的;如果传入的是地图ID数组,则获取指定的地图ID数组的信息。如果不想一次性获取,可通过传入分页对象获取,如{curPage: 1, pageCount: 10}
version string "_" 版本号,为空,则获取最新的; * 则获取所有的版本

Returns: Promise<any>


# metadata

metadata(mapid?: string, version?: string): Promise<any>

获取地图元数据

# Parameters
Name Type Description
mapid? string 地图ID ,为空, 则为当前打开的图形
version? string 版本号,为空 则为当前打开的版本;

Returns: Promise<any>


# openMap

openMap(param: IOpenMapParam, isWaitFinish?: boolean): Promise<any>

打开图

# Parameters
Name Type Default value Description
param IOpenMapParam -
isWaitFinish boolean true 是否等待打开完成

Returns: Promise<any>


# pointQueryFeature

pointQueryFeature(param: IPointQueryFeatures, cb?: (point: [number, number]) => undefined | null | [number, number]): Promise<any>

点查询实体

# Parameters
Name Type Description
param IPointQueryFeatures 参数
cb? (point: [number, number]) => undefined | null | [number, number] 结果中每个点的处理回调。如果返回空的话,则用默认处理方法

Returns: Promise<any>


# processQueryResult

processQueryResult(param: any, cb?: (point: [number, number]) => undefined | null | [number, number]): any

处理查询结果

# Parameters
Name Type Description
param any 参数
cb? (point: [number, number]) => undefined | null | [number, number] 结果中每个点的处理回调。如果返回空的话,则用默认处理方法

Returns: any


# pwdToSecretKey

pwdToSecretKey(pwd: string): string

密码转换为秘钥

# Parameters
Name Type Description
pwd string 密码

Returns: string


# qrcodeUrl

qrcodeUrl(content: string, size?: number): string

二维码图片地址

# Parameters
Name Type Description
content string 生成二维码的内容
size? number 生成二维码的大小,默认256

Returns: string


# rasterBlankStyle

rasterBlankStyle(minzoom?: number, maxzoom?: number, prefix?: string): Style

空白栅格style

# Parameters
Name Type Description
minzoom? number 最小级别,缺省0
maxzoom? number 最大级别,缺省24
prefix? string 前缀,缺省rasterBlank

Returns: Style


# rasterLayerId

rasterLayerId(prefix?: string): string

获取栅格图层ID

# Parameters
Name Type
prefix? string

Returns: string


# rasterSourceId

rasterSourceId(prefix?: string): string

获取栅格源ID

# Parameters
Name Type
prefix? string

Returns: string


# rasterStyle

rasterStyle(tileUrl?: string, minzoom?: number, maxzoom?: number, prefix?: string): Style

栅格style

# Parameters
Name Type Description
tileUrl? string 栅格瓦片地址
minzoom? number 最小级别,缺省0
maxzoom? number 最大级别,缺省24
prefix? string 前缀,缺省raster

Returns: Style


# rasterTileUrl

rasterTileUrl(param?: ITileUrlParam): string

栅格瓦片地址

# Parameters
Name Type Default value
param ITileUrlParam {}

Returns: string


# rectQueryFeature

rectQueryFeature(param: IRectQueryFeatures, cb?: (point: [number, number]) => undefined | null | [number, number]): Promise<any>

矩形查询实体

# Parameters
Name Type Description
param IRectQueryFeatures 参数
cb? (point: [number, number]) => undefined | null | [number, number] 结果中每个点的处理回调。如果返回空的话,则用默认处理方法

Returns: Promise<any>


# removeAccessKey

removeAccessKey(key: string): void

移除访问key, 如果key为undefined时,则移除所有的

# Parameters
Name Type Description
key string key值

Returns: void


# removeSecretKey

removeSecretKey(key: string): undefined | Set<string>

移除秘钥key, 如果key为undefined时,则移除所有的

# Parameters
Name Type Description
key string key值

Returns: undefined | Set<string>


# saveCustomData

saveCustomData(key: string | { key: string ; ttl?: number ; value: any }[], value?: any, ttl?: number): Promise<any>

保存用户自定义数据

# Parameters
Name Type Description
key string | { key: string ; ttl?: number ; value: any }[] 键名(必须唯一,否则会覆盖之前的数据,同类型的key前缀尽量一样),如果是数组的话,可以批量
value? any 键值
ttl? number 有效时间,单位秒,默认长期有效

Returns: Promise<any>


# serviceUrl

serviceUrl(u: string): string

得到服务地址

# Parameters
Name Type Description
u string 要拼接的地址

Returns: string

string


# setCurrentMapParam

setCurrentMapParam(param: IOpenMapResponse): null | IOpenMapResponse

设置打开地图参数

# Parameters
Name Type
param IOpenMapResponse

Returns: null | IOpenMapResponse


# setSprite

setSprite(name: string): string

设置精灵图片名称

# Parameters
Name Type Description
name string 精灵名称

Returns: string


# spriteUrl

spriteUrl(name: string): string

精灵图片名称

# Parameters
Name Type Description
name string 精灵名称

Returns: string


# strMd5

strMd5(str: string): string

获取字符串的Md5值

# Parameters
Name Type
str string

Returns: string


# styleVersion

styleVersion(): number

得到style的版本号

Returns: number


# switchWorkspace

switchWorkspace(workspaceName: string): void

切换至工作区

# Parameters
Name Type Description
workspaceName string 工作区名称

Returns: void


# thumbnailUrl

thumbnailUrl(mapid?: string, version?: string, width?: number, height?: number): string

获取图的缩略图

# Parameters
Name Type
mapid? string
version? string
width? number
height? number

Returns: string


# toLayerIndex

toLayerIndex(layernames: string[], layers: any[]): number[]

把图层名称数组转成图层索引数组

# Parameters
Name Type Description
layernames string[] 图层名称数组
layers any[] 图层列表

Returns: number[]


# updateMap

updateMap(param: IUpdateMapParam, isWaitFinish?: boolean): Promise<any>

更新地图

# Parameters
Name Type Default value Description
param IUpdateMapParam -
isWaitFinish boolean true 是否等待打开完成

Returns: Promise<any>


# uploadMap

uploadMap(file: File): Promise<any>

上传地图

# Parameters
Name Type
file File

Returns: Promise<any>


# uploadUrl

uploadUrl(): string

返回上传文件的url地址

Returns: string


# vectorStyle

vectorStyle(tileUrl?: string | Record<string, any>, minzoom?: number, maxzoom?: number, prefix?: string, hoverColor?: string, hoverOpacity?: number, hoverLineWidth?: number, customColorCaseExpr?: any[], customOpacityCaseExpr?: any[], customLineWidthCaseExpr?: any[]): Style

矢量style

# Parameters
Name Type Description
tileUrl? string | Record<string, any> 矢量瓦片地址 或者为一个Object,为Object时,设置项为参数的每个项值,做为一个参数传入
minzoom? number 最小级别,缺省0
maxzoom? number 最大级别,缺省24
prefix? string 前缀,缺省vector
hoverColor? string 高亮时颜色,缺省rgba(0,0,255,255)
hoverOpacity? number 高亮时透明度,缺省0.5
hoverLineWidth? number 高亮时线宽,缺省3
customColorCaseExpr? any[] 自定义颜色表达式,必须为数组[条件1,值,条件2,值,...],如[['==', ['feature-state', 'status'], 'alarm'], '#ff0000', ['==', ['feature-state', 'status'], 'normal'], '#00ff00'],缺省默认
customOpacityCaseExpr? any[] 自定义透明度表达式,必须为数组,缺省默认
customLineWidthCaseExpr? any[] 自定义线宽表达式,必须为数组,缺省默认

Returns: Style


# vectorTileUrl

vectorTileUrl(param?: ITileUrlParam): string

矢量瓦片地址

# Parameters
Name Type Default value
param ITileUrlParam {}

Returns: string


# waitMapOpenFinish

waitMapOpenFinish(mapid: string, version: string, tryTime?: number, maxTryTimes?: number): Promise<any>

等待地图打开完成

# Parameters
Name Type Default value Description
mapid string - 地图ID
version string - 地图版本号
tryTime number 5 每次尝试时间间隔(秒)
maxTryTimes number 120 最大尝试次数

Returns: Promise<any>


# webMapUrl

webMapUrl(tileProvider: { fourParameterAfter?: string ; fourParameterBefore?: string ; mapbounds?: string ; srs?: string ; tileCrs?: "gcj02" | "wgs84" ; tileFlipY?: boolean ; tileMaxZoom?: number ; tileRetina?: number ; tileShards?: string ; tileSize?: number ; tileToken?: string | string[] ; tileUrl: string | string[] }): string

获取服务器地图服务地址

# Parameters
Name Type
tileProvider object
tileProvider.fourParameterAfter? string
tileProvider.fourParameterBefore? string
tileProvider.mapbounds? string
tileProvider.srs? string
tileProvider.tileCrs? "gcj02" | "wgs84"
tileProvider.tileFlipY? boolean
tileProvider.tileMaxZoom? number
tileProvider.tileRetina? number
tileProvider.tileShards? string
tileProvider.tileSize? number
tileProvider.tileToken? string | string[]
tileProvider.tileUrl string | string[]

Returns: string


# wmsTileUrl

wmsTileUrl(param: IWmsTileUrl): string

# Parameters
Name Type
param IWmsTileUrl

Returns: string


# workspaceCreate

workspaceCreate(workspace: IWorkspace): Promise<any>

创建工作区(默认需要root权限)

# Parameters
Name Type Description
workspace IWorkspace 工作区设置

Returns: Promise<any>


# workspaceDelete

workspaceDelete(name: string): Promise<any>

删除工作区(会同时删除工作区下面的所有目录文件)(默认需要root权限)

# Parameters
Name Type Description
name string 要删除的工作区名称

Returns: Promise<any>


# workspaceModify

workspaceModify(workspace: IWorkspace): Promise<any>

修改工作区(默认需要root权限)

# Parameters
Name Type Description
workspace IWorkspace 工作区

Returns: Promise<any>

vjmap / Exports / SkyLayer