Skip to content

Poi 对象

createPoi

创建 poi 对象。

样例:

定义:

ts
interface NameCanvasInfo {
  canvasWidth?: number;
  canvasHeight?: number;
  font?: string;
  fillStyle?: CanvasFillStrokeStyles['fillStyle'];
  strokeStyle?: CanvasFillStrokeStyles['strokeStyle'];
  textAlign?: CanvasTextAlign;
  textBaseline?: CanvasTextBaseline;
  backgroundStyle?: CanvasFillStrokeStyles['fillStyle'];
  borderStyle?: CanvasFillStrokeStyles['strokeStyle'];
  borderWidth?: number;
}

interface PoiInfo extends BaseObject3DInfo {
  url: string;
  type?: PoiType;
  namePosition?: IVector3;
  nameScale?: IVector3;
  nameCanvasInfo?: NameCanvasInfo;
  iconScale?: IVector3;
  scaleFixed?: ScaleFixed;
}

function createPoi(poiInfo: PoiInfo): Poi;

用法:

js
ssp.createPoi(
  // poiInfo
  {
    id: 'xx',
    name: 'xx',
    nameCanvasInfo: {
      fillStyle: '#fff',
      strokeStyle: '#000',
    },
    type: '2.5d',
    url: 'http://xx.com/xx.png',
    level: {
      max: 1000,
      min: null,
    },
    position: { x: 0, y: 0, z: 0 },
    rotation: { x: 0, y: 0, z: 0 },
    scale: { x: 2, y: 2, z: 2 },
    onClick(e) {
      /**
       * 对象的独立事件触发后,默认不传播(类似 DOM 的事件冒泡)到全局事件,
       * 调用 eventPropagation 方法通知事件继续传播到全局。
       *
       * warn:
       *  在 **非箭头函数** 中参数 e 与 this 的指向都是当前对象对象,
       *  在 *箭头函数** 参数 e 依然是对象对象,但 this 指向会发生改变。
       */
      this.eventPropagation();

      console.log('对象自身的点击事件触发', this);
    },
    onDblClick: (e) => {
      /**
       * 这里模拟在 **箭头函数** 中
       */
      e.eventPropagation();

      console.log('对象自身的双击事件触发', e);
    },
    userData: {},
  }
);

// 3d poi
ssp.createPoi({
  id: 'xx',
  name: 'xx',
  nameCanvasInfo: {
    fillStyle: '#fff',
    strokeStyle: '#000',
  },
  type: '3d',
  url: '/xx.png',
});

提示

2d 不支持 rotationscale 属性。

