300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > qt quick-qml高德地图实现V1版本(跨平台支持 无需浏览器内核 运行迅速 下个版本实

qt quick-qml高德地图实现V1版本(跨平台支持 无需浏览器内核 运行迅速 下个版本实

时间:2020-09-20 20:41:08

相关推荐

qt quick-qml高德地图实现V1版本(跨平台支持 无需浏览器内核 运行迅速 下个版本实

1.效果图展示

gif如下所示(文件有点大,已压缩)

2.demo介绍

支持跨平台linux/windows等,qt插件方式,非浏览器加载支持缓存保存离线地图实现支持地图转向、旋转、方位调整等

缓存目录如下图所示,当有缓存时,则会获取该缓存目录,否则在线联网更新数据:

3.地图插件介绍

qml提供了四个内建的地图在线插件"esri"、"mapbox"、"nokia"、"osm",但是都不是国内地图,对国内很不友好,本章我们实现一个高德地图插件,我们以osm插件为例,如下所示:

{"Keys": ["osm"],"Provider": "osm","Version": 100,"Experimental": false,"Features": ["OnlineMappingFeature","OnlineGeocodingFeature","ReverseGeocodingFeature","OnlineRoutingFeature","OnlinePlacesFeature"]}

其中"Features"表示该插件支持的哪些特性,比如"OnlineMappingFeature"表示支持在线地图显示、则我们需要实现一个QGeoMappingManagerEngine引擎

每个引擎能支持的所有功能介绍如下所示:

QGeoRoutingManagerEngine

NoRoutingFeatures - Routing is not supported (KO: this option can be omitted)

OnlineRoutingFeature - Online routing support

OfflineRoutingFeature - Offline routing support

LocalizedRoutingFeature - Localized routing support

RouteUpdatesFeature - Support for dynamic path update

AlternativeRoutesFeature - Support for multiple alternative routes

ExcludeAreasRoutingFeature - Support for excluding routing factors

AnyRoutingFeatures - Supports anything your heart desires for routing

QGeoCodingManagerEngine

NoGeocodingFeatures - Geocoding is not supported

OnlineGeocodingFeature - Online geocoding support

OfflineGeocodingFeature - Offline geocoding support

ReverseGeocodingFeature - Reverse geocoding support

LocalizedGeocodingFeature - Localized geocoding support

AnyGeocodingFeatures - All of the above except NoGeocodingFeatures

QGeoMappingManagerEngine

NoMappingFeatures - No mapping supported

OnlineMappingFeature - Support for online maps

OfflineMappingFeature - Support for offline maps

LocalizedMappingFeature - Support for maps with localization

AnyMappingFeatures - All of the above except NoMappingFeatures

QPlaceManagerEngine

NoPlacesFeatures - Point-of-interest is not supported

OnlinePlacesFeature - Online Point-of-interest support

OfflinePlacesFeature - Offline Point-of-interest support

SavePlaceFeature - Support for saving custom points to the map

RemovePlaceFeature - Support for removing Point-of-interes on a map

SaveCategoryFeature - Create and save custom Point-of-interest categories

RemoveCategoryFeature - Remove Point-of-interest categories

PlaceRecommendationsFeature - Support for Recommended Point-of-interest according to keywords

SearchSuggestionsFeature - Suggestions support according to the search query part

LocalizedPlacesFeature - Localization support for Point-of-interes

NotificationsFeature - Support for Point-of-interes change notifications

PlaceMatchingFeature - Support for Point-of-interes comparison from two different providers

AnyPlacesFeatures - It's Time for You to Relax

4.QGeoServiceProviderFactory地图服务插件实现

实现一个QT地图服务插件,我们需要子类化QGeoServiceProviderFactory,以及实现 4个接口虚函数:

QGeoCodingManagerEngine* createGeocodingManagerEngine() : 位置搜索引擎,实现位置地理编码,比如配置文件有"OnlineGeocodingFeature"相关特性,则需要实现该虚函数QGeoMappingManagerEngine* createMappingManagerEngine() : 地图映射管理器引擎,实现地图显示,比如配置文件有"OnlineMappingFeature"相关特性,则需要实现该虚函数QGeoRoutingManagerEngine* createRoutingManagerEngine() : 路径规划引擎,实现路径规划,比如配置文件有"OnlineRoutingFeature"相关特性,则需要实现该虚函数QPlaceManagerEngine* createPlaceManagerEngine() : 位置搜索引擎,实现位置搜索,比如配置文件有"OnlinePlacesFeature"相关特性,则需要实现该虚函数

由于本章我们只需要实现一个在线高德地图显示,所以只需要实现QGeoMappingManagerEngine* createMappingManagerEngine()虚函数即可.

自定义一个GeoServiceProviderFactory类,并且继承于QGeoServiceProviderFactory类.

如果不生成dll的话,则需要在main函数中声明插件类:

Q_IMPORT_PLUGIN(GeoServiceProviderFactory)

GeoServiceProviderFactory代码如下所示:

class GeoServiceProviderFactory: public QObject, public QGeoServiceProviderFactory{Q_OBJECTQ_INTERFACES(QGeoServiceProviderFactory)Q_PLUGIN_METADATA(IID "org.qt-project.qt.geoservice.serviceproviderfactory/5.0" FILE "maps_plugin.json")public:QGeoMappingManagerEngine* createMappingManagerEngine (const QVariantMap &parameters,QGeoServiceProvider::Error *error, QString *errorString) const; // 返回我们子类化的地图映射管理器引擎类};

Q_PLUGIN_METADATA宏用来描述该属性的元信息

IID "org.qt-project.qt.geoservice.serviceproviderfactory/5.0" 则用来描述地图服务的通用接口描述符、

FILE "map_plugin.json" 则标明我们插件的配置描述文件是谁.

map_plugin.json配置文件如下所示:

{"Keys": ["Gaode"],"Provider": "Gaode","Version": 100,"Experimental": false,"Features": ["OnlineMappingFeature","OnlineGeocodingFeature","ReverseGeocodingFeature"]}

假如我们qml去使用Gaode插件,如下所示:

Map {id: _mapanchors.fill: parent// 地图插件plugin: Plugin { name: "Gaode" }}

那么就会根据"Gaode"去找到GeoServiceProviderFactory的createMappingManagerEngine虚函数,从而注册一个地图映射管理器引擎给qml显示地图用.

未完待续,具体实现细节参考文章:

61.qt quick-qml高德地图实现V1版本(跨平台支持、无需浏览器内核,运行迅速,下个版本实现位置搜索)_心中无女人 拔刀自然神 剑谱第一页 忘掉心上人-CSDN博客

下章学习:

63.qt quick-qml使用高德地图插件实现V2版本(新增:位置搜索、路径规划、轨迹编辑等)_获得黑色生命力,抵抗时间扭曲,坚持去做一件有长期有意义的事-CSDN博客

qt quick-qml高德地图实现V1版本(跨平台支持 无需浏览器内核 运行迅速 下个版本实现位置搜索)

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。