지도 표시
이 장은 지도 위에 축척 막대와 나침반을 켜고 끄는 방법을 설명합니다. 둘은 엔진 지도 뷰의 오버레이 컨트롤입니다. 지도 내용이 아니라 화면에 고정된 장식이고, 지도에 속하므로 워크스페이스 파일에 함께 저장됩니다.
켜고 끄기
glsGdkQt의 문서화된 범위에는 이 기능을 감싼 함수가 없습니다. 세션에서 엔진 지도 뷰를 빌려 엔진 API를 직접 부릅니다. mapView()가 돌려주는 포인터는 세션의 것이므로 해제하지 않습니다.
bool MapHostWindow::toggleScaleBar(QString* error)
{
// The scale bar is an overlay control of the engine map view. The session lends the view;
// the control belongs to the map, so a workspace file keeps it.
GDK::glsMapView* view = m_session->mapView();
if (!view) {
*error = QStringLiteral("The session has no map view.");
return false;
}
const GDK::glsOverlayLayout layout;
const GDK::glsStatus status = m_scaleBarShown
? view->RemoveOverlayCtrl(kScaleBarId)
: view->AddScaleBarOverlayCtrl(kScaleBarId, &layout);
if (!status.IsOk()) {
*error = GdkQt::GdkSession::statusMessage(status, QStringLiteral("Scale bar"));
return false;
}
m_scaleBarShown = !m_scaleBarShown;
m_mapWidget->refreshAfterViewChanged();
return true;
}
void MapHostWindow::addMapDisplayActions(QToolBar* toolBar)
{
auto* scaleBar = toolBar->addAction(QStringLiteral("Scale bar"));
connect(scaleBar, &QAction::triggered, this, [this] {
QString error;
if (!toggleScaleBar(&error)) {
statusBar()->showMessage(error);
}
});
}
AddScaleBarOverlayCtrl과 RemoveOverlayCtrl은 엔진의 상태(glsStatus)를 돌려줍니다. 나침반은 AddCompassOverlayCtrl입니다.
컨트롤의 ID
오버레이 컨트롤은 문자열 ID로 구분합니다. C#의 MapDisplay는 축척 막대에 qt.scaleBar, 나침반에 qt.compass를 씁니다(MapDisplayController.ScaleBarId, CompassId). Qt에서 같은 ID를 쓰면, 한쪽에서 저장한 워크스페이스를 다른 쪽에서 열어도 같은 컨트롤로 인식합니다. Qt 예제가 qt.scaleBar를 쓰는 것이 그 때문입니다.
모양, 위치, 글꼴 같은 세부 설정은 엔진의 오버레이 컨트롤 API입니다. 엔진 가이드 7장의 "더 알아보기"에서 시작하십시오.
이 가이드가 아직 다루지 않는 것
스타일 편집 컨트롤, 레이어 속성 창, 피처 정보 패널, SQL 콘솔은 이 가이드에 아직 없습니다. 형식별 계약은 레퍼런스에서 찾습니다.