地图初步可以显示
This commit is contained in:
@@ -1 +1,2 @@
|
||||
/.idea
|
||||
|
||||
|
||||
+4
-3
@@ -8,15 +8,16 @@ if (${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_LIST_DIR})
|
||||
include(third_party/build_infra/start.cmake)
|
||||
|
||||
|
||||
set(test_maplibre_rely QMapLibre_qt_5_15_2)
|
||||
library_is_installed_with_rely(global ok ${test_maplibre_rely})
|
||||
set(test_maplibre_rely global::QMapLibre_qt_5_15_2)
|
||||
library_is_installed_with_rely(ok ${test_maplibre_rely})
|
||||
if (${ok})
|
||||
include(${CMAKE_SOURCE_DIR}/main.cmake)
|
||||
else ()
|
||||
message("test_maplibre 依赖未安装! 请运行 test_maplibre_env 目标安装所需第三方依赖")
|
||||
endif ()
|
||||
rcl_add_dependency_action_targets("test_maplibre_env" ${test_maplibre_rely})
|
||||
include(third_party/build_infra/end.cmake)
|
||||
rcl_add_dependency_action_targets("test_maplibre_env" ${test_maplibre_rely})
|
||||
|
||||
else ()
|
||||
endif ()
|
||||
|
||||
|
||||
+36
-23
@@ -1,29 +1,42 @@
|
||||
set(dir ${CMAKE_CURRENT_LIST_DIR}/src)
|
||||
|
||||
|
||||
|
||||
block()
|
||||
find_package(Qt5 REQUIRED COMPONENTS Widgets)
|
||||
find_package(QMapLibre COMPONENTS Widgets REQUIRED)
|
||||
set(dir module/test_maplibre)
|
||||
file(GLOB_RECURSE srcs ${dir}/*.qrc ${dir}/*.c ${dir}/*.h ${dir}/*.cpp ${dir}/*.hpp)
|
||||
add_executable(test_maplibre ${srcs})
|
||||
target_link_libraries(test_maplibre PRIVATE Qt5::Widgets QMapLibre::Widgets)
|
||||
target_compile_definitions(test_maplibre PRIVATE QT_MAPLIBRE_STATIC)
|
||||
target_compile_definitions(test_maplibre PRIVATE QT_MAPLIBRE_STATIC WIN32_LEAN_AND_MEAN NOMINMAX)
|
||||
if(WIN32)
|
||||
target_link_libraries(test_maplibre PRIVATE ws2_32)
|
||||
endif()
|
||||
if(MSVC)
|
||||
target_compile_options(test_maplibre PRIVATE /utf-8)
|
||||
endif()
|
||||
set_property(TARGET test_maplibre PROPERTY AUTOMOC ON)
|
||||
set_property(TARGET test_maplibre PROPERTY AUTOUIC ON)
|
||||
set_property(TARGET test_maplibre PROPERTY AUTORCC ON)
|
||||
endblock()
|
||||
|
||||
|
||||
|
||||
|
||||
find_package(Qt5 REQUIRED COMPONENTS Widgets)
|
||||
find_package(QMapLibre COMPONENTS Widgets REQUIRED)
|
||||
|
||||
#set(osgEarth_DIR "D:/ae/cached_external_library/vs2019_Debug_global/install/osgearth/lib/cmake/osgearth")
|
||||
|
||||
file(GLOB_RECURSE srcs ${dir}/*.qrc ${dir}/*.c ${dir}/*.h ${dir}/*.cpp ${dir}/*.hpp)
|
||||
add_executable(test_maplibre ${srcs})
|
||||
target_link_libraries(test_maplibre PRIVATE Qt5::Widgets QMapLibre::Widgets)
|
||||
|
||||
|
||||
target_compile_definitions(test_maplibre PRIVATE QT_MAPLIBRE_STATIC)
|
||||
|
||||
|
||||
target_compile_definitions(test_maplibre PRIVATE QT_MAPLIBRE_STATIC WIN32_LEAN_AND_MEAN NOMINMAX)
|
||||
if(WIN32)
|
||||
target_link_libraries(test_maplibre PRIVATE ws2_32)
|
||||
endif()
|
||||
if(MSVC)
|
||||
target_compile_options(test_maplibre PRIVATE /utf-8)
|
||||
endif()
|
||||
|
||||
|
||||
set_property(TARGET test_maplibre PROPERTY AUTOMOC ON)
|
||||
set_property(TARGET test_maplibre PROPERTY AUTOUIC ON)
|
||||
set_property(TARGET test_maplibre PROPERTY AUTORCC ON)
|
||||
block()
|
||||
set(rely osgearth)
|
||||
rcl_load_dependency_environment(osg_earth ${rely})
|
||||
set(dir module/test_osg_earth)
|
||||
file(GLOB_RECURSE srcs ${dir}/*.qrc ${dir}/*.c ${dir}/*.h ${dir}/*.cpp ${dir}/*.hpp)
|
||||
add_executable(test_osg_earth ${srcs})
|
||||
find_package(osgEarth CONFIG REQUIRED)
|
||||
target_link_libraries(test_osg_earth PRIVATE osgEarth::osgEarth)
|
||||
if(MSVC)
|
||||
target_compile_options(test_osg_earth PRIVATE /utf-8)
|
||||
endif()
|
||||
rcl_unload_dependency_environment(osg_earth ${rely})
|
||||
endblock()
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
$env:OSGEARTH_HTTP_DEBUG = "1"
|
||||
$env:OSGEARTH_CACHE_DEBUG = "1"
|
||||
|
||||
|
||||
$base = "D:\ae\cached_external_library\vs2019_Debug_osg_earth\install"
|
||||
|
||||
$osgearth_bin = "$base\osgearth\bin"
|
||||
$osgearth_plugin = "$base\osgearth\bin\osgPlugins-3.6.5"
|
||||
$osg_bin = "$base\openscenegraph\bin"
|
||||
$gdal_bin = "$base\gdal\bin"
|
||||
$curl_bin = "$base\curl\bin"
|
||||
$proj_bin = "$base\proj\bin"
|
||||
$zlib_bin = "$base\zlib\bin"
|
||||
$geos_bin = "$base\geos\bin"
|
||||
$jpeg_bin = "$base\jpeg\bin"
|
||||
$tiff_bin = "$base\tiff\bin"
|
||||
$png_bin = "$base\png\bin"
|
||||
|
||||
$env:Path = "$png_bin;$tiff_bin;$jpeg_bin;$geos_bin;$zlib_bin;$proj_bin;$curl_bin;$gdal_bin;$osgearth_bin;$osg_bin;$env:Path"
|
||||
@@ -0,0 +1,4 @@
|
||||
|
||||
$bin1 = "D:\ae\cached_external_library\vs2019_Debug_global\install\QMapLibre_qt_5_15_2\bin"
|
||||
|
||||
$env:Path = "$bin1"
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,164 @@
|
||||
#include <cstddef>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <osg/ArgumentParser>
|
||||
#include <osg/Notify>
|
||||
#include <osgDB/FileUtils>
|
||||
#include <osgDB/Registry>
|
||||
#include <osgViewer/Viewer>
|
||||
#include <osgEarth/Controls>
|
||||
#include <osgEarth/EarthManipulator>
|
||||
#include <osgEarth/GLUtils>
|
||||
#include <osgEarth/MapNode>
|
||||
#include <osgEarth/Viewpoint>
|
||||
#include <osgEarth/XYZ>
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
namespace ui = osgEarth::Util::Controls;
|
||||
struct Tile_Source {
|
||||
std::string name;
|
||||
std::string url;
|
||||
};
|
||||
class Tile_Source_Controller {
|
||||
public:
|
||||
explicit Tile_Source_Controller(osgEarth::Map* map) : map_(map) {}
|
||||
void add_source(Tile_Source source, bool visible) {
|
||||
osg::ref_ptr<osgEarth::XYZImageLayer> layer = new osgEarth::XYZImageLayer();
|
||||
layer->setName(source.name);
|
||||
layer->setURL(source.url);
|
||||
layer->setProfile(osgEarth::Profile::create(osgEarth::Profile::SPHERICAL_MERCATOR));
|
||||
layer->setVisible(visible);
|
||||
map_->addLayer(layer.get());
|
||||
sources_.emplace_back(std::move(source));
|
||||
layers_.emplace_back(std::move(layer));
|
||||
}
|
||||
void select(std::size_t index) {
|
||||
for (std::size_t i = 0; i < layers_.size(); ++i) {
|
||||
layers_[i]->setVisible(i == index);
|
||||
}
|
||||
status_->setText(std::string("Current: ") + sources_[index].name);
|
||||
}
|
||||
void set_status(ui::LabelControl* status) {
|
||||
status_ = status;
|
||||
}
|
||||
[[nodiscard]] std::size_t size() const {
|
||||
return sources_.size();
|
||||
}
|
||||
[[nodiscard]] const std::string& name(std::size_t index) const {
|
||||
return sources_[index].name;
|
||||
}
|
||||
private:
|
||||
osgEarth::Map* map_;
|
||||
std::vector<Tile_Source> sources_;
|
||||
std::vector<osg::ref_ptr<osgEarth::XYZImageLayer>> layers_;
|
||||
ui::LabelControl* status_;
|
||||
};
|
||||
class Select_Tile_Source_Handler : public ui::ControlEventHandler {
|
||||
public:
|
||||
Select_Tile_Source_Handler(Tile_Source_Controller& controller, std::size_t index)
|
||||
: controller_(controller), index_(index) {}
|
||||
void onClick(ui::Control*) {
|
||||
controller_.select(index_);
|
||||
}
|
||||
private:
|
||||
Tile_Source_Controller& controller_;
|
||||
std::size_t index_;
|
||||
};
|
||||
ui::Control* create_tile_source_panel(Tile_Source_Controller& controller) {
|
||||
auto* grid = new ui::Grid();
|
||||
grid->setBackColor(0.0f, 0.0f, 0.0f, 0.72f);
|
||||
grid->setPadding(10.0f);
|
||||
grid->setChildSpacing(6.0f);
|
||||
grid->setAbsorbEvents(true);
|
||||
unsigned int row = 0;
|
||||
grid->setControl(0, row++, new ui::LabelControl("Tile source"));
|
||||
for (std::size_t i = 0; i < controller.size(); ++i) {
|
||||
auto* button = grid->setControl(
|
||||
0,
|
||||
row++,
|
||||
new ui::ButtonControl(
|
||||
controller.name(i),
|
||||
new Select_Tile_Source_Handler(controller, i)
|
||||
)
|
||||
);
|
||||
button->setHorizFill(true, 220.0f);
|
||||
}
|
||||
auto* status = grid->setControl(
|
||||
0,
|
||||
row,
|
||||
new ui::LabelControl("Current: OpenStreetMap")
|
||||
);
|
||||
controller.set_status(status);
|
||||
return grid;
|
||||
}
|
||||
int main(int argc, char** argv) {
|
||||
#ifdef _WIN32
|
||||
SetConsoleOutputCP(CP_UTF8);
|
||||
SetConsoleCP(CP_UTF8);
|
||||
#endif
|
||||
const std::string install_root =
|
||||
"D:/ae/cached_external_library/vs2019_Debug_osg_earth/install";
|
||||
osgDB::FilePathList plugin_paths{
|
||||
install_root + "/osgearth/bin/osgPlugins-3.6.5",
|
||||
install_root + "/openscenegraph/bin/osgPlugins-3.6.5"
|
||||
};
|
||||
auto* registry = osgDB::Registry::instance();
|
||||
registry->setLibraryFilePathList(plugin_paths);
|
||||
osg::setNotifyLevel(osg::NOTICE);
|
||||
if (registry->getReaderWriterForExtension("png") == nullptr) {
|
||||
std::cerr << "无法加载 OSG PNG 插件,请检查 osgdb_pngd.dll 和它依赖的 DLL\n";
|
||||
return 1;
|
||||
}
|
||||
osgEarth::initialize();
|
||||
osg::ArgumentParser args(&argc, argv);
|
||||
osg::ref_ptr<osgEarth::Map> map = new osgEarth::Map();
|
||||
Tile_Source_Controller tile_sources(map.get());
|
||||
tile_sources.add_source(
|
||||
{
|
||||
"OpenStreetMap",
|
||||
"https://tile.openstreetmap.org/{z}/{x}/{y}.png"
|
||||
},
|
||||
true
|
||||
);
|
||||
tile_sources.add_source(
|
||||
{
|
||||
"OpenTopoMap",
|
||||
"https://[abc].tile.opentopomap.org/{z}/{x}/{y}.png"
|
||||
},
|
||||
false
|
||||
);
|
||||
tile_sources.add_source(
|
||||
{
|
||||
"Esri World Imagery",
|
||||
"https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}"
|
||||
},
|
||||
false
|
||||
);
|
||||
osg::ref_ptr<osgEarth::MapNode> map_node = new osgEarth::MapNode(map.get());
|
||||
osgViewer::Viewer viewer(args);
|
||||
viewer.setUpViewInWindow(100, 100, 1280, 720);
|
||||
viewer.setRealizeOperation(new osgEarth::GL3RealizeOperation());
|
||||
viewer.getCamera()->setSmallFeatureCullingPixelSize(-1.0f);
|
||||
viewer.setSceneData(map_node.get());
|
||||
ui::ControlCanvas::getOrCreate(&viewer)->addControl(
|
||||
create_tile_source_panel(tile_sources)
|
||||
);
|
||||
osg::ref_ptr<osgEarth::EarthManipulator> manipulator =
|
||||
new osgEarth::EarthManipulator(args);
|
||||
viewer.setCameraManipulator(manipulator.get());
|
||||
manipulator->setViewpoint(
|
||||
osgEarth::Viewpoint(
|
||||
"Beijing",
|
||||
116.4074,
|
||||
39.9042,
|
||||
0.0,
|
||||
0.0,
|
||||
-90.0,
|
||||
1500000.0
|
||||
),
|
||||
0.0
|
||||
);
|
||||
return viewer.run();
|
||||
}
|
||||
Vendored
+1
@@ -26,3 +26,4 @@ fetch_repo() {
|
||||
|
||||
fetch_repo "$remote_root/ae/build_infra" "master" "third_party/build_infra"
|
||||
fetch_repo "$remote_root/ae/CPP_Core" "master" "third_party/CPP_Core"
|
||||
|
||||
|
||||
Vendored
-37
@@ -1,37 +0,0 @@
|
||||
$ErrorActionPreference = "Stop"
|
||||
$scriptDir = $PSScriptRoot
|
||||
if ( [string]::IsNullOrWhiteSpace($scriptDir))
|
||||
{
|
||||
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
}
|
||||
$root = (Resolve-Path -LiteralPath (Join-Path $scriptDir "..")).Path
|
||||
Set-Location -LiteralPath $root
|
||||
$origin = git remote get-url origin
|
||||
$origin = $origin.TrimEnd("/")
|
||||
$remoteRoot = $origin -replace "/[^/]+(\.git)?$", ""
|
||||
$remoteRoot = $remoteRoot -replace "/[^/]+$", ""
|
||||
echo "remoteRoot $remoteRoot"
|
||||
|
||||
function Fetch-Repo
|
||||
{
|
||||
param(
|
||||
[string]$Repo,
|
||||
[string]$Branch,
|
||||
[string]$Dir
|
||||
)
|
||||
if (Test-Path -LiteralPath $Dir -PathType Container)
|
||||
{
|
||||
git -C $Dir rev-parse --is-inside-work-tree *> $null
|
||||
git -C $Dir remote set-url origin $Repo
|
||||
git -C $Dir fetch origin $Branch
|
||||
git -C $Dir checkout $Branch
|
||||
git -C $Dir pull --ff-only origin $Branch
|
||||
}
|
||||
else
|
||||
{
|
||||
git clone --branch $Branch --single-branch $Repo $Dir
|
||||
}
|
||||
}
|
||||
|
||||
Fetch-Repo "$remoteRoot/ae/build_infra" -Branch "master" "third_party/build_infra"
|
||||
Fetch-Repo "$remoteRoot/ae/CPP_Core" -Branch "master" "third_party/CPP_Core"
|
||||
Reference in New Issue
Block a user