腾讯地图 qq.map 设置鼠标样式

本文介绍如何使用腾讯地图API自定义地图上的鼠标样式,通过设置draggableCursor和draggingCursor属性,实现鼠标指针在地图上的不同状态显示,如pointer和crosshair样式。
部署运行你感兴趣的模型镜像

腾讯地图设施鼠标样式我暂时没有找到直接的方法,但是它有一个属性可以控制draggableCursor,draggingCursor。直接修改地图实例的属性,就可以实现修改样式。

官方参考文章:http://open.map.qq.com/javascript_v2/doc/mapoptions.html

我的代码

this.map = new qq.maps.Map(this.$refs.thismap, {
   // 地图的中心地理坐标
   center: new qq.maps.LatLng(36.668419, 117.027225),
   // 地图缩放级别
   zoom: 16,
   // 地图的默认鼠标指针样式 pointer crosshair
   draggableCursor: 'pointer',
   // 拖动地图时的鼠标指针样式
   draggingCursor: 'pointer',
   // 该key绑定的style1对应于经典地图样式,若未绑定将弹出无权限提示窗
   mapStyleId: 'style1'
 });
// 直接进行修改
this.map.draggableCursor = 'crosshair';

您可能感兴趣的与本文相关的镜像

GPT-oss:20b

GPT-oss:20b

图文对话
Gpt-oss

GPT OSS 是OpenAI 推出的重量级开放模型,面向强推理、智能体任务以及多样化开发场景

init() { //步骤:定义map变量 调用 qq.maps.Map() 构造函数 获取地图显示容器 //设置地图中心点 var that = this; that.keyword = "" var myLatlng = new qq.maps.LatLng(that.center.lat, that.center.lng); //定义工厂模式函数 var myOptions = { zoom: that.zoom, //设置地图缩放级别 center: myLatlng, //设置中心点样式 mapTypeId: qq.maps.MapTypeId.ROADMAP, //设置地图样式详情参见MapType disableDefaultUI: true } //获取dom元素添加地图信息 map = new qq.maps.Map(document.getElementById("container"), myOptions); that.getLocation() }, async getLocation() { const responseAll = await listUser({ sex: "1" }) this.peopleList = responseAll.rows this.getLabel() this.getMaker() }, getLabel() { var peopleList = this.peopleList if (peopleList.length != 0) { const positionMap = new Map(); for (let i = 0; i < peopleList.length; i++) { if (peopleList[i].lon && peopleList[i].lat) { const key = `${peopleList[i].lat},${peopleList[i].lon}`; if (!positionMap.has(key)) positionMap.set(key, []); positionMap.get(key).push(peopleList[i]); } } positionMap.forEach((people, key) => { const [lat, lon] = key.split(',').map(Number); const position = new qq.maps.LatLng(lat, lon); var labelName = people.map(p => p.userName).join(',') const x = (this.getTextByteLen(labelName)) * 10 * 0.25 + 5; const label = new qq.maps.Label({ offset: new qq.maps.Size(-x, -55), position: position, map: map, content: labelName, style: { color: "#ffffff", fontSize: "14px", backgroundColor: "rgba(64, 64, 65, 0.8)", border: "1px solid rgba(64, 64, 65, 0.8)", paddingLeft: "5px", paddingTop: "2px", paddingRight: "5px", paddingBottom: "2px", borderRadius: '5px' }, visible: true }); }); // cluster.addMarkers(this.markers); } }, getMaker() { var peopleList = this.peopleList if (peopleList.length != 0) { this.markers = [] for (var i = 0; i < peopleList.length; i++) { if (peopleList[i].lon && peopleList[i].lat) { var anchor = new qq.maps.Point(14, 28), size = new qq.maps.Size(28, 28), origin = new qq.maps.Point(0, 0), icon = new qq.maps.MarkerImage(this.iconUrl, size, origin, anchor); var position = new qq.maps.LatLng(peopleList[i].lat, peopleList[i].lon) var marker = new qq.maps.Marker({ position: position, map: map, icon: icon, title: peopleList[i].userName, }); this.marker = this.markers.push(marker) // 创建标记聚合器 } } const cluster = new qq.maps.MarkerCluster({ map: map, minimumClusterSize: 2, // 聚合触发阈值 markers: this.markers, gridSize: 40, // 聚合计算网格大小 zoomOnClick: true, // 点击聚合点自动缩放 onCluster: function(clusterMarker) { clusterMarker.setContent(`聚合数量:`); // 鼠标悬停事件 console.log("markers",markers) qq.maps.event.addListener(clusterMarker, 'mouseover', () => { // 提取所有标记的标签内容 const labelNames = markers.map(marker => marker.labelContent).join(','); infoWindow.setContent(` <div style="background: rgba(64, 64, 65, 0.9); color: white; padding: 6px 10px; border-radius: 4px; max-width: 250px; font-size: 12px;"> <strong>聚类点位(${count}):</strong> ${labelNames} </div> `); infoWindow.setPosition(clusterMarker.getPosition()); infoWindow.open(map); }); } }); // cluster.addMarkers(this.markers); } }, getTextByteLen(text) { var length = 0; text.split('').map(function(char) { if (char.charCodeAt(0) > 255) { //字符编码大于255,说明是双字节字符 length += 2; } else { length++; } }); return length; }, // 位置模糊搜索 remoteMethod(query) { if (query != '') { this.getAddress(query); } else { this.addressList = []; } }, // 地址选择 onChange(val) { console.log(val) map.panTo(new qq.maps.LatLng(val.location.lat, val.location.lng)); }, // 输入框模糊搜索 getAddress(query) { var that = this $.ajax({ url: "https://apis.map.qq.com/ws/place/v1/suggestion/", data: { key: '3NIBZ-NB5RB-WYUUM-NRFML-BJ6TT-I5FRV', keyword: query, region: '天津', output: 'jsonp', }, dataType: "jsonp", jsonp: "callback", //传递给请求处理程序或页面的,用以获得jsonp回调函数名的参数名(一般默认为:callback) jsonpCallback: "jsonpcallback", success: function(result) { console.log(result) that.addressList = result.data; } }); }, vue2 直接在原代码修改 聚合时不显示单个坐标点的标签,显示聚合的标签
最新发布
10-28
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值