2.5d 不支持 rotation 属性`。

参数:

poiInfo

  • 描述: 实例 Poi 对象所需信息
  • 类型: poiInfo
  • 必填:
poiInfo
属性描述类型必填默认值
id唯一IDstring | number
name名称string
type类型PoiType2.5d
namePosition展示名称的位置偏移(相对于poi)Position{ x: 0, y: 10, z: 0 }
nameScale展示名称的缩放比例Scale{ x: 16, y: 16, z: 1 }
nameCanvasInfo展示名称 canvas 配置NameCanvasInfo参考下方
iconScale图片的缩放比例Scale{ x: 16, y: 16, z: 1 }
scaleFixed相机超过设定距离时的固定缩放比例ScaleFixed
url图片资源路径string
level显示层级范围Level{ max: null, min: null }
visible是否可见booleantrue
position位置坐标Position{ x: 0, y: 0, z: 0 }
rotation旋转弧度Rotation{ x: 0, y: 0, z: 0 }
scale缩放比例Scale{ x: 1, y: 1, z: 1 }
userData用户数据any{}
onClick左键单击事件(object: Poi) => voidnull
onDblClick左键双击事件(object: Poi) => voidnull
onRightClick右键单击事件(object: Poi) => voidnull
onLoad创建完成事件(object: Poi) => voidnull
nameCanvasInfo
属性描述类型必填默认值
canvasWidth画布宽度number256
canvasHeight画布高度number256
font字体string32px Microsoft YaHei
fillStyle填充色CanvasFillStrokeStyles[fillStyle]#fff
strokeStyle描边色CanvasFillStrokeStyles[strokeStyle]#000
textAlign文本对齐CanvasTextAligncenter
textBaseline文本基线CanvasTextBaselinemiddle
backgroundStyle文本背景色CanvasFillStrokeStyles[fillStyle]
borderStyle文本边框色CanvasFillStrokeStyles[strokeStyle]
borderWidth文本边框宽度number3
scaleFixed
属性描述类型必填默认值
originScale小于 distance 时的 scalenumber
fixedScale大于 distance 时的固定 scalenumber
distance距离阈值number

提示

使用 scaleFixed 需要开启 scaleFixedEnabled 配置

getPoiById

通过 id 查找

定义:

ts
function getPoiById(id: PoiInfo['id']): Poi | null;

用法:

js
const poi = ssp.getPoiById('xxx');

弃用警告

请使用 getObjectById 替代

getPoiByName

通过 name 查找

定义:

ts
function getPoiByName(name: string): Poi[];

用法:

js
const poiList = ssp.getPoiByName('xxx');

弃用警告

请使用 getObjectByName 替代

getAllPoi

获取所有 Poi 对象

定义:

ts
function getAllPoi(): Poi[];

用法:

js
const allPoiList = ssp.getAllPoi();

getPoiByUserDataProperty

通过 userData 属性查找

定义:

ts
function getPoiByUserDataProperty(propNameOrFindFunc: string | UserDataPropertyFindFunc, value?: any): Poi[];

用法:

js
const poiList = ssp.getPoiByUserDataProperty('propKey''propVal')
// or
const poiList = ssp.getPoiByUserDataProperty(item => item['itemPropKey'] === 'itemPropVal')

参数:

propNameOrFindFunc

  • 描述: userData 内属性名 或 find 函数
  • 类型: string | function
  • 必填:

propValue

  • 描述: userData 内属性值。
  • 类型: any
  • 必填:

find 函数使用场景

js
poi.userData = {
  people: {
    name: 'xiaoming',
    age: 18,
  },
};
const poiList = ssp.getPoiByUserDataProperty((userData) => userData?.people?.name === 'xiaoming');

弃用警告

请使用 getObjectByUserDataProperty 替代

removePoiById

通过 id 移除

定义:

ts
function removePoiById(id: PoiInfo['id']): boolean;

用法:

js
ssp.removePoiById('xxx');

弃用警告

请使用 removeObjectById 替代

createPoiToGroup

创建 poi 到一个组内。

定义:

ts
function createPoiToGroup(groupInfo: GroupInfo, poiInfoList: PoiInfo[]): Group;

用法:

js
ssp.createPoiToGroup(
  // groupInfo
  {
    id: 'firstPoiGroup',
    name: 'name_firstPoiGroup',
    // ...
  },
  // poiInfoList
  [poiInfo1, poiInfo2, poiInfo3]
);

参数

groupInfo

  • 描述: 实例组对象所需信息
  • 类型: GroupInfo
  • 必填:

poiInfoList

  • 描述: poiInfo 集合
  • 类型: poiinfo[]
  • 必填:

createGroupForPoi

poi 提前创建一个空组。

使用场景

createPoiToGroup 不同,有些时候可能你还没有具体的 poiInfo 数据,但你想提前创建一个批量管理的空组,当有数据时再使用 addPoiForGroup 插入。

定义:

ts
function createGroupForPoi(groupInfo: GroupInfo): Group;

用法:

js
ssp.createGroupForPoi({
  id: 'firstPoiGroup',
  name: 'name_firstPoiGroup',
  // ...
});

参数

groupInfo

  • 描述: 实例组对象所需信息
  • 类型: GroupInfo
  • 必填:

弃用警告

请使用 createGroup 替代

addPoiForGroup

向一个已经存在的组内添加 poi 对象。

定义:

ts
function addPoiForGroup(groupId: GroupInfo['id'], poiInfoList: PoiInfo[]): Group | null;

用法:

js
ssp.addPoiForGroup(
  // groupId
  'firstPoiGroup',
  // poiInfoList
  [poiInfo4, poiInfo5]
);

参数

groupId

  • 描述:id
  • 类型: groupId[‘id’]
  • 必填:

poiInfoList

  • 描述: poiInfo 集合
  • 类型: poiinfo[]
  • 必填:

getPoiGroupById

通过 id 查找 poi

定义:

ts
function getPoiGroupById(id: GroupInfo['id']): Group | null;

用法:

js
const group = ssp.getPoiGroupById('firstPoiGroup');

弃用警告

请使用 getObjectById 替代

getPoiGroupByName

通过 name 查找 poi

定义:

ts
function getPoiGroupByName(name: string): Group[];

用法:

js
const groupList = ssp.getPoiGroupByName('name_firstPoiGroup');

弃用警告

请使用 getObjectByName 替代

getAllPoiGroup

获取所有 Poi 对象组

定义:

ts
function getAllPoiGroup(): Group[];

用法:

js
const allPoiGroupList = ssp.getAllPoiGroup();

弃用警告

请使用 getAllGroup 替代

removePoiGroupById

通过 id 移除 poi

定义:

ts
function removePoiGroupById(id: GroupInfo['id']): boolean;

用法:

js
const isRemoveSuccess = ssp.removePoiGroupById('firstPoiGroup');

弃用警告

请使用 removeObjectById 替代

clearPoi

清除当前场景内所有 poi 对象。

定义:

ts
function clearPoi(): void;

用法:

js
ssp.clearPoi();

showAllPoi

显示当前场景内所有 poi 对象。

定义:

ts
function showAllPoi(): void;

用法:

js
ssp.showAllPoi();

hideAllPoi

隐藏当前场景内所有 poi 对象。

定义:

ts
function hideAllPoi(): void;

用法:

js
ssp.hideAllPoi();

浙ICP备16043491号