Browse Source

feat 修复感知事件 分页点击对应错乱问题

wangqin
qingzhengli 8 months ago
parent
commit
039db9782e
  1. 34
      ruoyi-ui/src/views/JiHeExpressway/pages/Home/components/RoadAndEvents/utils/map.js

34
ruoyi-ui/src/views/JiHeExpressway/pages/Home/components/RoadAndEvents/utils/map.js

@ -106,8 +106,9 @@ export class MarkerCluster {
const pageSize = 6; const pageSize = 6;
let page = 1; let page = 1;
const totalPages = Math.ceil(data.length / pageSize); const totalPages = Math.ceil(data.length / pageSize);
const dataFirstPage = const currentPageData =
totalPages > 1 ? data.slice((page - 1) * pageSize, pageSize) : data; totalPages > 1 ? data.slice((page - 1) * pageSize, pageSize) : data;
window.currentPageData = currentPageData;
window.pageSize = pageSize; window.pageSize = pageSize;
window.page = page; window.page = page;
window.totalPages = totalPages; window.totalPages = totalPages;
@ -127,7 +128,7 @@ export class MarkerCluster {
// 截取当前页的数据 // 截取当前页的数据
const currentPageData = data.slice(startIndex, endIndex); const currentPageData = data.slice(startIndex, endIndex);
window.currentPageData = currentPageData;
const itemsTpl = currentPageData const itemsTpl = currentPageData
.map( .map(
(item) => ` (item) => `
@ -144,15 +145,7 @@ export class MarkerCluster {
.join(""); .join("");
// 渲染当前页数据 // 渲染当前页数据
dataContainer.innerHTML = itemsTpl; dataContainer.innerHTML = itemsTpl;
window.infoWindow.dom bindItemClick();
.querySelectorAll(".info-window-item")
.forEach((item, index) => {
item.onclick = () =>
data[index].config.markerClick?.(
data[index].extData,
data[index].config?.item
);
});
} }
window.renderData = renderData; window.renderData = renderData;
@ -173,7 +166,7 @@ export class MarkerCluster {
<img class="info-close" style="width: 12px;cursor: pointer;" src="${require("@screen/images/dialog/icon-close.svg")}" /> <img class="info-close" style="width: 12px;cursor: pointer;" src="${require("@screen/images/dialog/icon-close.svg")}" />
</div> </div>
<div id="dataContainer" style="padding: 15px 9px;flex: 1; overflow: auto;" class="info-window-content"> <div id="dataContainer" style="padding: 15px 9px;flex: 1; overflow: auto;" class="info-window-content">
${dataFirstPage ${currentPageData
.map( .map(
(item) => ` (item) => `
<div style="cursor: pointer; padding: 3px 6px;display: flex;align-items: center; gap: 6px;" class="info-window-item"> <div style="cursor: pointer; padding: 3px 6px;display: flex;align-items: center; gap: 6px;" class="info-window-item">
@ -199,7 +192,7 @@ export class MarkerCluster {
} }
</div>`); </div>`);
window.infoWindow = this.infoWindow; window.infoWindow = this.infoWindow;
this.infoWindow.open(map, data[0].lnglat); this.infoWindow.open(map, currentPageData[0].lnglat);
this.infoWindow.dom.querySelector(".info-close").onclick = () => this.infoWindow.dom.querySelector(".info-close").onclick = () =>
this.infoWindow.close(); this.infoWindow.close();
@ -211,16 +204,21 @@ export class MarkerCluster {
this.infoWindow.dom.querySelector(".info-window-content").onwheel = (e) => this.infoWindow.dom.querySelector(".info-window-content").onwheel = (e) =>
e.stopPropagation(); e.stopPropagation();
this.infoWindow.dom function bindItemClick() {
window.infoWindow.dom
.querySelectorAll(".info-window-item") .querySelectorAll(".info-window-item")
.forEach((item, index) => { .forEach((item, index) => {
item.onclick = () => item.onclick = () => {
data[index].config.markerClick?.( const currentPageData = window.currentPageData;
data[index].extData, currentPageData[index].config.markerClick?.(
data[index].config?.item currentPageData[index].extData,
currentPageData[index].config?.item
); );
};
}); });
} }
bindItemClick();
}
async setMarkerCluster() { async setMarkerCluster() {
const AMap = await loadAMap(); const AMap = await loadAMap();

Loading…
Cancel
Save