gpt4 book ai didi

javascript - 如何从 HERE map 中删除现有标记和信息气泡

转载 作者:行者123 更新时间:2023-11-28 11:30:23 27 4
gpt4 key购买 nike

我的 map 使用 HERE map API。每当我单击 map 时,我都可以添加标记和信息气泡。但是,我只想要 map 上最新的标记和信息气泡,并删除所有其他标记。下面是我的代码,在我多次单击 map 后,其中包含所有标记和信息气泡。

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, width=device-width" />
<link rel="stylesheet" type="text/css" href="https://js.api.here.com/v3/3.0/mapsjs-ui.css?dp-version=1533195059" />
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-core.js"></script>
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-service.js"></script>
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-ui.js"></script>
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-mapevents.js"></script>

</head>
<body>
<div id="map" style="height:550px;width:720px;"></div>

<script>
//Step 1: initialize communication with the platform
var platform = new H.service.Platform({
app_id: 'devportal-demo-20180625',
app_code: '9v2BkviRwi9Ot26kp2IysQ',
useHTTPS: true
});
var pixelRatio = window.devicePixelRatio || 1;
var defaultLayers = platform.createDefaultLayers({
tileSize: pixelRatio === 1 ? 256 : 512,
ppi: pixelRatio === 1 ? undefined : 320
});

//Step 2: initialize a map - not specificing a location will give a whole world view.
var map = new H.Map(document.getElementById('map'),
defaultLayers.normal.map, {pixelRatio: pixelRatio});

//Step 3: make the map interactive
// MapEvents enables the event system
// Behavior implements default interactions for pan/zoom (also on mobile touch environments)
var behavior = new H.mapevents.Behavior(new H.mapevents.MapEvents(map));

// Create the default UI components
var ui = H.ui.UI.createDefault(map, defaultLayers);




function setUpClickListener(map) {
map.addEventListener('tap', function (evt) {
var coord = map.screenToGeo(evt.currentPointer.viewportX,
evt.currentPointer.viewportY);
addMarker(coord);
});
}

function addMarker(coordinates){
var marker = new H.map.Marker({lat:coordinates.lat, lng: coordinates.lng});
map.addObject(marker);

var bubble = new H.ui.InfoBubble({lat:coordinates.lat, lng: coordinates.lng}, {
content: '<b>Hello World!</b>'
});
// show info bubble
ui.addBubble(bubble);
}

setUpClickListener(map);
</script>

</body>
</html>

最佳答案

map.removeObjects(map.getObjects ())

关于javascript - 如何从 HERE map 中删除现有标记和信息气泡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51748185/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com