OpenLayers学习笔记(四)— QML显示html中openlayers地图的坐标

GitHub:八至

作者:狐狸家的鱼

本文链接:实现QML中显示html中地图的坐标

如何QML与HTML通信已经在这篇文章 QML与HTML通信之画图 详细讲述了

1.HTML

var coord;
map.on('singleclick',(evt)=>{
       coord = ol.coordinate.toStringXY(ol.proj.transform(evt.coordinate,'EPSG:3857','EPSG:4326'),2);
       content.changeText(coord);
});

2.QML

(1)WebChannel中

function changeText(newText) {//鼠标点击经纬度显示 鼠标点击时会调用该函数 并更新文本coordinateTex
        console.log(newText);
        giwSC.coordinateTex = newText;//
    }

(2)label.qml中

MyText{
      id:coordinateTex;
      fontSize: l;
      text: "104.08,30.66";
}
原文地址:https://www.cnblogs.com/suRimn/p/10113654.html