Android SDK
灵奇地图(CMGIS) Android SDK
是一套地图开发调用接口,开发者可以轻松地在自己的Android应用中加入地图相关的功能,包括:地图显示、与地图交互、在地图上绘制、兴趣点搜索、路径规划、绘制自定义Marker、标签、面状图形等功能;
CMGIS SDK不仅支持调用二维地图开发接口,也支持调用仿真三维地图开发接口
CMGIS SDK调用需要获取官方KEY授权;
IOS SDK
灵奇地图(CMGIS) IOS SDK
是一套地图开发调用接口,开发者可以轻松地在自己的IOS应用中加入地图相关的功能,包括:地图显示、与地图交互、在地图上绘制、兴趣点搜索、路径规划、绘制自定义Marker、标签、面状图形等功能;
CMGIS SDK不仅支持调用二维地图开发接口,也支持调用仿真三维地图开发接口;
CMGIS SDK调用需要获取官方KEY授权;
JavaScript SDK
灵奇地图(CMGIS) JS SDK
是一套地图开发调用接口,开发者可以轻松地在自己的JS应用中加入地图相关的功能,包括:地图显示、与地图交互、在地图上绘制、兴趣点搜索、路径规划、绘制自定义Marker、标签、面状图形等功能;
CMGIS SDK不仅支持调用二维地图开发接口,也支持调用仿真三维地图开发接口;
CMGIS SDK调用需要获取官方KEY授权;
Url “http://211.149.241.213:8081/repository/public/”
}1. 如何程序签名的SHA-1值?
2. 安装jdk8后,打开系统控制台,切换到签名key所在目录,执行命令keytool -v -list -keystore < key名称> ,证书指纹中的SHA-1.
矢量地图:
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
栅格地图:
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
"https://gis.you07.com/");
在OnStart的回调中调用
protected void onStart() {
super.onStart();
mapView.onStart();
}
其余的生命周期回调:
onCreate();
onStart();
onResume();
onPause();
onStop();
onSaveInstanceState();
onLowMemory();
onDestroy();
使用墨卡托投影将地图SDK的地图表示为平面。在东西方向,地图无缝地环绕无限次。由于地图的底部和顶部可能会无限地变大,并进一步扭曲
地图朝向两极,南北轴线将在北90度和南90度处切断。考虑到这一点,介绍摄像机对象来表示用户在地图上方的视点。
默认情况下,相机可以被用户或开发人员倾斜,旋转,缩放和/或移动。重要的是要知道,相机对象不会对标记,图层的来源或您添加的其他注
释进行任何更改,而不会直接影响此行为。
摄像机API调用说明
API | 描述 |
---|---|
moveCamera() | 根据更新中定义的说明重新定位相机,并立即移动相机。建议避免使用此API来支持易用或动画相机API,这些API将为您的用户提供更多上下文,以便相机在地图上定位自己。 |
easeCamera() | 逐渐移动相机默认持续时间,除非在CameraUpdate中指定,否则缩放不会受到影响。如果您打算让地图相机在移动时跟踪当前用户,则这是正确的API,因为其中一个参数可以设置为false,禁用动画插值器并导致线性缓动。 |
animateCamera() | 使用启动动力飞行的过渡动画将摄像机动画到CameraUpdate中定义的新位置。 |
CameraPosition position = new CameraPosition.Builder()
.target(new LatLng(51.50550, -0.07520)) // 移动的目标位置,单位是经纬度
.zoom(10) // 缩放等级,0-20级
.tilt(20) // 倾斜角度
.build(); // 生成位置对象
在地图上识别单个点时,标记很有用。该SDK附带一个默认标记图标,可以根据您的特定需求进行配置。暴露API可选择将此图标更改为您希望
的任何位图图像。要为你的地图创建一个标记,你只需要提供一个位置来定义标记将被放置在地图上的位置。调用实际将标记添加到地图。
LatLng map.addMarker()
.position(new LatLng(48.85819, 2.29458))
.title("Eiffel Tower")
);
@Override
public boolean onMarkerClick(@NonNull Marker marker) {
Toast.makeText(MainActivity.this, marker.getTitle(),
Toast.LENGTH_LONG).show();
return true;
} });
.addAll(points)
.color(Color.parseColor("#3bb2d0"))
.width(2));
.addAll(polygon)
.fillColor(Color.parseColor("#3bb2d0")));
方法名 | 说明 | 传入参数 | 返回值 |
---|---|---|---|
setStartLocationName | 设置起点位置名称 | Name:string | void |
setEndLocationName | 设置结束点位置名称 | name: String | void |
setStartMarker | 设置起点marker | centerLatLng: Coordinate | void |
setEndMarker | 设置终点marker | centerLatLng: Coordinate | void |
showRouteLine | 显示导航线段 | isIndoor: Boolean(是否室内) | void |
setPathListView | 设置路径线 | paths: MutableList < RoutePresenter.OnLineRoutePath> , startLocationName: String, endLocationName: String | void |
setCountInfo | 设置路径规划统计信息 | lengthInfo: String, timeInfo: String | void |
runChooseLocationAnim | 执行选择位置动画 | isClose: Boolean 是否是关闭动画 | void |
startProgressDialog | 显示进度弹窗 | void | void |
dismissProgressDialog | 关闭进度弹窗 | void | void |
routeSuccess | 路径规划成功 | void | void |
routeError | 路径规划失败 | void | void |
isIndoor | 是否是室内 | void | Boolean |
设置了起点后,自动进行路径规划.
回调方法名称 | 返回参数 |
---|---|
onClick() | Feature:地图上被点击的面对象 |
回调方法名称 | 说明 |
---|---|
onSuccess() | 遮罩层加载成功 |
onError() | 遮罩层加载失败 |
.putExtra(MAP_TYPE, < 2D或者3D> ) );
super.onActivityResult(requestCode, resultCode, data)
if (resultCode == SearchActivity.RESULT_CODE) {
//处理逻辑 } }
方法名称 | 回调参数 | 说明 |
---|---|---|
searchFinish | results: List
|
搜索完成 |
searchNoResult | void | 无搜索结果 |
searchError | e: Exception | 搜索失败 |
noneInput | void | 没有输入结果 |
pod 'Mapbox-iOS-SDK', '~> 3.7.8'
pod 'AFNetworking'
pod 'MJExtension'
pod 'Masonry'
#c++库
pod 'geos', '~> 3.4.2'
添加App Transport Security Settings 字段
在字段里在添加Allow Arbitrary Loads字段 值为:YES
添加MGLMapboxAccessToken字段,对应的值如下:
(这个值为灵奇地图引擎调用授权KEY,请联系当前项目经理进行获取)
添加NSLocationWhenInUseUsageDescription字段 值为:
配置地图sdk到工程中
sdk需要使用HTTPS协议发起网络请求
在你的viewController.h中添加头文件
- (void)viewDidLoad {
[super viewDidLoad];
//实例化地图对象
LQQMapView *mapView = [[LQQMapView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight - StaNavBarH - TabFooder) mapId:@"2"];
//是否显示楼层信息
mapView.isHaveLevel = YES;
[self.view addSubview: mapView]; }
- (void)viewDidLoad {
[super viewDidLoad];
/例子
LQQPathsView *mapView = [[LQQPathsView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight -
StaNavBarH - TabFooder) mapId:@"2"];
mapView.mapDeletage = self;
mapView.isHaveLevel = YES;
[self.view addSubview: mapView]; }
调用下方接口,获取路径数组
/** 路径规划(包含路径数据和虚线数据)
@param startLat 起点纬度
@param startLon 起点经度
@param startLevel 起点楼层
@param endLat 终点纬度
@param endLon 终点经度
@param endLevel 终点路层
@param typeStr 人走或者车走
@param strideStr 跨楼层方式
@param mapId 地图Id
@param completion 结果
@param errorStr 错误 */
-(void)getWithStartLat:(double)startLat startLon:(double)startLon startLevel:(NSString *)startLevel endLat:(double)endLat
endLon:(double)endLon endLevel:(NSString *)endLevel footAndCar:(NSString *)typeStr elevatorAndStairs:(NSString *)strideStr
mapId:(NSString *)mapId completion:(Return)completion errorStr:(Error)errorStr;
通过绘制导航线接口,绘制在地图上
//添加导航线
/**
如需自己添加属性,则需在添加导航线之前设置, 是否显示导航栏图片
*/
@property (nonatomic,readwrite) BOOL isNavLineImgae;
/**
如需自己添加属性,则需在添加导航线之前设置,如果显示导航图片,此属性无效 设置导航线颜色
*/
@property (nonatomic,readwrite) UIColor * _Nullable naviLineColor;
/**
如需自己添加属性,则需在添加导航线之前设置 设置导航线宽度
*/ @property (nonatomic,readwrite) NSNumber * _Nullable naviLineWidth; /**
添加导航线,切换完楼层重新调此方法
添加导航线,切换完楼层重新调此方法
@param identifier 导航线的唯一标识符
@param currentFloor 当前楼层
@param completion 回调结果
*/
-(void)LQKJMapAddNAvilineWithCoordinatesArr:(NSArray < Routing* > *_Nonnull)dic
AndIdentifier:(NSString*_Nonnull)identifier AndFloor:(NSString*_Nullable)currentFloor
completionHandler:(nullable void (^)(NSError* _Nullable error))completion;
/**
删除所有导航线
- (void)viewDidLoad {
[super viewDidLoad];
//实例化地图对象
LQQ3DMapViews *mapView = [[LQQ3DMapViews alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth,
ScreenHeight - StaNavBarH - TabFooder) mapId:@"2"];
[self.view addSubview: mapView]; }
在你的viewController.h中添加头文件
- (void)viewDidLoad {
[super viewDidLoad];
//实例化地图对象
LQLMapView *mapView = [[LQLMapView alloc] initWithFrame:self.view.bounds];
//设置地图中心点经纬度及缩放级别
[mapView setCenterCoordinate:CLLocationCoordinate2DMake(43.7383, 7.4094)
zoomLevel:12
animated:NO];
[self.view addSubview:mapView]; }
- (void)viewDidLoad {
[super viewDidLoad];
//实例化地图对象
LQLMapView *mapView = [[LQLMapView alloc] initWithFrame:self.view.bounds];
//设置地图中心点经纬度及缩放级别
[mapView setCenterCoordinate:CLLocationCoordinate2DMake(43.457, -75.789) zoomLevel:4
animated:NO];
mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
mapView.lQLDelegate = self;
[self.view addSubview:mapView];
}
- (void)LQKJmapView:(LQLMapView *)mapView didFinishLoadingStyle:(LQLStyle *)style {
//设置图片的范围
MGLCoordinateQuad coordinates = MGLCoordinateQuadMake(CLLocationCoordinate2DMake(46.437, -80.425),
CLLocationCoordinate2DMake(37.936, -80.425),CLLocationCoordinate2DMake(37.936, -71.516),
CLLocationCoordinate2DMake(46.437, -71.516));
//设置图片地址
NSString *radarImage = [[NSBundle mainBundle] pathForResource:@"xiongmao" ofType:@"gif"];
//设置ImageSource
MGLImageSource *source = [[MGLImageSource alloc] initWithIdentifier:@"xiongmao"
coordinateQuad:coordinates image:[UIImage imageWithContentsOfFile:radarImage]];
[style addSource:source];
//设置显示在最上层
MGLRasterStyleLayer *radarLayer = [[MGLRasterStyleLayer alloc] initWithIdentifier:@"radar-layer" source:source];
for (MGLStyleLayer *layer in style.layers.reverseObjectEnumerator) {
if (![layer isKindOfClass:[MGLSymbolStyleLayer class]]) {
[style insertLayer:radarLayer aboveLayer:layer];
break;
}
}
}
- (void)viewDidLoad {
[super viewDidLoad];
LQLMapView *mapView = [[LQLMapView alloc] initWithFrame:self.view.bounds];
mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
mapView.lQLDelegate = self;
//显示当前位置
mapView.showsUserLocation = YES;
[self.mapView setCenterCoordinate:CLLocationCoordinate2DMake(30.11, 104.11)
zoomLevel:2
animated:NO];
[self.view addSubview:self.mapView];
}
- (void)LQKJmapViewRegionIsChanging:(LQLMapView *)mapView {
if (_annotation) {
//选中mark
[self.mapView setSelectedAnnotations:@[self.annotation]];
}
}
-(LQLAnnotationImage*)LQKJmapView:(LQLMapView*)mapView
imageForAnnotation:(id)annotation {
//修改mark图片
if ([annotation isKindOfClass:[LQLPointAnnotation class]]) {
LQLAnnotationImage *startImag = [LQLAnnotationImage
annotationImageWithImage:Image(@"delfu") reuseIdentifier:@"delfu"];
return startImag;
}
return nil;
}
//是否显示mark
- (BOOL)LQKJmapView:(LQLMapView *)mapView annotationCanShowCallout:(id)annotation {
return YES;
}
- (void)viewDidLoad {
[super viewDidLoad];
LQQSearchView *mapView = [[LQQSearchView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight - StaNavBarH - TabFooder) mapId:@"2"];
mapView.mapSearchViewDeletage = self;
[self.view addSubview: mapView];
}
/**
搜索结果模型数组
@param mapId 地图Id
@param lonLat 经纬度字符串(定位经纬度或屏幕中心点经纬度字符串:经度在前中间“,”纬度在后)
@param textStr 搜索文字
@param complate 结果
@param errorStr 错误
*/
-(void)getSearchWithMapId:(NSString*)mapId lonAndLatStr:(NSString *)lonLat textStr:(NSString
*)textStr complate:(RetuBlock)complate errorStr:(ErrorBlock)errorStr;
通过上面接口获取搜索的数据。
- (void)viewDidLoad {
[super viewDidLoad];
//加载地图
LQLMapView *mapView = [[LQLMapView alloc] initWithFrame:self.view.bounds];
mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[mapView setCenterCoordinate:CLLocationCoordinate2DMake(48.13863, 11.57603)
zoomLevel:12
animated:NO];
mapView.lQLDelegate = self;
[self.view addSubview:mapView];
//创建mark
LQLPointAnnotation *hello = [[LQLPointAnnotation alloc] init];
hello.coordinate = CLLocationCoordinate2DMake(48.13863, 11.57603);
hello.title = @"Hello world!";
hello.subtitle = @"Welcome to my marker";
[mapView addAnnotation:hello];
}
-(LQLAnnotationView*)LQKJmapView:(LQLMapView*)mapView viewForAnnotation:(id)annotation
{
return nil;
}
//是否显示mark
- (BOOL)LQKJmapView:(LQLMapView *)mapView annotationCanShowCallout:(id)annotation {
return YES;
}
- (void)viewDidLoad {
[super viewDidLoad];
//加载地图
LQLMapView *mapView = [[LQLMapView alloc] initWithFrame:self.view.bounds];
mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[mapView setCenterCoordinate: CLLocationCoordinate2DMake(-33.8500000,18.4158234)
zoomLevel:12
animated:NO];
mapView.lQLDelegate = self;
[self.view addSubview:mapView];
//创建mark
LQLPointAnnotation *point = [[LQLPointAnnotation alloc] init];
point.title = @"Cape Town Harbour";
point.subtitle = @"Un dels ports mes actius a del sud";
point.coordinate = CLLocationCoordinate2DMake(-33.8500000,18.4158234);
[mapView addAnnotation:point];
}
-(LQLAnnotationImage*)LQKJmapView:(LQLMapView*)mapView
imageForAnnotation:(id)annotation {
if ([annotation isKindOfClass:[LQLPointAnnotation class]]) {
//修改mark图片
LQLAnnotationImage *imag = [LQLAnnotationImage annotationImageWithImage:Image(@"delfu")
reuseIdentifier:@"test"];
return imag;
}
return nil;
}
//显示mark
- (BOOL)LQKJmapView:(LQLMapView *)mapView annotationCanShowCallout:(id)annotation {
return YES;
}
- (void)viewDidLoad {
[super viewDidLoad];
//加载地图对象
self.mapView = [[LQLMapView alloc] initWithFrame:self.view.bounds];
self.mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.mapView setCenterCoordinate:CLLocationCoordinate2DMake(45.5076, -122.6736)
zoomLevel:11
animated:NO];
self.mapView.lQLDelegate = self;
[self.view addSubview:self.mapView];
UIImageView *image = [[UIImageView alloc] init];
image.image = Image(@"logo40");
[self.mapView addSubview:image];
[self drawPolyline];
}
//绘制线
- (void)drawPolyline {
dispatch_queue_t backgroundQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(backgroundQueue, ^(void) {
//获取geojson数据
NSString *jsonPath = [[NSBundle mainBundle] pathForResource:@"example" ofType:@"geojson"];
NSData *data = [[NSData alloc] initWithContentsOfFile:jsonPath];
LQLShapeCollectionFeature *shapeCollectionFeature = (LQLShapeCollectionFeature *)[LQLShape
shapeWithData:data encoding:NSUTF8StringEncoding error:NULL];
//获取lineFeature
LQLPolylineFeature *polyline = (LQLPolylineFeature *)shapeCollectionFeature.shapes.firstObject;
__weak typeof(self) weakSelf = self;
dispatch_async(dispatch_get_main_queue(), ^(void) {
//绘制线到地图上
[weakSelf.mapView addAnnotation:polyline];
});
});
}
-(CGFloat)LQKJmapView:(LQLMapView*)mapView alphaForShapeAnnotation:(id)annotation{
return 1.0f;
}
//设置线的颜色
-(UIColor*)LQKJmapView:(LQLMapView*)mapView strokeColorForShapeAnnotation:(id)annotation
{
return [UIColor colorWithRed:59.0f/255.0f green:178.0f/255.0f blue:208.0f/255.0f alpha:1.0f];
}
- (void)viewDidLoad {
[super viewDidLoad];
self.mapView = [[LQLMapView alloc] initWithFrame:self.view.bounds];
self.mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.mapView setCenterCoordinate:CLLocationCoordinate2DMake(45.520486, -122.673541) zoomLevel:11 animated:NO];
self.mapView.lQLDelegate = self;
[self.view addSubview:self.mapView];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self drawShape];
}
//绘制面
- (void)drawShape {
//面的各个顶点数组
CLLocationCoordinate2D coordinates[] = {
CLLocationCoordinate2DMake(45.522585, -122.685699),
CLLocationCoordinate2DMake(45.534611, -122.708873),
CLLocationCoordinate2DMake(45.530883, -122.678833),
CLLocationCoordinate2DMake(45.547115, -122.667503),
CLLocationCoordinate2DMake(45.530643, -122.660121),
CLLocationCoordinate2DMake(45.533529, -122.636260),
CLLocationCoordinate2DMake(45.521743, -122.659091),
CLLocationCoordinate2DMake(45.510677, -122.648792),
CLLocationCoordinate2DMake(45.515008, -122.664070),
CLLocationCoordinate2DMake(45.502496, -122.669048),
CLLocationCoordinate2DMake(45.515369, -122.678489),
CLLocationCoordinate2DMake(45.506346, -122.702007),
CLLocationCoordinate2DMake(45.522585, -122.685699),
};
//顶点个数
NSUInteger numberOfCoordinates = sizeof(coordinates) / sizeof(CLLocationCoordinate2D)
//面数据
LQLPolygon *shape = [LQLPolygon polygonWithCoordinates:coordinates count:numberOfCoordinates];
//添加面
[self.mapView addAnnotation:shape];
}
-(CGFloat)LQKJmapView:(LQLMapView *)mapView alphaForShapeAnnotation:(id)annotation {
return 0.5f;
}
//设置面的边框颜色
-(UIColor*)LQKJmapView:(LQLMapView*)mapView strokeColorForShapeAnnotation:(id)annotation {
return [UIColor whiteColor];
}
-(UIColor*)LQKJmapView:(LQLMapView*)mapView fillColorForPolygonAnnotation:(id)annotation {
//设置面的颜色
return [UIColor colorWithRed:59.0f/255.0f green:178.0f/255.0f blue:208.0f/255.0f alpha:1.0f];
}
- (void)viewDidLoad {
[super viewDidLoad];
self.mapView = [[LQLMapView alloc] initWithFrame:self.view.bounds];
self.mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.mapView setCenterCoordinate:CLLocationCoordinate2DMake(45.520486, -122.673541)
zoomLevel:11
animated:NO];
self.mapView.lQLDelegate = self;
[self.view addSubview:self.mapView];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self drawShape];
}
- (void)drawShape {
//部分面的数组
CLLocationCoordinate2D coordinates1[] = {
CLLocationCoordinate2DMake(25.256531695820797, 55.30084858315658),
CLLocationCoordinate2DMake(25.252243254705405, 55.298280197635705),
CLLocationCoordinate2DMake(25.250501032248863, 55.30163885563897),
CLLocationCoordinate2DMake(25.254700192612702, 55.304059065092645),
CLLocationCoordinate2DMake(25.256531695820797, 55.30084858315658)};
NSUInteger numberOfCoordinates1 = sizeof(coordinates1) / sizeof(CLLocationCoordinate2D);
LQLPolygon *shape1 = [LQLPolygon polygonWithCoordinates:coordinates1 count:numberOfCoordinates1];
//部分面的数组
CLLocationCoordinate2D coordinates2[] = {
CLLocationCoordinate2DMake(25.262517391695198, 55.30173763969924),
CLLocationCoordinate2DMake(25.26122200491396, 55.301095543307355),
CLLocationCoordinate2DMake(25.259479911263526, 55.30396028103232),
CLLocationCoordinate2DMake(25.261132667394975, 55.30489872958182),
CLLocationCoordinate2DMake(25.262517391695198, 55.30173763969924)};
NSUInteger numberOfCoordinates2 = sizeof(coordinates1) / sizeof(CLLocationCoordinate2D);
LQLPolygon *shape2 = [LQLPolygon polygonWithCoordinates:coordinates2 count:numberOfCoordinates2];
LQLMultiPolygon *shapes = [LQLMultiPolygon multiPolygonWithPolygons:@[shape1,shape2]];
//整个面的数组
CLLocationCoordinate2D coordinates[] = {
CLLocationCoordinate2DMake(25.26476622289597, 55.30122473231012),
CLLocationCoordinate2DMake(25.25827212207261, 55.29743486255916),
CLLocationCoordinate2DMake(25.251356725509737, 55.28978863411328),
CLLocationCoordinate2DMake(25.246425506635504, 55.300027931336984),
CLLocationCoordinate2DMake(25.244200378933655, 55.307474692951274),
CLLocationCoordinate2DMake(25.256408010450187, 55.31212891895635),
CLLocationCoordinate2DMake(25.26266169122738, 55.30774064871093),
CLLocationCoordinate2DMake(25.264946609615492, 55.301357710197806),
};
NSUInteger numberOfCoordinates = sizeof(coordinates) / sizeof(CLLocationCoordinate2D);
LQLPolygon *poly = [LQLPolygon polygonWithCoordinates:coordinates count:numberOfCoordinates interiorPolygons:shapes.polygons];
[self.mapView addAnnotation:poly];
}
//填充透明度
-(CGFloat)LQKJmapView:(LQLMapView *)mapView alphaForShapeAnnotation:(id)annotation {
return 0.5f;
}
//面的边框颜色
-(UIColor*)LQKJmapView:(LQLMapView*)mapView
strokeColorForShapeAnnotation:(id)annotation {
return [UIColor whiteColor];
}
//设置面的颜色
-(UIColor*)LQKJmapView:(LQLMapView*)mapView
fillColorForPolygonAnnotation:(id)annotation {
return [UIColor colorWithRed:59.0f/255.0f green:178.0f/255.0f blue:208.0f/255.0f alpha:1.0f];
}
- (void)viewDidLoad {
[super viewDidLoad];
NSURL *styleURL = [MGLStyle satelliteStyleURL];
self.mapView = [[LQLMapView alloc] initWithFrame:self.view.bounds styleURL:styleURL];
self.mapView.attributionButton.tintColor = [UIColor whiteColor];
self.mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.mapView setCenterCoordinate:CLLocationCoordinate2DMake(64.900932, -18.167040)
zoomLevel:5
animated:NO];
self.mapView.lQLDelegate = self;
[self.view addSubview:self.mapView];
}
- (void)tapTouceMapView:(UITapGestureRecognizer *)tap {
CGPoint point = [tap locationInView:self.mapView];
self.tapCoordinate = [self.mapView convertPoint:point toCoordinateFromView:self.mapView];
self.delAnnotation.coordinate = self.tapCoordinate;
}
-(LQLAnnotationView*)LQKJmapView:(LQLMapView*)mapView
viewForAnnotation:(id)annotation {
if ([annotation isKindOfClass:[LQLPointAnnotation class]]) {
self.annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:@"startPoint"];
return self.annotationView;
}
return nil;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self.mapView setCenterCoordinate:CLLocationCoordinate2DMake(29.757898337410225,-95.363484945553751) zoomLevel:14 animated:YES];
self.mapView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
self.mapView.lQLDelegate = self;
[self.view addSubview:self.mapView];
}
- (void)handleMapTap:(UITapGestureRecognizer *)gesture {
if (self.shape) {
[self.mapView removeAnnotation:self.shape];
}
CGPoint spot = [gesture locationInView:self.mapView];
//把点击的点转换为地图的经纬
CLLocationCoordinate2D coor = [self.mapView convertPoint:spot toCoordinateFromView:self.mapView];
//获取当前经纬度对应的面
NSArray* featureArr = [self.mapView visibleFeaturesAtPoint:[self.mapView convertCoordinate:coor toPointToView:self.mapView]];
self.shape = featureArr.firstObject;
//添加面到地图上
[self.mapView addAnnotation:self.shape];
}
//填充的透明度
-(CGFloat)LQKJmapView:(LQLMapView *)mapView alphaForShapeAnnotation:(id)annotation {
return 0.5f;
}
//面的边框颜色
-(UIColor*)LQKJmapView:(LQLMapView*)mapView strokeColorForShapeAnnotation:(id)annotation {
return [UIColor whiteColor];
}
//面的颜色
-(UIColor*)LQKJmapView:(LQLMapView*)mapView fillColorForPolygonAnnotation:(id)annotation {
return [UIColor colorWithRed:59.0f/255.0f green:178.0f/255.0f blue:208.0f/255.0f alpha:1.0f];
}
- (void)viewDidLoad {
[super viewDidLoad];
self.mapView = [[LQLMapView alloc] initWithFrame:self.view.bounds];
[self.mapView setCenterCoordinate:CLLocationCoordinate2DMake(29.757898337410225,-95.363484945553751) zoomLevel:14 animated:YES];
self.mapView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
self.mapView.lQLDelegate = self;
[self.view addSubview:self.mapView];
}
- (void)handleMapTap:(UITapGestureRecognizer *)gesture {
CGPoint spot = [gesture locationInView:self.mapView];
//把点击的点转换为地图的经纬
CLLocationCoordinate2D coor = [self.mapView convertPoint:spot toCoordinateFromView:self.mapView];
//获取经纬度对应面的数据
NSArray* featureArr = [self.mapView visibleFeaturesAtPoint:[self.mapView convertCoordinate:coor toPointToView:self.mapView]];
if (featureArr.count > 0) {
//将面的数据展示出来
LQLPolygonFeature *feature = featureArr.lastObject;
self.annotation.coordinate = coor;
NSString *str = feature.attributes[@"class"];
if (str.length > 0) {
self.annotation.title = str;
self.annotation.subtitle = @"";
} else {
self.annotation.title = [NSString stringWithFormat:@"Propietats:"];
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:feature.attributes options:NSJSONWritingPrettyPrinted error:nil];
NSString * str = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
str = [str stringByReplacingOccurrencesOfString:@" " withString:@""];
str = [str stringByReplacingOccurrencesOfString:@"{" withString:@""];
str = [str stringByReplacingOccurrencesOfString:@"}" withString:@""];
str = [str stringByReplacingOccurrencesOfString:@"\n" withString:@""];
self.annotation.subtitle = str;
}
[self.mapView selectAnnotation:self.annotation animated:YES];
} else {
self.annotation.coordinate = coor;
self.annotation.title = @"Cap resultat";
[self.mapView selectAnnotation:self.annotation animated:YES];
}
}
- (BOOL)LQKJmapView:(LQLMapView *)mapView annotationCanShowCallout:(id)annotation {
return YES;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.mapView = [[LQLMapView alloc] initWithFrame:self.view.bounds];
[self.mapView setCenterCoordinate:CLLocationCoordinate2DMake(29.757898337410225,-95.363484945553751) zoomLevel:14 animated:YES];
self.mapView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
//设置协议
self.mapView.lQLDelegate = self;
[self.view addSubview:self.mapView];
//点击地图的手势
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleMapTap:)];
for (UIGestureRecognizer *recognizer in self.mapView.gestureRecognizers) {
if ([recognizer isKindOfClass:[UITapGestureRecognizer class]]) {
[singleTap requireGestureRecognizerToFail:recognizer];
}
}
[self.tView addGestureRecognizer:singleTap];
}
- (void)handleMapTap:(UITapGestureRecognizer *)gesture {
//获取点击面对应的面属性
NSArray* featureArr = [self.mapView lQLShowRect:self.tView.frame];
//将面绘制到地图上
[self.mapView addAnnotations:featureArr];
}
- (CGFloat)LQKJmapView:(LQLMapView *)mapView alphaForShapeAnnotation:(id)annotation
{
return 0.5f;
}
//绘制面的边框颜色
-(UIColor*)LQKJmapView:(LQLMapView*)mapView
strokeColorForShapeAnnotation:(id)annotation {
return [UIColor whiteColor];
}
//绘制面的颜色
-(UIColor*)LQKJmapView:(LQLMapView*)mapView
fillColorForPolygonAnnotation:(id)annotation {
return [UIColor colorWithRed:59.0f/255.0f green:178.0f/255.0f blue:208.0f/255.0f alpha:1.0f];
}
Html文件引入标签:
<!-- 引入css文件 -->
<link href='css地址' rel='stylesheet'/>
<!-- 引入js文件 -->
< script src="js地址"> </script>
var vectorMap = new creeper.VectorMap('map', 2, 'https://gis.you07.com/');
var rasterMap = new creeper.RasterMap('map',3,'https://gis.you07.com/');
参数名称 | 说明 | 类型 |
---|---|---|
id | div标签的id名称 | string |
map_id | 地图id | number |
server_url | 地图服务器baseURL | string |
map.on(‘回调类型’,回调方法);
map.off(‘回调类型’,回调方法);
回调类型 | 说明 |
---|---|
click | 当定位设备(一般是鼠标)在地图上的同一个点被按下又释放时触发。 |
load | 所有需要的数据源下载完毕, 并且第一个可见的地图渲染完成后即刻触发。 |
zoom | 在用户交互或 Map#flyTo 等方法引发缩放级别转换之前触发。 |
touchstart | 当一个触点落在地图上时触发。 |
touchmove | 当触点在地图中移动时触发。 |
touchend | 触点从地图中移开时触发。 |
new Marker(element: [HTMLElement], options: [Object])
element ([HTMLElement]) 用作标记的 DOM 元素(默认创建一个 div 元素)
options ([Object])
Name | Description |
---|---|
options.offset [PointLike] | 作为 PointLink 对象对于元素左上角的像素偏移。负数表示左和上。 |
var marker = new mapboxgl.Marker() .setLngLat([30.5, 50.5])
.addTo(map);
marker.remove();
GeoJson规范参考:
https://www.oschina.net/translate/geojson-spec?cmp
https://tools.ietf.org/html/rfc7946
创建geojson
vectorMap.on('load',function () {
增加数据源
vectorMap.addSource('lineSource', {
type: 'geojson',
data: geoJson
});
增加线图层
vectorMap.addLayer({
type: 'line',
source: 'lineSource',
id: 'lineLayer',
paint: {
'line-color': 'red',
'line-width': 3
},
layout: {
'line-cap': 'round',
'line-join': 'round'
}
});
});
创建Geojson
var geoJson = {
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"geometry": {
"coordinates": [],
"type": "LineString"
}
}]
};
vectorMap.on('load', function () {
增加数据源
vectorMap.addSource('polygonSource', {
type: 'geojson',
data: geoJson
});
增加图层
vectorMap.addLayer({
type: 'fill',
source: 'polygonSource',
//id唯一
id: 'polygonLayer',
paint: {
'fill-color': 'red'
}
});
});
//先移除数据源关联的图层
map.removeLayer(layerId)
//再移除数据源
map.removeSource(sourceId);
var routeComponent = new creeper.RouteComponent(vectorMap, 2, 'https://gis.you07.com/');
routeComponent.ri = {
routeSuccess: function () {
console.info('路径规划成功');
},
routeError: function () {
console.error('路径规划失败');
},
setPathListView: function (paths, startName, endName) {
console.info('paths is %o',paths);
},
isIndoor: function () {
return true;
}
};
routeComponent.setLocation({
type: "Point",
coordinates: [startLocation.lat, startLocation.lng, -1]
}, "起点", -1);
routeComponent.setLocation({
type: "Point",
coordinates: [endLocation.lat, endLocation.lng, -1]
}, "终点", -1);
rasterMap.on('overlayer.click', function (e) {
content.innerText = JSON.stringify(e.feature, null, 4);
})
Geojson的Feature类型
var poiComponent = new creeper.POIComponent('https://gis.you07.com/', 2,
creeper.POIComponent.Vector_Map);
poiComponent.callback = {
searchFinish: function (results, isAdd) {
var searchResult = JSON.stringify(results,null,4);
console.info("搜索结果:" + searchResult);
},
searchNoResult: function () {
console.warn('无搜索内容')
},
searchError: function (e) {
console.error('搜索失败:' + e)
},
noneInput: function () {
console.warn('无输入内容')
}
};
poiComponent.createSearchRequest(‘需要搜索的内容’, false);
Name | Description |
---|---|
options.curve [number](default 1.42) | 随着飞行路径出现的缩放“曲线”。要获得类似 Map#easeTo 的效果, 大幅度移动时会出现较高的缩放值,较小移动时有较低的缩放值。 van Wijk (2003) 进行的用户调查中 显示用户选择的平均值为 1.42。 Math.pow(6, 0.25) 的值与均方根平均速率相同。 值为 1 时会出现圆周运动。 |
options.minZoom [number] | 位于飞行路径顶点的以 0 为起点的缩放级别。如果指定了 options.curve ,可忽略这一选项。 |
options.speed [number](default 1.2) | 与 options.curve 相关的动态转换的平均速率。 速率为 1.2 指,地图每秒以 1.2 倍于 options.curve 可见整屏(screenful)的速度随着飞行路径移动。 screenful 指地图的可见屏幕跨度区域。它不对应固定的物理距离,而是随缩放级别变化。 |
options.screenSpeed [number] | 线性时间曲线情况下,动态转换的平均速率,按照每秒的移动的 screenful 数量计算。 如果指定了 options.speed ,则忽略该选项。 |
eventData ([Object]) | 该方法触发的事件对象需要添加的其它属性。 |
例子:
map.flyTo({center: [0, 0], zoom: 9});// using flyTo options
map.flyTo({
center: [0, 0],
zoom: 9,
speed: 0.2,
curve: 1,
easing(t) {
return t;
}
});