mirror of
https://github.com/ea4k/klog.git
synced 2024-09-21 02:18:32 +00:00
test canvas
This commit is contained in:
parent
d50cb684af
commit
772f63a527
@ -352,7 +352,7 @@ int Locator::getDistance(const double lon1, const double lat1, const double lon2
|
||||
bool Locator::checkCoords(const double lon1, const double lat1){
|
||||
//qDebug() << "Locator::checkCoords" ;
|
||||
// Checks if a coordinates is correct.
|
||||
if ((lat1 > 90.0 || lat1 < -90.0) && (lon1 > 180.0 || lon1 < -180.0)){
|
||||
if (((lat1 <= 90.0) || (lat1 >= -90.0)) && ((lon1 <= 180.0) || (lon1 >= -180.0))){
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
|
@ -37,9 +37,24 @@ Rectangle {
|
||||
property alias lat: map.center.latitude
|
||||
property alias lon: map.center.longitude
|
||||
property double oldZoom
|
||||
property double locatorTemplateW
|
||||
property double locatorTemplateH
|
||||
property int wgrid
|
||||
/*
|
||||
if (aux.length() == 2)
|
||||
{
|
||||
return (((aux.at(1)).toLatin1() - 'A') * 10) - 85;
|
||||
}
|
||||
*/
|
||||
//function getLat(b) {
|
||||
// a = qth.charCodeAt(0) - 65;
|
||||
// return a*20
|
||||
//}
|
||||
|
||||
//property alias mapLocale: map.plugin.locales
|
||||
|
||||
Location {
|
||||
Location
|
||||
{
|
||||
// Define location that will be "center" of map
|
||||
id: mapCenter
|
||||
}
|
||||
@ -86,7 +101,7 @@ Rectangle {
|
||||
//{
|
||||
// console.log("Map Center X: ", lat, " - Map Center Y: ", lon);
|
||||
//}
|
||||
zoomLevel: 14
|
||||
zoomLevel: 5
|
||||
MouseArea
|
||||
{
|
||||
hoverEnabled: true
|
||||
@ -122,7 +137,6 @@ Rectangle {
|
||||
|
||||
Rectangle {
|
||||
id: buttonout
|
||||
|
||||
width: 30
|
||||
height: 30
|
||||
border.color: "red"
|
||||
@ -146,6 +160,7 @@ Rectangle {
|
||||
onClicked: {
|
||||
oldZoom = zoom
|
||||
zoom = oldZoom - 1
|
||||
canvasGrid.requestPaint()
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -174,6 +189,7 @@ Rectangle {
|
||||
onClicked: {
|
||||
oldZoom = zoom
|
||||
zoom = oldZoom + 1
|
||||
canvasGrid.requestPaint()
|
||||
//buttonText.text = qsTr("Clicked");
|
||||
//buttonText.color = "black";
|
||||
}
|
||||
@ -191,6 +207,27 @@ Rectangle {
|
||||
color : model.color
|
||||
//opacity : 0.5
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
hoverEnabled: true
|
||||
anchors.fill: parent
|
||||
//acceptedButtons: Qt.LeftButton
|
||||
//onClicked:
|
||||
//{
|
||||
// console.log("left button clicked!")
|
||||
//}
|
||||
/*
|
||||
onPositionChanged:
|
||||
{
|
||||
Qt.point(mouseX, mouseY)
|
||||
var coordinate = map.toCoordinate(Qt.point(mouse.x,mouse.y))
|
||||
console.log("Mouse Position (", mouseX, ", ", mouseY, ")");
|
||||
console.log("Mouse GeoPosition (", coordinate.latitude, ", ", coordinate.longitude, ")");
|
||||
var posicion = map.fromCoordinate(coordinate, false);
|
||||
console.log("Pos (", posicion.x, ", ", posicion.y, ")");
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
MapItemView
|
||||
{
|
||||
@ -202,6 +239,100 @@ Rectangle {
|
||||
border.width: 10
|
||||
}
|
||||
}
|
||||
Canvas {
|
||||
id: canvasGrid
|
||||
anchors.fill : parent
|
||||
function clear_canvas() {
|
||||
var ctx = getContext("2d");
|
||||
ctx.reset();
|
||||
requestPaint();
|
||||
}
|
||||
onPaint: {
|
||||
|
||||
clear_canvas()
|
||||
if (map.zoomLevel > 7)
|
||||
{
|
||||
//wgrid = 80
|
||||
console.log("Zoom>7: ", zoom);
|
||||
console.log("wgrid: ", wgrid);
|
||||
}
|
||||
else
|
||||
{
|
||||
//wgrid = 10
|
||||
console.log("Zoom<7: ", zoom);
|
||||
console.log("wgrid: ", wgrid);
|
||||
}
|
||||
|
||||
var ctx = getContext("2d")
|
||||
ctx.lineWidth = 1
|
||||
ctx.strokeStyle = "black"
|
||||
ctx.beginPath()
|
||||
/*
|
||||
var posicion = map.fromCoordinate(coordinate, false);
|
||||
console.log("Pos (", posicion.x, ", ", posicion.y, ")");
|
||||
*/
|
||||
//https://dxcluster.ha8tks.hu/hamgeocoding/L.Maidenhead.js
|
||||
//wgrid = 18
|
||||
//var nrows = height/wgrid;
|
||||
console.log("Height: ", height);
|
||||
console.log("Width: ", width);
|
||||
//console.log("Rows: ", nrows);
|
||||
var w = map.toCoordinate(Qt.point(0,0));
|
||||
var e = map.toCoordinate(Qt.point(width,height));
|
||||
console.log("West: ", w.latitude, ",", w.longitude);
|
||||
console.log("East: ", e.latitude, ",", e.longitude);
|
||||
|
||||
//coordinate: QtPositioning.coordinate(-27.5, 153.1)
|
||||
var nrows = 18
|
||||
var lati = w.longitude
|
||||
var posici
|
||||
//center: QtPositioning.coordinate(19.997454, 73.789803)
|
||||
var controlPoint = w
|
||||
//var mouseGeoPos = map.toCoordinate(Qt.point(mouse.x, mouse.y));
|
||||
//var preZoomPoint = map.fromCoordinate(mouseGeoPos, false);
|
||||
for(var i=0; i < 10; i++){
|
||||
//QtPositioning.coordinate((360/filas)*i, 0)
|
||||
// -180 -> 180
|
||||
controlPoint = controlPoint + QtPositioning.coordinate(w.latitude+(10.0*i), w.longitude)
|
||||
//posici = map.fromCoordinate(controlPoint, true);
|
||||
|
||||
lati = posici.y
|
||||
console.log("Y: ", lati);
|
||||
ctx.moveTo(0, lati);
|
||||
ctx.lineTo(width, lati);
|
||||
}
|
||||
//for(var i=0; i < nrows+1; i++){
|
||||
// ctx.moveTo(0, wgrid*i);
|
||||
// ctx.lineTo(width, wgrid*i);
|
||||
//}
|
||||
|
||||
//var ncols = width/wgrid
|
||||
//console.log("Painting ncols: ", ncols);
|
||||
//for(var j=0; j < ncols+1; j++){
|
||||
// ctx.moveTo(wgrid*j, 0);
|
||||
// ctx.lineTo(wgrid*j, height);
|
||||
//}
|
||||
ctx.closePath()
|
||||
ctx.stroke()
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Text { // text changes when button was clicked
|
||||
id: status
|
||||
//x: 12; y: 76
|
||||
//width: 116; height: 26
|
||||
text: "waiting ..."
|
||||
//horizontalAlignment: Text.AlignHCenter
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
//verticalAlignment: Text.AlignVCenter
|
||||
//anchors.centerIn: parent
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -32,16 +32,13 @@
|
||||
|
||||
MapWidget::MapWidget(QWidget *parent)
|
||||
{
|
||||
|
||||
//qDebug() << Q_FUNC_INFO;
|
||||
|
||||
//qDebug() << Q_FUNC_INFO << " - END";
|
||||
}
|
||||
|
||||
void MapWidget::init()
|
||||
{
|
||||
createUI();
|
||||
|
||||
}
|
||||
|
||||
void MapWidget::createUI()
|
||||
@ -81,7 +78,7 @@ void MapWidget::clearMap()
|
||||
void MapWidget::setCenter(const Coordinate &_c)
|
||||
{
|
||||
QObject *object = qmlView.rootObject ();
|
||||
object->setProperty ("zoom", 8.0);
|
||||
object->setProperty ("zoom", 2.0);
|
||||
object->setProperty ("lat", _c.lat);
|
||||
object->setProperty ("lon", _c.lon);
|
||||
//qDebug() << Q_FUNC_INFO << " - END";
|
||||
@ -104,10 +101,6 @@ void MapWidget::addMarker(const Coordinate _coord)
|
||||
QObject *object = qmlView.rootObject ();
|
||||
QMetaObject::invokeMethod(object, "addMarker",
|
||||
Q_ARG(double, _coord.lat), Q_ARG(double, _coord.lon));
|
||||
// QMetaObject::invokeMethod(object, "addMarker",
|
||||
// Q_RETURN_ARG(QString, returnedValue),
|
||||
// Q_ARG(double, 40.5), Q_ARG(double, -3.5));
|
||||
|
||||
}
|
||||
|
||||
void MapWidget::addQSO(const QString &_loc)
|
||||
@ -118,7 +111,6 @@ void MapWidget::addQSO(const QString &_loc)
|
||||
return;
|
||||
}
|
||||
qmlView.rootContext()->setContextProperty("circle_model", &modelCircle);
|
||||
//qmlView.setSource(QUrl(QStringLiteral("qrc:qml/mapqmlfile.qml")));
|
||||
QStandardItem *item = new QStandardItem;
|
||||
item->setData(QVariant::fromValue(QGeoCoordinate(locator.getLat(_loc), locator.getLon(_loc))), CoordinateRole);
|
||||
modelCircle.appendRow(item);
|
||||
@ -152,6 +144,7 @@ void MapWidget::addLocator(const QString &_loc, const QColor &_color)
|
||||
item->setData(QVariant::fromValue(QGeoCoordinate(_north.lat, _north.lon)), NorthRole);
|
||||
item->setData(QVariant::fromValue(QGeoCoordinate(_south.lat, _south.lon)), SouthRole);
|
||||
item->setData(QVariant::fromValue(_color), ColorRole);
|
||||
item->setData(QVariant::fromValue(_loc), TextRole);
|
||||
modelRectangle.appendRow(item);
|
||||
//qDebug() << Q_FUNC_INFO << " Rectangle OK";
|
||||
}
|
||||
|
@ -64,6 +64,7 @@ private:
|
||||
int NorthRole = Qt::UserRole + 1000;
|
||||
int SouthRole = Qt::UserRole + 1001;
|
||||
int ColorRole = Qt::UserRole + 1002;
|
||||
int TextRole = Qt::UserRole + 1003;
|
||||
Locator locator;
|
||||
//double lat, lon;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user