Class: FMMap

FMMap

FMMap 是加载、 显示、 操作地图的主类, 一个页面中至少需要包含一个FMMap对象, 属于fengmap.map.min.js

new fengmap.FMMap(options)

构造FMMap类

Name Type Description
options Object

FMMap可配置参数

Name Type Description
appName string

appName 必填

key string

key 必填

mapID string

mapID 必填

container Document

地图容器 必填

mapURL string

地图数据资源路径

mapURLAbsolute boolean

地图数据资源路径是否为绝对路径,默认为false,会自动拼接mapID目录层级.

preLoad boolean

是否预加载,默认值:true

themeURL string

地图主题资源路径

themeID string

地图默认主题ID,默认值:'2001'

themeExtension json

主题扩展

backgroundColor int

地图背景色,默认使用主题配置背景色

backgroundAlpha number

地图背景透明度,默认使用主题配置背景色

state json

地图状态码,json从 getState 方法中获取

center json

视图中心的地图坐标

Name Type Description
x number

x坐标

y number

y坐标

mapZoom number

缩放级别,默认值:20

zoomRange Array

比例尺缩放级别(可调范围为1-29),默认值:[16,23]

visibleLevels Array

显示楼层,默认值:[1]

level number

聚焦楼层, 默认值: 1,如果聚焦楼层不在显示楼层范围内,则修改显示楼层,修改规则:1. 显示单楼层时,则切换显示楼层为聚焦楼层 2. 显示楼层为多层时,则把聚焦楼层添加到显示楼层中

rotation number

旋转角度,默认值: 0

tiltAngle number

倾斜角度 默认值: 30

maxTiltAngle number

最大倾斜角度 默认值: 90

minTiltAngle number

最小倾斜角度 默认值: 30

floorSpace number

默认的层间距 默认值:50

viewMode fengmap.FMViewMode

视图模式 默认值:fengmap.FMViewMode.MODE_3D

logarithmicDepthBuffer boolean

是否开启对数深度缓存,用以解决较大场景下的闪面问题,但可能导致性能下降,默认值:false

renderOrder Array

[fengmap.FMType] 图层渲染顺序。默认图层顺序为:[EXTENT,EXTERNAL_MODEL,MODEL,DYNAMIC_MODEL_MARKER,EXTRUDE_MARKER,POLYGON_MARKER,HEAT_MAP_MARKER,LINE_MARKER,FACILITY,LABEL,IMAGE_MARKER,TEXT_MARKER,LOCATION_MARKER],DOM_MARKE始终在最上层不支持调整顺序。

collisionOrder Array

不同marker类避让排序分组, 默认值: [TEXT_MARKER, IMAGE_MARKER] 1. 内侧数组每组组成一套避让检查, 外侧数组进行分组; 2. 组与组之间避让关系互不影响; 不支持重复设置同一个marker类, 如果重复设置, 仅保留第一个, 后面设置的marker类将会被滤掉; 3. 仅支持传入TEXT_MARKER, IMAGE_MARKERmarker类, 如果传入其他类, 则无效果, 也无报错;

lock boolean

true 锁定交互(不可交互) false 不锁定交互(可以交互) 默认 false

highlightColor int

模型高亮的颜色,默认使用主题配置高亮颜色

highlightPicker Array

触发高亮事件,目前支持 ’click‘ 和 ’hover‘,默认['click']

nonFocusAlphaMode boolean

非聚焦楼层的透明模式,默认值:false

nonFocusAlpha number

非聚焦楼层的透明度,默认值:0.1

enabledPanRange boolean

启用/禁止将地图不能拖出屏幕范围,默认值:false

panRangeValue object

地图拖动范围参数,当enabledPanRange为true时如果不设置默认为地图内置范围,例子{center:{x: 13951602.736502802, y: 5440972.214299999},radius:5}

light fengmap.FMLight

灯光参数, fengmap.FMLight 的实例

hideList object

