diff --git a/wasm/Client/js/scripts.js b/wasm/Client/js/scripts.js
index 725df07..62580be 100644
--- a/wasm/Client/js/scripts.js
+++ b/wasm/Client/js/scripts.js
@@ -1,7 +1,5 @@
var mapsPlaceholder = [];
var serverMarkers = [];
-var mine;
-let qtModule = undefined;
async function init() {
@@ -27,7 +25,7 @@ async function init() {
showUi(spinner);
status.innerHTML = 'Loading...';
- qtModule = await qtLoad({
+ const instance = await qtLoad({
qt: {
onLoaded: () =>
{
@@ -35,17 +33,19 @@ async function init() {
resized = function() {
if(document.documentElement.clientWidth<600)
{
- document.getElementById("map").style.zIndex = "1000";
- document.getElementById("qtrootDiv").style.zIndex = "1";
- qtModule.BookClient.instance().setOneColumn(1);
+ document.getElementById("map").style.visibility = "visible";
+ document.getElementById("qtrootDiv").style.visibility = "hidden";
+ instance.BookClient.instance().setOneColumn(1);
}
else
{
- qtModule.BookClient.instance().setOneColumn(0);
+ document.getElementById("map").style.visibility = "visible";
+ document.getElementById("qtrootDiv").style.visibility = "visible";
+ instance.BookClient.instance().setOneColumn(0);
}
var canvas = document.getElementById("screen");
- qtModule.qtResizeContainerElement(canvas);
+ instance.qtResizeContainerElement(canvas);
}
window.addEventListener("resize", resized);
L.Map.addInitHook(function () {
@@ -54,10 +54,6 @@ async function init() {
document.getElementById("map").style.visibility = "visible";
const map = L.map('map').setView([51.505, -0.09], 13);
- const mineMarker = L.icon({
- iconUrl: 'img/mineMarker.png',
- iconSize: [24, 24],
- });
L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19,
@@ -73,22 +69,22 @@ async function init() {
function success(pos) {
const crd = pos.coords;
- mine.setLatLng([crd.latitude,crd.longitude]);
- }
- function initmapview(pos) {
- const crd = pos.coords;
-
- mine = new L.marker([crd.latitude,crd.longitude],{icon: mineMarker});
- map.addLayer(mine);
- map.setView([crd.latitude,crd.longitude],13);
- const recButt = document.querySelector("#recenter");
- recButt.style.visibility="visible";
- recButt.onclick = () => {
- map.setView(mine.getLatLng(),13);
-
- };
-
+ if ( typeof success.mine == 'undefined' ) {
+ const mineMarker = L.icon({
+ iconUrl: 'img/mineMarker.png',
+ iconSize: [24, 24],
+ });
+ success.mine = new L.marker([crd.latitude,crd.longitude],{icon: mineMarker});
+ map.addLayer(success.mine);
+ map.setView([crd.latitude,crd.longitude],13);
+ const recButt = document.querySelector("#recenter");
+ recButt.style.visibility="inherit";
+ recButt.onclick = () => {
+ map.setView(success.mine.getLatLng(),13);
+ };
+ }
+ success.mine.setLatLng([crd.latitude,crd.longitude]);
}
function error(err) {
console.warn(`ERROR(${err.code}): ${err.message}`);
@@ -96,7 +92,6 @@ async function init() {
}
id = navigator.geolocation.watchPosition(success, error, options);
- navigator.geolocation.getCurrentPosition(initmapview, error, options);
},
onExit: exitData =>
diff --git a/wasm/Client/style.css b/wasm/Client/style.css
index 101d8db..119d774 100644
--- a/wasm/Client/style.css
+++ b/wasm/Client/style.css
@@ -22,7 +22,6 @@ html,body{
height: 100%;
width: 100%;
position: absolute;
- z-index:1;
}
a{
text-decoration: underline;
From 2bef484c21a774599795fef72cef0fd1ab5a8d4b Mon Sep 17 00:00:00 2001
From: Eduardo Gonzalez Lazo <30321688+EddyTheCo@users.noreply.github.com>
Date: Sat, 17 Feb 2024 13:27:31 +0100
Subject: [PATCH 3/3] improved logic
---
Client/main.cpp | 2 +-
Client/qml/window.qml | 1 +
Server/include/server.hpp | 17 +++++++++++------
Server/main.cpp | 6 +++---
Server/qml/ConfDrawer.qml | 3 ++-
Server/qml/window.qml | 15 ++++++++-------
Server/src/server.cpp | 16 ++++++----------
wasm/Client/js/scripts.js | 27 ++++++++++++++-------------
8 files changed, 46 insertions(+), 41 deletions(-)
diff --git a/Client/main.cpp b/Client/main.cpp
index 212f592..f99ebe5 100644
--- a/Client/main.cpp
+++ b/Client/main.cpp
@@ -21,7 +21,7 @@ int main(int argc, char *argv[])
engine.addImportPath("qrc:/esterVtech.com/imports");
- const QUrl url(u"qrc:/esterVtech.com/imports/Esterv/DLockers/Client/qml/window.qml"_qs);
+ const QUrl url("qrc:/esterVtech.com/imports/Esterv/DLockers/Client/qml/window.qml");
engine.load(url);
return app.exec();
}
diff --git a/Client/qml/window.qml b/Client/qml/window.qml
index 2174321..e8429b3 100644
--- a/Client/qml/window.qml
+++ b/Client/qml/window.qml
@@ -10,6 +10,7 @@ import Esterv.DLockers.Client
ApplicationWindow {
id:window
+ visible:true
FontLoader {
id: webFont
source: "qrc:/esterVtech.com/imports/Esterv/DLockers/Client/qml/fonts/DeliciousHandrawn-Regular.ttf"
diff --git a/Server/include/server.hpp b/Server/include/server.hpp
index 7e84b9d..4d54ce6 100644
--- a/Server/include/server.hpp
+++ b/Server/include/server.hpp
@@ -21,7 +21,8 @@ class BookServer : public QObject
{
Q_OBJECT
Q_PROPERTY(bool open READ isOpen NOTIFY openChanged)
- Q_PROPERTY(std::vector
coords READ coords NOTIFY coordsChanged)
+ Q_PROPERTY(float latitude READ latitude NOTIFY latitudeChanged)
+ Q_PROPERTY(float longitude READ longitude NOTIFY longitudeChanged)
Q_PROPERTY(DayModel* dayModel READ dayModel CONSTANT)
Q_PROPERTY(State state READ state NOTIFY stateChanged)
Q_PROPERTY(QString openAddress READ getOpenAddress NOTIFY openAddressChanged)
@@ -37,11 +38,14 @@ class BookServer : public QObject
Q_ENUM(State)
static BookServer* instance(){return m_instance;}
DayModel* dayModel(void)const{return m_dayModel;}
- std::vector coords()const{return m_coords;}
+ qreal longitude()const{return m_longitude;}
+ qreal latitude()const{return m_latitude;}
void setCoords(float lat,float lon)
{
- m_coords.at(0)=lat;
- m_coords.at(1)=lon;
+ m_latitude=lat;
+ m_longitude=lon;
+ emit latitudeChanged();
+ emit longitudeChanged();
}
void setOpen(bool op){if(op!=m_open){m_open=op;emit openChanged();}}
bool isOpen()const{return m_open;}
@@ -54,7 +58,8 @@ class BookServer : public QObject
signals:
- void coordsChanged();
+ void latitudeChanged();
+ void longitudeChanged();
void stateChanged();
void openChanged();
void openAddressChanged();
@@ -79,7 +84,7 @@ class BookServer : public QObject
void checkLPermission();
void initGPS();
- std::vector m_coords;
+ qreal m_latitude,m_longitude;
DayModel* m_dayModel;
State m_state;
c_array m_pubId;
diff --git a/Server/main.cpp b/Server/main.cpp
index db214fb..be2a5e2 100644
--- a/Server/main.cpp
+++ b/Server/main.cpp
@@ -9,13 +9,13 @@ int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
#if defined(FORCE_STYLE)
- QQuickStyle::setStyle(FORCE_STYLE);
+ QQuickStyle::setStyle(FORCE_STYLE);
#endif
QQmlApplicationEngine engine;
engine.addImportPath("qrc:/esterVtech.com/imports");
- engine.addImageProvider(QLatin1String("qrcode"), new QRImageProvider(1));
- const QUrl url(u"qrc:/esterVtech.com/imports/Esterv/DLockers/Server/qml/window.qml"_qs);
+ engine.addImageProvider(QLatin1String("qrcode"), new QRImageProvider(1));
+ const QUrl url("qrc:/esterVtech.com/imports/Esterv/DLockers/Server/qml/window.qml");
engine.load(url);
return app.exec();
}
diff --git a/Server/qml/ConfDrawer.qml b/Server/qml/ConfDrawer.qml
index 0200d94..d9dc06d 100644
--- a/Server/qml/ConfDrawer.qml
+++ b/Server/qml/ConfDrawer.qml
@@ -39,10 +39,11 @@ Drawer
NodeConnectionSettings
{
- id:conn_
+ id:conn
Layout.fillWidth: true
}
+
}
}
diff --git a/Server/qml/window.qml b/Server/qml/window.qml
index e9fb471..6e903af 100644
--- a/Server/qml/window.qml
+++ b/Server/qml/window.qml
@@ -34,14 +34,12 @@ ApplicationWindow {
});
}
-
ConfDrawer
{
id:drawer
width: Math.max(parent.width*0.2,350)
height: window.height
}
-
ColumnLayout
{
anchors.fill: parent
@@ -64,9 +62,9 @@ ApplicationWindow {
}
Timer {
id:goback
- interval: 60000; running: false; repeat: false
- onTriggered: openbut.inOpenBox=false;
- }
+ interval: 60000; running: false; repeat: false
+ onTriggered: openbut.inOpenBox=false;
+ }
}
RowLayout
{
@@ -137,14 +135,17 @@ ApplicationWindow {
Layout.minimumHeight: 150
Layout.maximumHeight: width
Layout.alignment: Qt.AlignCenter
- latitude:BookServer.coords[0]
- longitude:BookServer.coords[1]
+ latitude: BookServer.latitude
+ longitude: BookServer.longitude
color:Style.frontColor2
}
+
+
}
}
+
}
diff --git a/Server/src/server.cpp b/Server/src/server.cpp
index 62a1d1e..5317e3e 100644
--- a/Server/src/server.cpp
+++ b/Server/src/server.cpp
@@ -35,10 +35,6 @@ EM_JS(void, js_getPos, (), {
function success(pos) {
const crd = pos.coords;
- console.log("Your current position is:");
- console.log(`Latitude : ${crd.latitude}`);
- console.log(`Longitude: ${crd.longitude}`);
- console.log(`More or less ${crd.accuracy} meters.`);
Module.BookServer.instance().setCoords(crd.latitude,crd.longitude);
}
@@ -213,7 +209,7 @@ void BookServer::restart(void)
#include
-BookServer::BookServer(QObject *parent):QObject(parent),m_pph(10000),m_coords({-90+QRandomGenerator::system()->generateDouble()*180,-180+QRandomGenerator::system()->generateDouble()*360}),m_state(Ready),m_open(false),m_dayModel(new DayModel(this)),
+BookServer::BookServer(QObject *parent):QObject(parent),m_pph(10000),m_latitude(-90+QRandomGenerator::system()->generateDouble()*180),m_longitude(-180+QRandomGenerator::system()->generateDouble()*360),m_state(Ready),m_open(false),m_dayModel(new DayModel(this)),
m_timer(new QTimer(this)),receiver(nullptr)
{
Account::instance()->setVaultFile(
@@ -228,7 +224,6 @@ BookServer::BookServer(QObject *parent):QObject(parent),m_pph(10000),m_coords({-
Account::instance()->readFromVault(VAULT_PASS);
}
- //Account::instance()->setSeed("marriage casual adjust trim rail jungle impact view lyrics ginger taxi upset edit negative crystal base amount food wine suit vendor scrub arrow basket");
m_instance=this;
connect(Wallet::instance(),&Wallet::synced,this,[=](){
restart();
@@ -248,9 +243,10 @@ void BookServer::initGPS(void)
connect(PosSource,&QGeoPositionInfoSource::positionUpdated,
this, [=](const QGeoPositionInfo &update){
const auto geoCoord=update.coordinate();
- m_coords.at(0)=geoCoord.latitude();
- m_coords.at(1)=geoCoord.longitude();
- emit coordsChanged();
+ m_latitude=geoCoord.latitude();
+ m_longitude=geoCoord.longitude();
+ emit latitudeChanged();
+ emit longitudeChanged();
});
connect(PosSource,&QGeoPositionInfoSource::errorOccurred,
this, [=](QGeoPositionInfoSource::Error _t1){
@@ -598,7 +594,7 @@ QByteArray BookServer::serializeState()const
var.insert("b",bookings);
var.insert("pph",QString::number(m_pph));
var.insert("pt",(++Wallet::instance()->addresses().begin())->second->getAddressHash());
- var.insert("c",QJsonArray({m_coords.at(0),m_coords.at(1)}));
+ var.insert("c",QJsonArray({m_latitude,m_longitude}));
auto state = QJsonDocument(var);
return state.toJson();
}
diff --git a/wasm/Client/js/scripts.js b/wasm/Client/js/scripts.js
index 62580be..f5a2065 100644
--- a/wasm/Client/js/scripts.js
+++ b/wasm/Client/js/scripts.js
@@ -3,6 +3,8 @@ var serverMarkers = [];
async function init() {
+
+
document.body.innerHTML += '
';
@@ -29,6 +31,18 @@ async function init() {
qt: {
onLoaded: () =>
{
+ document.getElementById("map").style.visibility = "visible";
+ L.Map.addInitHook(function () {
+ mapsPlaceholder.push(this);
+ });
+ const map = L.map('map').setView([51.505, -0.09], 13);
+
+ L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
+ maxZoom: 19,
+ crossOrigin: "",
+ attribution: '© OpenStreetMap '
+ },
+ ).addTo(map);
showUi(screen);
resized = function() {
if(document.documentElement.clientWidth<600)
@@ -48,19 +62,6 @@ async function init() {
instance.qtResizeContainerElement(canvas);
}
window.addEventListener("resize", resized);
- L.Map.addInitHook(function () {
- mapsPlaceholder.push(this);
- });
- document.getElementById("map").style.visibility = "visible";
- const map = L.map('map').setView([51.505, -0.09], 13);
-
-
- L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
- maxZoom: 19,
- crossOrigin: "",
- attribution: '© OpenStreetMap '
- },
- ).addTo(map);
const options = {
enableHighAccuracy: true,
timeout: 5000,