您可以在地图的指定位置添加CustomPoi以标识位置、商家、建筑等,并可以通过信息窗口展示详细信息。CustomPoi支持文字标注碰撞和方向选择避让:
调用HWMapJsSDK.HWCustomPoi(customPoiOptions)添加CustomPoi。
function initMap() {
var mapOptions = {};
mapOptions.center = {lng: 2.3506770476074217, lat: 48.93245374505838};
mapOptions.zoom = 12;
mapOptions.language = 'en';
mapOptions.sourceType = 'vector';
mapOptions.navigationControl = true;
mapOptions.locationControl = true;
mapOptions.rotateControl = true;
mapOptions.zoomControl = true;
mapOptions.zoomSlider = true;
mapOptions.scaleControl = true;
mapOptions.copyrightControl = true;
map = new HWMapJsSDK.HWMap(document.getElementById('map'), mapOptions);
// 添加CustomPoi(point 1)
customPoi1 = new HWMapJsSDK.HWCustomPoi({
map,
icon: {
anchor: 'center',
scale: 1,
opacity: 1,
},
label: {
color: '#333',
fontSize: '36px',
text: 'point 1',
offsetX: 0,
offsetY: 0,
},
position: {lat: 49, lng: 2.35},
zIndex: 1,
collisionEnabled: true,
variableLabelAnchor: ['top','bottom','left', 'right'],
});
// 添加CustomPoi(point 2)
customPoi2 = new HWMapJsSDK.HWCustomPoi({
map,
icon: {
anchor: 'bottom',
scale: 1,
opacity: 1,
},
label: {
color: '#333',
fontSize: '36px',
text: 'point 2',
offsetX: 0,
offsetY: 0,
},
position: {lat: 48.5, lng: 2.35},
zIndex: 1,
collisionEnabled: true,
variableLabelAnchor: ['top','bottom','left', 'right'],
});
} CustomPoi文字标注碰撞效果:

调用HWCustomPoi的addListener(type, callback)、removeListener(type, callback)方法,添加/删除点击事件。
function handleListener(e) {
console.log(e);
}
// 添加点击事件
customPoi.addListener('click', handleListener);
// 删除点击事件
customPoi.removeListener('click', handleListener);