隐藏列表,该对象最多包含5个子对象,子对象的key可以是: fengmap.FMType.LABEL_LAYER, fengmap.FMType.FACILITY_LAYER, fengmap.FMType.MODEL_LAYER,fengmap.FMType.EXTERNAL_MODEL_LAYER, fengmap.FMType.EXTENT_LAYER, 例子:

{
   [fengmap.FMType.EXTENT_LAYER]: {},
   [fengmap.FMType.LABEL_LAYER]: {
     typeIDs: [...],
     FIDs: [...],
   }
},

如果只写了key,没有内容,那么就会隐藏该layer的所有内容; 如果有内容就只会对指定元素起作用.

Name Type Description
list object

隐藏列表的子对象

Name Type Description
typeIDs array

typeID 构成的数组

FIDs array

FID 构成的数组, 数组内容为字符串

ClassicMaterial

true将有贴图的三维模型自身颜色改为白色;false为使用模型自身颜色,默认为true

hdr fengmap.FMHDR

hdr对象

Members

readonlybound

Properties:
Name Type Description
bound fengmap.FMBound

边界

Methods

adjustRenderOrder(array)

调整渲染顺序,只调整参数中传入的图层顺序,将他们的渲染顺序按照参数传入顺序调换,不影响其他。DOM_MARKE始终在最上层不支持调整顺序。

Name Type Description
array Array

[fengmap.FMType]

autoRotate(){fengmap.FMAnimation}

地图自动旋转

Name Type Description
options.duration number

地图旋转一周所需时间 默认 5.0 秒

Returns:
Type Description
fengmap.FMAnimation 动画单元
Example
let animation = map.autoRotate();
 animation.finish(); // 强制完成
 animation.pause();  // 暂停
 animation.play();   // 播放
 animation.resume(); // 重置
 animation.stop();   // 停止

clearThemeExtension()

清空主题扩展

dispose()

废置地图对象

getBound(){Object}

获取地图界限

