20250619学习日志
Decorator模式——登场角色
Component:被装饰物
ConcreteComponent:具体被装饰物
Border:装饰
SideBorder:具体装饰
FullBorder:具体装饰
类图

Decorator模式——拓展思路
透明性
得益于接口(API)的透明性,装饰边框中的“被装饰物”实际上有是别的物体的“装饰边框”,如:

腾讯地图API
TMap:构建地图基本对象
center:填入经纬度(必须)
let center = new TMap.LatLng(39.984104, 116.307503);
//初始化地图
map = new TMap.Map(document.getElementById('container'), {
rotation: 20,//设置地图旋转角度
pitch:30, //设置俯仰角度(0~45)
zoom:12,//设置地图缩放级别
center: center//设置地图中心点坐标
});MultiMarker:地图选点
markerLayer.setGeometries([])
nearbyStation(center.lat, center.lng).then(response => {
let latLngList = response.data;
for (let i = 0; i < latLngList.length; i++) {
let station = latLngList[i];
let position = new TMap.LatLng(station.latitude, station.longitude)
// 参考示例 https://lbs.qq.com/webDemoCenter/glAPI/glServiceLib/search
let geometries = markerLayer.getGeometries();
geometries.push({
id: String(i), // 点标注数据数组
position: position
});
markerLayer.updateGeometries(geometries); // 绘制地点标注一些标记配置:
let isUsable = "不可借";
if(station.isUsable == '1') {
isUsable = "可借";
}
let isReturn = "不可还";
if(station.isReturn == '1') {
isReturn = "可还";
}
//创建InfoWindow实例,并进行初始化
var infoWindow = new TMap.InfoWindow({
map: map,
position: position,
offset: { x: 0, y: -32 },
//设置infoWindow,content支持直接传入html代码,以实现各类内容格式需求
content: "<div class=\"info-container\">\n" +
" <div class=\"image-container\">\n" +
" <img src=\""+station.imageUrl+"\">\n" +
" </div>\n" +
" <div class=\"text-container\">\n" +
" <p style='font-weight: bold;'>"+station.name+"</p>\n" +
" <p style='font-size: 12px;'>"+station.fullAddress+"</p>\n" +
" <p>运营时间:"+station.businessHours+"</p>\n" +
" <p>"+isUsable+" "+isReturn+"</p>\n" +
" </div>\n" +
"</div>"
});
infoWindowList[i] = infoWindow;
infoWindow.close();//初始关闭信息窗关闭
//监听标注点击事件
markerLayer.on("click", function (evt) {
//关闭全部信息窗
infoWindowList.forEach(item => item.close());
// 打开点击的信息窗
infoWindowList[Number(evt.geometry.id)].open();
})
}算法——解题
[LCR 012. 寻找数组的中心下标 - 力扣(LeetCode)](https://leetcode.cn/problems/tvdfij/description/)
解题思路
这题需要使用到一个变量 sum 以及前缀和的思想:
[1, 7, 3, 6, 5, 6]:
sum= 28nums[0]= 1
随着sum不断缩小: sum - 1 -> sum - 7 -> ...
使用一个cur记录当前的总和,即可得到两边的和:
cur是左边之和
sum为右边之和
- 感谢你赐予我前进的力量
赞赏者名单
因为你们的支持让我意识到写文章的价值🙏
本文是原创文章,采用 CC BY-NC-ND 4.0 协议,完整转载请注明来自 zxb
评论
隐私政策
你无需删除空行,直接评论以获取最佳展示效果

