import QtQuick 2.0
import QtQuick.Window 2.0
import QtQuick.Controls 2.2
import QtPositioning 5.12
import QtLocation 5.12
import Esri.ArcGISRuntime 100.14
Item
{
id: qmlMap
signal transmetreClique (var lat, var log, var changer, var zoom)
signal transmettreCliqueSuppression(var lat, var log, var zoom)
signal clavierToucheSuppr()
signal undo();
signal redo();
MapView
{
anchors.fill: parent
// set focus to enable keyboard navigation
focus: true
property bool changer : false
property int item;
property bool animer : false
property int tot : 1
property bool buttonvalue : false;
property var polygon_contour_obj : null;
property var polygon_buffer_obj : null;
property var polygon_contour : null;
property var polygon_buffer : null;
property var listPolyline : [];
property var listPolygonContour : [];
id : map
Component.onCompleted: {
// Set the focus on MapView to initially enable keyboard navigation
forceActiveFocus();
}
// add a map to the mapview
Map {
// add the ArcGISTopographic basemap to the map
id : fondmap
initBasemapStyle: Enums.BasemapStyleArcGISImagery
initialViewpoint: viewpoint
}
GraphicsOverlay {
id: graphicsOverlay
}
ViewpointCenter {
id: viewpoint
// Specify the center Point
center: Point {
x: 2.3522219
y: 48.856614
spatialReference: SpatialReference {wkid: 4326}
}
targetScale: 50000000.0
}
onMouseClicked: { //on MapView
const spatialReference = ArcGISRuntimeEnvironment.createObject("SpatialReference",{wkid: 4326});
const projectedPoint = GeometryEngine.project(mouse.mapPoint, spatialReference);
console.log(projectedPoint.x,projectedPoint.y,map.mapScale );
if (mouse.button == Qt.LeftButton && mouse.objectName != 'bouton')
{
transmetreClique( projectedPoint.y,projectedPoint.x,map.changer, map.mapScale)
}
else
{
transmettreCliqueSuppression( projectedPoint.y, projectedPoint.x, map.mapScale);
map.changer = false
}
}
Keys.onPressed: {
if( event.key === Qt.Key_Escape)
{
//console.log("ok");
map.animer=false;
animation.running=false
map.changer = false
if(map.listPolygonContour[map.item].length > 3)
{
map.listPolygonContour[map.item][2].visible =true
}
}
else if (event.key === Qt.Key_Delete && map.changer)
{
clavierToucheSuppr()
map.changer = false
}
}
Button {
width: 80
height: 30
x: qmlMap.width-width-10
y: 10
id : buttonUndo
font.pointSize: 16;
background: Rectangle {
id : fondUndo;
radius: 5
}
property bool buttonvalue : true;
//color:"yellow"
visible: true
text: ">"
flat : false
onPressed: {
fondUndo.opacity = .80
redo()
}
onReleased:
{
fondUndo.opacity = 1
}
}
Button {
width: 80
height: 30
x: qmlMap.width-width-20-buttonUndo.width
y: 10
id : buttonRedo
font.pointSize: 16;
background: Rectangle {
id : fondRedo;
radius: 5
}
property bool buttonvalue : true;
//color:"yellow"
visible: true
text: "<"
flat : false
onPressed: {
fondRedo.opacity = .80
undo()
}
onReleased:
{
fondRedo.opacity = 1
}
}
}
Point {
id: helper
x : 0
y : 0
spatialReference: SpatialReference {wkid: 4326}
}
PolygonBuilder {
id: polygon_contour
spatialReference: SpatialReference {wkid: 4326}
}
PolygonBuilder {
id: polygon_buffer
spatialReference: SpatialReference {wkid: 4326}
}
SimpleFillSymbol {
id: polygon_fill_symbol_buffer_contour
style: Enums.SimpleFillSymbolStyleNull
color: "yellow"
SimpleLineSymbol {
style: Enums.SimpleLineSymbolStyleSolid
color: "red"
width: 1
antiAlias: true
}
}
SimpleFillSymbol {
id: polygon_fill_symbol_buffer
style: Enums.SimpleFillSymbolStyleNull
color: "yellow"
SimpleLineSymbol {
style: Enums.SimpleLineSymbolStyleSolid
color: "blue"
width: 1
antiAlias: true
}
}
SimpleLineSymbol {
id: line_symbol_path
style: Enums.SimpleLineSymbolStyleSolid
color: "yellow"
width: 4
antiAlias: true
}
PictureMarkerSymbol {
id : pictureMarkerSymbolBorder
url : "../ressource/marqueur_rouge.png"
width : 60
height : 60
}
PictureMarkerSymbol {
id : pictureMarkerSymbolBuffer
url : "../ressource/marqueur_bleu.png"
width : 60
height : 60
}
PictureMarkerSymbol {
id : pictureMarkerSymbolStarter
url : "../ressource/marqueur_jaune.png"
width : 20
height : 20
}
PointBuilder {
id: ptBuilder
spatialReference: SpatialReference { wkid: 4326 }
}
function createGraphic(geometry, symbol) {
console.log("create graphic debut")
//I suppose, the line create the crash (beacause ofen the crash, the line "create graphic debut" it's display
const graphic = ArcGISRuntimeEnvironment.createObject("Graphic");
console.log("1")
graphic.geometry = geometry;
console.log("2")
graphic.symbol = symbol;
console.log("create graphic fin")
return graphic;
}
function reset()
{
console.log("reset")
map.changer = false;
map.animer=false;
animation.running=false
}
function viderPoint (changeParcelle)
{
console.log("vider")
graphicsOverlay.graphics.clear()
if (map.polygon_buffer && map.polygon_contour)
{
map.polygon_buffer.destroy()
map.polygon_contour.destroy()
}
map.listPolygonContour = [];
map.listPolyline = []
map.polygon_contour = Qt.createQmlObject('
import QtQuick 2.0
import QtQuick.Window 2.0
import QtQuick.Controls 2.2
import QtPositioning 5.12
import QtLocation 5.12
import Esri.ArcGISRuntime 100.14
PolygonBuilder {
id: polygon_contour_1
spatialReference: SpatialReference {wkid: 4326}
}',qmlMap)
//console.log(map.polygon_contour)
map.polygon_buffer = Qt.createQmlObject('
import QtQuick 2.0
import QtQuick.Window 2.0
import QtQuick.Controls 2.2
import QtPositioning 5.12
import QtLocation 5.12
import Esri.ArcGISRuntime 100.14
PolygonBuilder {
id: polygon_contour_2
spatialReference: SpatialReference {wkid: 4326}
}',qmlMap, "dynamicSnippet1" );
if (changeParcelle)
{
map.changer = false;
ptBuilder.setXY(2.3522219,48.856614);
//ptBuilder.setXY(0,0);
map.setViewpointCenterAndScale(ptBuilder.geometry, 50000000.0);
}
}
function modifPoint(lat,log)
{
console.log("modif pooint")
console.log("change : " + lat +" "+ log)
animation.running=false
map.changer = false
/*map.mapItems[map.item-1].opacity= 1
map.mapItems[map.item-1].coordinate = QtPositioning.coordinate(lat, log)*/
}
function addPointParcelle(lat, log,val)
{
console.log("debut add parcelle")
if (map.polygon_contour_obj)
{
var index = graphicsOverlay.graphics.indexOf(map.polygon_contour_obj);
if (index !== -1)
{
graphicsOverlay.graphics.removeOne(map.polygon_contour_obj)
}
}
map.polygon_contour.addPointXY(log,lat);
map.polygon_contour_obj = createGraphic(map.polygon_contour.geometry, polygon_fill_symbol_buffer_contour);
graphicsOverlay.graphics.append(map.polygon_contour_obj);
//lat = lat +projectedPoint.y
var marqueuradd = Qt.createQmlObject('
import QtQuick 2.0
import QtQuick.Window 2.0
import QtQuick.Controls 2.2
import QtPositioning 5.12
import QtLocation 5.12
import Esri.ArcGISRuntime 100.14
Point {
id: point_add
x: '+log+'
y: '+lat+'
spatialReference: SpatialReference {wkid: 4326}
}',qmlMap)
var point_graphic = createGraphic(marqueuradd, pictureMarkerSymbolBorder);
graphicsOverlay.graphics.append(point_graphic);
map.listPolygonContour.push([log,lat,point_graphic])
map.tot = map.tot + 1
console.log("fin add parcelle")
}
function addPointParcelleBufferiser(lat, log)
{
console.log("debut add buffer")
if (map.polygon_buffer_obj)
{
var index = graphicsOverlay.graphics.indexOf(map.polygon_buffer_obj);
if (index !== -1)
{
graphicsOverlay.graphics.removeOne(map.polygon_buffer_obj)
}
}
map.polygon_buffer.addPointXY(log,lat);
map.polygon_buffer_obj = createGraphic(map.polygon_buffer.geometry, polygon_fill_symbol_buffer);
graphicsOverlay.graphics.append(map.polygon_buffer_obj);
//polygoneBufferiser.addCoordinate(QtPositioning.coordinate(lat,log))
//map.addMapItem(polygoneBufferiser)
var marqueuradd = Qt.createQmlObject('
import QtQuick 2.0
import QtQuick.Window 2.0
import QtQuick.Controls 2.2
import QtPositioning 5.12
import QtLocation 5.12
import Esri.ArcGISRuntime 100.14
Point {
id: point_add'+map.tot+'
x: '+log+'
y: '+lat+'
spatialReference: SpatialReference {wkid: 4326}
}',qmlMap)
var point_graphic = createGraphic(marqueuradd, pictureMarkerSymbolBuffer);
graphicsOverlay.graphics.append(point_graphic);
map.tot = map.tot + 1
console.log("fin add buffer")
}
function setCenter(lat,log)
{
console.log("cset center")
map.changer = false;
ptBuilder.setXY(lat, log);
map.setViewpointCenterAndScale(ptBuilder.geometry, 10000.0);
}
function clearParcours()
{
console.log("clear parcours")
while (map.listPolyline.length > 0)
{
var elem = map.listPolyline.pop()
graphicsOverlay.graphics.removeOne(elem)
}
}
function addLine (lat1,log1, lat2,log2)
{
console.log("add line")
//console.log("ok");
console.log ("lat1 : " + lat1 +", log 1 : "+ log1 + ", lat2 : "+lat2 + ",log 2 : " + log2);
if(map.tot > 9)
{
map.tot = 0;
}
else
{
map.tot++;
}
const line = {"paths":[[[log1,lat1],[log2,lat2]]],"spatialReference":{"wkid":4326}}
const line1 = ArcGISRuntimeEnvironment.createObject("Polyline", {"json": line });
const line_graphic = createGraphic(line1, line_symbol_path);
console.log(line_graphic)
map.listPolyline.push(line_graphic)
graphicsOverlay.graphics.append(line_graphic);
}
function faireClignoterPoint(lat,log)
{
console.log("cligbotter")
console.log(" rechercher : lat " + lat + "log " + log);
map.item = 0;
var trouver = false
while (map.listPolygonContour.length > map.item && !trouver)
{
console.log("lat " + map.listPolygonContour[map.item][0] + "log " + map.listPolygonContour[map.item][1]);
//console.log("val : "+ map.mapItems[i].coordinate.latitude + ' ' + map.mapItems[i].coordinate.longitude );
if (map.listPolygonContour[map.item][1] === lat && map.listPolygonContour[map.item ][0] === log)
{
console.log("trouver",map.listPolygonContour[map.item][2])
trouver = true;
map.changer = true;
console.log(map.listPolygonContour[map.item][2].visible )
//map.polygon_contour_obj[0].opacity = 2
animation1.target = map.listPolygonContour[map.item][2];
animation2.target = map.listPolygonContour[map.item][2];
animation3.target = map.listPolygonContour[map.item][2];
animation4.target = map.listPolygonContour[map.item][2];
//console.log("activer suite");
animation.running=false
animation.running=true
// console.log("activer fin");
}
else
{
map.changer = false;
}
map.item = map.item + 1;
}
}
function pointDebut(lat,log)
{
console.log("point debut")
var marqueuradd = Qt.createQmlObject('
import QtQuick 2.0
import QtQuick.Window 2.0
import QtQuick.Controls 2.2
import QtPositioning 5.12
import QtLocation 5.12
import Esri.ArcGISRuntime 100.14
Point {
id: point_add
x: '+log+'
y: '+lat+'
spatialReference: SpatialReference {wkid: 4326}
}',qmlMap)
var point_graphic = createGraphic(marqueuradd, pictureMarkerSymbolStarter);
graphicsOverlay.graphics.append(point_graphic);
}
function afficherPointDebut(lat,log)
{
console.log("cpoint debut bis")
var marqueuradd = Qt.createQmlObject('
import QtQuick 2.0
import QtQuick.Window 2.0
import QtQuick.Controls 2.2
import QtPositioning 5.12
import QtLocation 5.12
import Esri.ArcGISRuntime 100.14
Point {
id: point_add
x: '+log+'
y: '+lat+'
spatialReference: SpatialReference {wkid: 4326}
}',qmlMap)
var point_graphic = createGraphic(marqueuradd, pictureMarkerSymbolStarter);
graphicsOverlay.graphics.append(point_graphic);
}
function subButton()
{
console.log("sub bouton")
buttonRedo.destroy();
buttonUndo.destroy();
}
SequentialAnimation{
id: animation
running: false
loops: Animation.Infinite
PropertyAnimation {
id: animation1
//target: rect
to:0
properties: "visible"
duration: 100
}
PropertyAnimation {
id: animation2
//target: rect
to:0
properties: "visible"
duration: 300
}
PropertyAnimation {
id: animation3
//target: rect
to:1
properties: "visible"
duration: 100
}
PropertyAnimation {
id: animation4
//target: rect
to:1
properties: "visible"
duration: 300
}
}
}