为 WRLD SDK 提供Objective-C iOS绑定,这是一个基于OpenGL的库,用于美丽且可自定义的 3D 地图。
WRLD 3D 地图 API 简单易用,可以无痕地添加到应用程序中。它遵循了常见的映射 API 习惯用法,所以对于在该领域有先验经验的人来说应该很熟悉。
如果您有任何问题、错误报告或功能请求,请随时向该存储库的 问题跟踪器 提交。
入门的最简单方法是使用 WRLD iOS API 示例应用程序,该应用程序演示了在 iOS 应用程序中使用 WRLD 的 3D 地图。入门说明可以在该仓库的 README 文件中找到。
为了使用 WRLD 3D 地图 API,您必须在 https://www.wrld3d.com/developers 上注册一个免费的开发者账户。注册后,您将为您的应用程序创建一个 API 密钥。
如果您正在创建新应用程序或将 WRLD 3D 地图集成到现有应用程序中,则 API 密钥应出现在主应用程序包信息字典中,其键为 "eeGeoMapsApiKey",在 EGMapView 创建时。
以下分步指南详细说明了向 iOS API 贡献的过程。
下载以下内容
git clone [email protected]:wrld3d/ios-api.git
git clone [email protected]:wrld3d/ios-api-example.git
设置项目
target :eeGeoApiExample do
platform :ios, "7.0"
pod 'SMCalloutView', '~> 2.1'
pod 'GoogleMaps', '1.10.1'
pod 'FPPopover', '1.4.1'
end
进行修改
使用 WRLD iOS API 时,应用与以下三种主要类型交互,如下所述:EGMapView、EGMapDelegate 和 EGMapApi。
有关 API 的更详细文档,请参阅 WRLD CocoaDocs 页面。
EGMapView 是 UIView 子类,可以添加到应用程序视图层次结构中。它包含将 WRLD 3D 地图渲染到的表面。将 EGMapView 添加到视图层次结构中开始构建 EGMapApi 实例的过程,该实例将通过 EGMapDelegate 代理提供给应用程序。
EGMapView 负责内部管理地图数据的流式传输和绘制,以及处理触摸输入以移动相机。在实现 EGMapDelegate 协议的 ViewController 中,可以从 EGMapDelegate 协议中添加一个视图
- (void)viewDidLoad
{
[super viewDidLoad];
self.eegeoMapView = [[[EGMapView alloc] initWithFrame:self.view.bounds] autorelease];
self.eegeoMapView.eegeoMapDelegate = self;
[self.view insertSubview:self.eegeoMapView atIndex:0];
}
添加 EGMapDelegate 很重要,因为主 EGMapApi 实例是通过代理提供的。执行此操作的方法是代理协议中唯一要求的方法。当 API 准备好由应用程序使用时,EGMapView 将调用 eegeoMapReady 方法,应按以下方式实现
- (void)eegeoMapReady:(id<EGMapApi>)api
{
self.eegeoMapApi = api;
// App code to handle the API becoming available...
}
EGMapDelegate 还提供了处理地图生成事件的可选方法,例如选择和取消选择注释,以及地图行为的多项自定义选项。
EGMapApi 是应用操作地图的主要接口。它提供了绘制多边形、显示注释和更改地图主题的方法。
添加注释很简单
EGPointAnnotation* annotation = [[[EGPointAnnotation alloc] init] autorelease];
annotation.coordinate = CLLocationCoordinate2DMake(37.794851, -122.402650);
annotation.title = @"Three Embarcadero";
annotation.subtitle = @"(Default Callout)";
[self.eegeoMapApi addAnnotation:annotation];
添加到地图上的注释选择时将显示默认呼叫。默认呼叫通过使用 SMCalloutView 库来实现,类似于熟悉的内置 MapKit 呼叫。我们可以通过实现 EGMapDelegate 方法来处理注释的选择
- (void)didSelectAnnotation:(id<EGAnnotation>)annotation
{
// Add a nice left callout accessory.
EGAnnotationView* view = [self.eegeoMapApi viewForAnnotation:annotation];
view.leftCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
printf("Selected annotation with title: %s\n", [[annotation title] UTF8String]);
}
从视觉上看,结果如下所示
根据使用的主题更改地图的表示。主题允许修改环境纹理、光照参数和叠加效果,从而允许对地图的视觉进行重大变化。还包括预设的主题集合,允许更改季节、天气和时间。也可以创建新主题。
将主题更改为使用现有预设非常简单。这里有一些示例
// Spring, dawn, rainy weather
EGMapTheme* mapTheme = [[[EGMapTheme alloc] initWithSeason: EGMapThemeSeasonSpring
andTime: EGMapThemeTimeDawn
andWeather: EGMapThemeWeatherRainy] autorelease];
[self.eegeoMapApi setMapTheme: mapTheme];
// Summer, day-time, clear weather
EGMapTheme* mapTheme = [[[EGMapTheme alloc] initWithSeason: EGMapThemeSeasonSummer
andTime: EGMapThemeTimeDay
andWeather: EGMapThemeWeatherClear] autorelease];
[self.eegeoMapApi setMapTheme: mapTheme];
还有许多其他预设可供选择,让开发者能够为他们的地图创建独特和个性化的风格。
WRLD 3D Maps iOS API在简化的BSD许可下发布。有关详细信息,请参阅LICENSE.md。