qt環境下Mapx組建的編程---------regoin


#include "widget.h"
#include "ui_widget.h"

#include <QPushButton>
#include <QToolBar>
Widget::Widget(QWidget *parent) :
    QWidget(parent),
    map(nullptr),
    pCMapXPoint(nullptr),pCMapXPoint1(nullptr),pCMapXPoint2(nullptr),
    pCMapFeaFactory(nullptr),
    pCMapXFeature(nullptr),
    pCMapStyle(nullptr),
    pCMapLayers(nullptr),
    pCMapLayer(nullptr),

    pCMapLine(nullptr),
    pCMapPoints(nullptr),
    pCMapParts(nullptr),

    pCMapArc(nullptr),

    pCMapXFeatureRegoin(nullptr),
    //坐標的變化
    pCMapXCoordSys(nullptr),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
    this->resize(1000,800);

    QPushButton *pButton = new QPushButton("tool",this);
    pButton->resize(70,23);

    //建立一個地圖
    map = new MapSpace::Map("",this);
    //設置大小屬性
    map->move(QPoint(10,25));
    map->resize(QSize(size().width()-20,size().height()-20));

    map->SetCurrentTool(MapSpace::ToolConstants::miPanTool);//鼠標工具
    map->setProperty("MousewheelSupport",2);//支持滾輪
 /* 顯示一個小圖標(旗子模樣)*/
    pCMapLayers = map->Layers();
    pCMapLayers->AddGeoSetLayers("C:/mapx/MapX4/Maps/Captial.gst");
    pCMapLayer = pCMapLayers->CreateLayer("test");


    pCMapFeaFactory = map->FeatureFactory();



    //划一個區域。regoin
    pCMapXFeatureRegoin = pCMapFeaFactory->CreateRegion();//創建一個區域feature
    pCMapPoints = new MapSpace::CMapXPoints;
    pCMapPoints->setControl("MapX.Points.4");
    pCMapParts = pCMapXFeatureRegoin->Parts();
    pCMapXPoint = pCMapPoints->AddXY(120.07372, 29.35792);
    pCMapXPoint1 = pCMapPoints->AddXY(120.07270, 29.35780);
    pCMapXPoint2 = pCMapPoints->AddXY(120.07000, 29.35000);

    pCMapStyle = pCMapXFeatureRegoin->Style();
    //pCMapStyle->setControl("Mapx.Style.4");
    //pCMapStyle->SetRegionBackColor(200);
    //pCMapStyle->SetLineColor(117);
    pCMapStyle->SetRegionBorderWidthUnit(MapSpace::StyleUnitConstants::miStyleUnitTenthsOfPoint);
    pCMapStyle->SetRegionBorderWidth(35);//邊界線條寬度,與上方函數一起使用
    pCMapStyle->SetRegionBorderColor(243);//邊界顏色
    pCMapStyle->SetRegionColor(123);//背景顏色
   // pCMapStyle->SetRegionStyle(MapSpace::miPenSolid);
    pCMapStyle->SetRegionPattern(MapSpace::miPatternCross);
    //pCMapStyle->SetRegionTransparent(true);//用於至少兩個圖元之間

    pCMapParts->Add(pCMapPoints->asVariant().value<IDispatch*>());
    pCMapLayer->AddFeature(pCMapXFeatureRegoin->asVariant().value<IDispatch*>());
    map->ZoomTo(200,120.06272, 29.35522);
}
在加上圓形的圖元
 1 void MainWindow::CMapxInit(){
 2     widget = new QAxWidget(this);
 3     widget->setControl(QString::fromUtf8("{9D6ED188-5910-11D2-98A6-00A0C9742CCA}"));
 4     widget->resize(size().width(),size().height());
 5 
 6     pCMapX = new CMapX(widget->asVariant().value<IDispatch*>());
 7     pCMapXLayer = pCMapX->Layers()->CreateLayer("aaa");
 8 
 9     pCMapXFeatureFactory = pCMapX->FeatureFactory();
10     pCMapXFeaturePoint = pCMapXFeatureFactory->CreateSymbol();
11 
12     pCMapXPoint = pCMapXFeaturePoint->Point();
13     pCMapXPoint->Set(120.06872,29.35692);
14     //算出外接矩形的兩個角坐標,一個在X軸上,一個在Y軸上
15 
16     pCMapXFeatureCircularRegion = pCMapXFeatureFactory->CreateCircularRegion(miCircleTypeMap,pCMapXPoint->asVariant().value<IDispatch*>(),1,0,1000);
17     pStyle =  pCMapXFeatureCircularRegion->Style();
18     pStyle->SetRegionColor(QColor(255,0,0));
19 
20     pCMapXLayer->AddFeature(pCMapXFeatureCircularRegion->asVariant().value<IDispatch*>());
21 
22     pCMapX->ZoomTo(10,120.06872,29.35692);
23 }
 
        

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM