"use script"; //开发环境建议开启严格模式
(function (window, mars3d) {
//创建widget类,需要继承BaseWidget
class MyWidget extends mars3d.widget.BaseWidget {
//外部资源配置
get resources() {
return ["view.css"];
}
//弹窗配置
get view() {
return {
type: "append",
url: "view.html",
parent: "body",
};
}
//初始化[仅执行1次]
create() {
this.storageName = "mars3d_queryBaiduPOI";
this.pageSize = 6;
this.allpage = 0;
this.thispage = 0;
//创建矢量数据图层
this.graphicLayer = new mars3d.layer.GraphicLayer({
name: this.config.name,
pid: 99, //图层管理 中使用,父节点id
});
//鼠标单击后的信息面板弹窗
this.graphicLayer.bindPopup(function (event) {
let item = event.graphic?.attr;
if (!item) {
return;
}
var name;
if (item.detailUrl) {
name = '' + item.name + "";
} else {
name = item.name;
}
var inHtml = '
";
return inHtml;
});
//查询控制器
this._queryPoi = new mars3d.query.BaiduPOI({
// city: '合肥市',
});
}
//每个窗口创建完成后调用
winCreateOK(opt, result) {
if (opt.type != "append") {
return;
}
var that = this;
var img = $("#map-querybar img");
img.each((index, item) => {
$(item).attr("src", this.path + $(item).attr("src"));
});
if (this.config.position) {
$("#map-querybar").css(this.config.position);
}
if (this.config.style) {
$("#map-querybar").css(this.config.style);
}
// 搜索框
$("#txt_querypoi").click(function () {
// 文本框内容为空
if ($.trim($(this).val()).length === 0) {
that.hideAllQueryBarView();
that.showHistoryList(); // 显示历史记录
}
});
var timetik = 0;
// 搜索框绑定文本框值发生变化,隐藏默认搜索信息栏,显示匹配结果列表
$("#txt_querypoi").bind("input propertychange", () => {
clearTimeout(timetik);
timetik = setTimeout(() => {
this.hideAllQueryBarView();
this.clearLayers();
var queryVal = $.trim($("#txt_querypoi").val());
if (queryVal.length == 0) {
// 文本框内容为空,显示历史记录
this.showHistoryList();
} else {
this.autoTipList(queryVal, true);
}
}, 500);
});
// 点击搜索查询按钮
$("#btn_querypoi").click(() => {
clearTimeout(timetik);
this.hideAllQueryBarView();
var queryVal = $.trim($("#txt_querypoi").val());
this.strartQueryPOI(queryVal, true);
});
//绑定回车键
$("#txt_querypoi").bind("keydown", (event) => {
if (event.keyCode == "13") {
$("#btn_querypoi").click();
}
});
// 返回查询结果面板界面
$("#querybar_detail_back").click(() => {
this.hideAllQueryBarView();
$("#querybar_resultlist_view").show();
});
}
//打开激活
activate() {
this.map.addLayer(this.graphicLayer);
$(".mars3d-locationbar").append('没有找到"' + this.queryText + '"相关结果
';
} else {
this.objResultData = this.objResultData || {};
for (var index = 0; index < data.length; index++) {
var item = data[index];
var startIdx = (this.thispage - 1) * this.pageSize;
item.index = startIdx + (index + 1);
var _id = index;
inhtml += `