ESRI JS API Print widget:如何获取用户选中的布局和格式
ESRI Print Widget 布局/格式参数获取方法
ArcGIS API for JavaScript 4.x 版本(主流版本)
你可以通过两种场景获取参数:
实时监听用户选择变更
通过watch绑定viewModel的对应属性实现:
const printWidget = new Print({ view: view, printServiceUrl: "你的打印服务地址" }); // 监听布局变更 printWidget.watch("viewModel.layout", (newVal) => { console.log("当前选中布局:", newVal); }); // 监听格式变更 printWidget.watch("viewModel.format", (newVal) => { console.log("当前选中格式:", newVal); });
打印提交时获取
直接监听组件的submit事件,从事件参数里提取:
printWidget.on("submit", (e) => { const selectedLayout = e.template.layout; const selectedFormat = e.template.format; // 这里直接使用两个参数即可 });
ArcGIS API for JavaScript 3.x 版本
实时监听变更
绑定property-change事件筛选对应属性:
const printWidget = new Print({ map: map, url: "你的打印服务地址" }, "printDiv"); printWidget.startup(); printWidget.on("property-change", (evt) => { if(evt.propertyName === "layout"){ console.log("当前布局:", evt.value); } if(evt.propertyName === "format"){ console.log("当前格式:", evt.value); } });
打印启动时获取
printWidget.on("print-start", () => { const selectedLayout = printWidget.get("layout"); const selectedFormat = printWidget.get("format"); });
注意:如果你自定义了打印模板,请不要硬编码layout和format属性,否则用户选择的数值不会同步到上述属性中。
内容的提问来源于stack exchange,提问作者nadiamoa
相关产品推荐
相关产品推荐

