功能描述: 拾取坐标
用户点击vue中的Button后,
vue ->>+ index.html: 发送消息:
index.html -->>- CoomandManager.js:
CoomandManager.js -->> index.html:
index.html -->>- vue:
vue页面
getcoord () { //拾取坐标的方法
// 1.向index.html发送消息
let messager = window.messagerService;
let postData = {
event: 'jicheng:PowerdataSubmited',
data: ''
};
messager.postMessageToParent(postData);
}
// 监听来自父级页面的消息
addMessageListener: function () {
let messager = window.messagerService;
messager.addListener('jicheng:PowerdataSubmited', (data) => {
console.log('event data from parent page', data);
topic.publish(Messages.MISPANE_OPEN);
if (data) {
}
});
},
index.html页面
var xytolonlat = webMercatorUtils.xyToLngLat;
// console.log("webMercatorUtils", webMercatorUtils)
window.messagerService.addListener('jicheng:PowerdataSubmited', function(data) {
var listener = topic.subscribe(Messages.EDITOR_DRAWPOINT_END, function(param) {
// console.log(webMercatorUtils)
var graphic = param.drawgraphic;
var point = param.drawgraphic.geometry;
var p = xytolonlat(point.x, point.y);
point = new Point(p[0], p[1]);
window.messagerService.postMessageToChildIframe({
event: 'jicheng:PowerdataSubmited',
data: JSON.stringify(point)
})
listener.remove(); //dojo topic subscribe 取消监听
});
console.log("listener", listener)
topic.publish(Messages.MISPANE_CLOSE);
topic.publish(Messages.EDITOR_DRAWPOINT, {
"token": "pickupnewclear"
});
});
dojo发布者订阅者模式(topic.publish/topic.subscribe)
CommandManager.js
//拾取坐标
topic.subscribe(Messages.EDITOR_DRAWPOINT_END, dojo.hitch(this,function(param){
if(param.token=="pickupnewclear"){
topic.publish(Messages.NUCLEAR_EDIT_SET_LOCATION, param);
}
}));