// Copyright 2016 ESRI // // All rights reserved under the copyright laws of the United States // and applicable international laws, treaties, and conventions. // // You may freely redistribute and use this sample code, with or // without modification, provided you include the original copyright // notice and use restrictions. // // See the Sample code usage restrictions document for further information. // #ifdef PCH_BUILD #include "pch.hpp" #endif // PCH_BUILD #include "DisplayMap.h" #include "ArcGISRuntimeEnvironment.h" #include "Basemap.h" #include "Map.h" #include "MapGraphicsView.h" #include "GraphicsOverlay.h" #include "PolylineBuilder.h" #include "PolygonBuilder.h" #include "SimpleMarkerSymbol.h" #include "SimpleFillSymbol.h" #include "PictureMarkerSymbol.h" #include "ServiceFeatureTable.h" #include "FeatureLayer.h" #include "AuthenticationManager.h" #include "Credential.h" #include "CredentialCache.h" #include "Portal.h" #include "PortalUser.h" #include using namespace Esri::ArcGISRuntime; DisplayMap::DisplayMap(QWidget *parent /*=nullptr*/): QMainWindow(parent), m_map(nullptr), m_mapView(nullptr), overlay(nullptr) //Opción4: // m_credential(new Credential(OAuthClientInfo("iLkGIj0nX8A4EJda", OAuthMode::User), this)), // m_portal(new Portal(m_credential, this)) { // Note: it is not best practice to store API keys in source code. The API key is referenced here for the convenience of this tutorial. // const QString api_key = QStringLiteral("AAPK0bf731f0382a4d768e39c275175fc557ljd9nlp97JPh4Po-ucCsJ08lAqg0Hx92BhjVjgNjaWazJpVErpxpwJVoAJhxZFB_"); // ArcGISRuntimeEnvironment::setApiKey(api_key); // Create the Widget view m_mapView = new MapGraphicsView(this); m_mapView->setWrapAroundMode(WrapAroundMode::Disabled); //Create Graphic Overlay overlay = new GraphicsOverlay(this); //** opción 1: ver mapa web según ejemplo -> https://developers.arcgis.com/qt/maps-2d/tutorials/display-a-web-map/ //Mapa público de ArcGIS // const QString item_id("392451c381ad4109bf04f7bd442bc038"); // //Mapa privado de TMR const QString item_id("26c05778806b435283c9787079b96b51"); // //Otros // const QString item_id("01f052c8995e4b9e889d73c3e210ebe3"); // const QString item_id("92ad152b9da94dee89b9e387dfe21acd"); // const QString item_id("41281c51f9de45edaf1c8ed44bb10e30"); // const QString item_id("71acbc5be2de4d5cb90882d33c6f6690"); // const QUrl portal_url(QString("https://arcgis.com/sharing/rest/content/items/" + item_id)); // m_map = new Map(portal_url, this); //---------------------------------------------------------------------- //** opción 2: ver mapa base sin información. //** usar de ejemplo -> https://developers.arcgis.com/documentation/mapping-apis-and-services/maps/maps-2d/ // Create a map using the streets BaseMap //m_map = new Map(Basemap::streets(this), this); //----------------------------------------------------------------------- //Opción 3: ver mapa web usando un portal configurado como //https://developers.arcgis.com/qt/arcgis-organization-portals/ Credential* ucPortal = new Credential("MyUser","MyPass", parent); Portal* myPortal = new Portal(QUrl("https://timerdeveloper.maps.arcgis.com"), ucPortal, parent); connect(myPortal, &Portal::doneLoading, this, [](Esri::ArcGISRuntime::Error loadError) { if (!loadError.isEmpty()) qDebug() << loadError.message(); }); myPortal->load(); PortalItem* portalItem = new PortalItem(myPortal, item_id, parent); connect(portalItem, &PortalItem::doneLoading, this, [portalItem](){ qDebug() << "Item title:" << portalItem->title(); }); portalItem->load(); m_map = new Map(portalItem, this); //------------------------------------------------------------------------ //Opción 4: Acceder al portal usando OAuth2.0 segun el ejemplo: // https://developers.arcgis.com/qt/cpp/sample-code/access-portal-user-info/ // connect(m_portal, &Portal::loadStatusChanged, this, &DisplayMap::onPortalLoadStatusChanged); // connect(m_portal, &Portal::doneLoading, this, &DisplayMap::loadErrorMessageChanged); // emit authManagerChanged(); // AuthenticationManager::instance()->setCredentialCacheEnabled(false); // const QString item_id("26c05778806b435283c9787079b96b51"); // PortalItem* portalItem = new PortalItem(m_portal, item_id, parent); // connect(portalItem, &PortalItem::doneLoading, this, [portalItem](){ // qDebug() << "Item title:" << portalItem->title(); // }); // portalItem->load(); // m_map = new Map(portalItem, this); // Set map to map view m_mapView->setMap(m_map); // #24: cuadre en Santiago de Chile inicialmente el map_view // const Point santiago_centro(-70.66259500484787, -33.45766421133760, SpatialReference(4326)); // m_mapView->setViewpointCenter(santiago_centro); // //#27 Visualizar Feature Layer propia. // const QUrl pointFeatureUrl("https://services3.arcgis.com/KhES5E3UMlWuLtRE/arcgis/rest/services/conversiones_por_ciudades_top_10_paises_3/FeatureServer/0"); // ServiceFeatureTable* point_feature_table= new ServiceFeatureTable(pointFeatureUrl, this); // FeatureLayer* point_feature_layer = new FeatureLayer(point_feature_table, this); // m_map->operationalLayers()->append(point_feature_layer); // Ya está añadido en el contructor de la clase DisplayMap // GraphicsOverlay* overlay = new GraphicsOverlay(this); // set the mapView as the central widget setCentralWidget(m_mapView); } // destructor DisplayMap::~DisplayMap() { } //void DisplayMap::init() //{ // qmlRegisterUncreatableType("Esri.TestNamespace", 1, 0, "AuthenticationManager", "AuthenticationManager is uncreateable"); //} //AutenticationManager *DisplayMap::authManager() const //{ // return AuthenticationManager::instance(); //} void DisplayMap::drawPoint(double latitude, double longitude){ //Graphics for drawPoint function // GraphicsOverlay* overlay = new GraphicsOverlay(this); // Create a point const Point dume_beach(longitude, latitude, SpatialReference::wgs84()); // Create symbols for the point SimpleLineSymbol* point_outline = new SimpleLineSymbol(SimpleLineSymbolStyle::Solid, QColor(Qt::yellow), 2, this); SimpleMarkerSymbol* point_symbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle::Circle, QColor(Qt::red), 5, this); point_symbol->setOutline(point_outline); // Create a graphic to display the point with its symbology Graphic* point_graphic = new Graphic(dume_beach, point_symbol, this); // Add point graphic to the graphics overlay overlay->graphics()->append(point_graphic); // drawPoint(overlay,-33.45766421133769,-70.66259500484787); m_mapView->graphicsOverlays()->append(overlay); } void DisplayMap::drawLine(double coordinates[14]){ // Create a line PolylineBuilder* polyline_builder = new PolylineBuilder(SpatialReference::wgs84(), this); int arrSize = sizeof(coordinates)/sizeof(coordinates[0]); for(int i = 0; i < 14; i = i+2){ double latitude = coordinates[i+1]; double longitude = coordinates[i]; polyline_builder->addPoint(latitude, longitude); } // Create a symbol for the line SimpleLineSymbol* line_symbol = new SimpleLineSymbol(SimpleLineSymbolStyle::Solid, QColor(Qt::red), 3, this); // Create a graphic to display the line with its symbology Graphic* polyline_graphic = new Graphic(polyline_builder->toGeometry(), line_symbol, this); // Add line graphic to the graphics overlay overlay->graphics()->append(polyline_graphic); } void DisplayMap::putWarningImg(double latitude, double longitude,float size){ // create a blue symbol from a local resource PictureMarkerSymbol* image = new PictureMarkerSymbol(QUrl("C:/Users/marce/Desktop/TMR_AMC/tmr_desktop/imagenes/warning.png"), this); image->setWidth(size); image->setHeight(size); Point SymbolPoint(longitude,latitude, SpatialReference::wgs84()); // create graphic Graphic* graphic = new Graphic(SymbolPoint, image, this); // append to graphicsoverlay overlay->graphics()->append(graphic); // add GraphicsOverlay to MapView m_mapView->graphicsOverlays()->append(overlay); }