Deprecated
  • 3.1.5 版本及以后版本将不可用
    See:
    • bound
    Returns:
    Name Type Description
    bound Object 界限
    Name Type Description
    max Object 最大坐标
    Name Type Description
    x number 最大x坐标
    y number 最大y坐标
    min Object 最小坐标
    Name Type Description
    x number 最小x坐标
    y number 最小y坐标
    center Object 中心坐标
    Name Type Description
    x number 中心x坐标
    y number 中心y坐标
    size Object 尺寸
    Name Type Description
    x number x方向尺寸
    y number y方向尺寸

    getCenter(){Object}

    获取视图中心的地图坐标

    Returns:
    Type Description
    Object 地图坐标

    getCollisionOrder()

    获取部分覆盖物避让排序

    Returns:
    避让排序分组

    getFloor(level){fengmap.FMFloor}

    获取楼层

    Name Type Description
    level int

    楼层等级

    Returns:
    Type Description
    fengmap.FMFloor 楼层

    getFloorInfos(){Array}

    获取所有楼层的信息

    Returns:
    Type Description
    Array

    getFloorSpace(){number}

    获取楼层间距

    Returns:
    Type Description
    number 楼层间距

    getInteracations(){fengmap.FMInteracations}

    获取地图交互控制器

    Returns:
    Type Description
    fengmap.FMInteracations interacations 交互控制器
    Example
    let interacation = map.getInteracations();
     interacation.enableDrag = true;
     interacation.enableRotate= true;
     interacation.enableTilt = true;
     interacation.enableZoom = true;

    getLevel(){number}

    获取地图聚焦楼层等级

    Returns:
    Type Description
    number level 楼层等级

    getLevels(){Array}

    获取地图所有楼层等级

    Returns:
    Type Description
    Array 楼层等级

    getMarkerGroup(){Object}

    获取地图覆盖物组

    Returns:
    Type Description
    Object 地图覆盖物组

    getNodes(results){Array}

    获取地图节点

    Name Type Description
    results Array

    搜索查询的结果

    Returns:
    Type Description
    Array nodes 地图节点集合

    getRenderOrder(){Array}

    获取部分覆盖物的渲染顺序

    Returns:
    Type Description
    Array [fengmap.FMType] 渲染顺序

    getRotation(){int}

    获取地图旋转角度

    Returns:
    Type Description
    int 地图旋转角度

    getState(){Object}

    获取地图状态

    Returns:
    Type Description
    Object state 地图状态码

    getTilt(){int}

    获取地图倾斜角度

    Returns:
    Type Description
    int 地图倾斜角度

    getViewMode(){int}

    获取视图模式

    Returns:
    Type Description
    int 视图模式

    getVisibleLevels(){Array}

    获取显示楼层

    Returns:
    Type Description
    Array arr 显示楼层数组

    getZoom(){number}

    获取地图当前缩放级别

    Returns:
    Type Description
    number 缩放级别

    getZoomRange(){Array}

    获取地图缩放级别范围

    Returns:
    Type Description
    Array 缩放级别范围

    off(type, callback)

    地图事件注销

    Name Type Description
    type string

    事件类型

    callback function

    回调函数

    on(type, callback)

    地图事件注册

    Name Type Description
    type string

    事件类型

    callback function

    回调函数

    pickFilterFunction(){boolean}

    过滤设置可点击拾取函数。可通过过滤设置模型的可点击拾取和不可点击拾取。

    Returns:
    Type Description
    boolean 该方法返回true表示支持点击拾取,false表示不可点击拾取
    Example
    //过滤不允许点击的地图元素,设置为true为允许点击,设置为false为不允许点击
    map.pickFilterFunction = function (event) {
       return event.type !== fengmap.FMType.MODEL;
    }

    setBackgroundColor(color, alpha)

    设置地图背景颜色

    Name Type Description
    color int | string

    颜色值0xFF0000 | '#FF0000'

    alpha number

    透明度,取值范围:0.0 - 1.0

    setCenter(options)

    设置视图中心的地图坐标

    Name Type Description
    options Object

    地图移动参数

    Name Type Description
    x number

    地图x坐标

    y number

    地图y坐标

    animate boolean

    true:开启动画;false:不开启动画. 默认false

    duration number

    动画持续时间

    finish function

    动画完成回调函数

    setCollisionOrder(collisionOrder)

    设置部分覆盖物避让排序

    Name Type Description
    collisionOrder Array

    不同marker类避让排序分组, 默认值: [TEXT_MARKER, IMAGE_MARKER] 1. 内侧数组每组组成一套避让检查, 外侧数组进行分组; 2. 组与组之间避让关系互不影响; 不支持重复设置同一个marker类, 如果重复设置, 仅保留第一个, 后面设置的marker类将会被滤掉; 3. 仅支持传入TEXT_MARKER, IMAGE_MARKERmarker类, 如果传入其他类, 则无效果, 也无报错;

    setFitView(bound)

    设置合适的视图

    Name Type Description
    bound Object
    options.animate Boolean

    true 动画执行 false 不带动画执行 默认 true

    options.finish function

    动画执行完成回调函数

    setFloorSpace(value)

    楼层间距

    Name Type Description
    value number

    间距

    setHighlightColor(color)

    设置高亮颜色

    Name Type Description
    color

    setLabelField(labelField)

    设置label显示的字段

    Name Type Description
    labelField fengmap.FMLabelField

    label显示的字段,默认 fengmap.FMLabelField.NAME

    setLevel(options)

    设置地图聚焦楼层等级,如果聚焦楼层不在显示楼层范围内,则修改显示楼层,修改规则:1. 显示单楼层时,则切换显示楼层为聚焦楼层 2. 显示楼层为多层时,则把聚焦楼层添加到显示楼层中

    Name Type Description
    options Object

    设置聚焦楼层参数

    Name Type Description
    level int

    楼层等级

    animate boolean

    是否开启动画,true:开启;false:不开启.默认开启

    duration number

    动画持续时间

    callback function

    开启动画时,该函数返回当前执行的动画单元,动画单元可以对当前动画进行基本操作,详细 { @link fengmap.FMAnimation }

    finish function

    动画完成回调函数

    setRenderOrder(array)

    设置渲染顺序 默认顺序为:[EXTENT,EXTERNAL_MODEL,MODEL,DYNAMIC_MODEL_MARKER,EXTRUDE_MARKER,POLYGON_MARKER,HEAT_MAP_MARKER,LINE_MARKER,FACILITY,LABEL,IMAGE_MARKER,TEXT_MARKER,LOCATION_MARKER],DOM_MARKE始终在最上层不支持调整顺序。 (在深度检测开启后无效,如FMExtrudeMarker、FMLineMarker、FMDynamicModel。一般作用于覆盖物layer之间的显示顺序)

    Name Type Description
    array Array

    [fengmap.FMType]

    setRotation(options)

    旋转地图到指定角度

    Name Type Description
    options Object

    旋转参数

    Name Type Description
    rotation int

    旋转角度

    animate boolean

    是否开启动画,true:开启;false:不开启.默认不开启

    duration number

    动画持续时间

    finish function

    动画完成回调函数

    setState(state, options)

    设置地图状态

    Name Type Description
    state Object

    地图状态码

    options Object

    参数

    Name Type Description
    animate Boolean

    true 动画执行 false 不带动画执行 默认 true

    finish function

    动画执行完成回调函数

    setTheme(themeID)

    设置主题

    Name Type Description
    themeID string

    setThemeExtension(data)

    设置主题扩展

    Name Type Description
    data json

    主题数据

    setTilt(options)

    倾斜地图到指定角度

    Name Type Description
    options Object

    倾斜参数

    Name Type Description
    tilt int

    倾斜角度

    animate boolean

    是否开启动画,true:开启;false:不开启. true

    duration number

    动画持续时间

    finish function

    动画完成回调函数

    setViewMode(options)

    设置视图模式

    Name Type Description
    options Object
    Name Type Description
    mode int

    视图模式

    animate int

    是否开启动画,默认 true

    finish int

    完成回调

    Example
    setViewMode({mode:fengmap.FMViewMode.MODE_3D})

    setVisibleLevels(levels, callback)

    设置显示楼层

    Name Type Description
    levels Array

    楼层id数组

    callback function

    回调函数

    Example
    setVisibleLevels([1,2]);

    setZoom(options)

    缩放地图到指定级别

    Name Type Description
    options Object

    地图缩放参数

    Name Type Description
    zoom number

    地图缩放级别

    animate boolean

    是否开启动画,true:开启;false:不开启.默认不开启

    duration number

    动画持续时间

    finish function

    动画完成回调函数

    setZoomRange(range)

    设置地图缩放级别范围

    Name Type Description
    range Array

    缩放级别范围

    zoomIn()

    放大地图

    zoomOut()

    缩小地图

    Events

    click

    鼠标点击事件

    Example
    {
     type:'click', // 事件类型
     coords:{x:12619616.66,y:2621878.60}, // 点击到的地图坐标
     mouseEvent:{}, // MouseEvent 鼠标事件
     targets:[], // 所有点击到的地图节点(按距离排序)
    }

    externalFirstLoaded

    外部模型首次加载完成事件

    hover

    鼠标划过事件

    info

    地图运行信息

    Name Type Description
    event Object

    事件返回参数

    Name Type Description
    type string

    事件类型

    InfoMode

    信息内容,信息内容请参照 fengmap.FMInfoMode

    Example
    map.on("info", function(event){
     if (fengmap.FMInfoMode.THEME_DATA_ERROR === event.InfoMode) {
         console.log("主题数据加载错误");
     }
    });

    levelChanged

    聚焦楼层改变事件

    loaded

    地图加载完成事件

    move

    地图移动事件

    update

    地图更新事件

    viewChanged

    视图改变事件

    viewModeChanged

    视图模式改变事件

    visibleLevelsChanged

    地图可见楼层改变事件

    Deprecated
    • 3.1.0版本及以后版本将不可用
      See:
      • visibleLevelsLoaded

      visibleLevelsLoaded

      地图可见楼层加载完成事件

      zoom

      地图缩放事件