Ios 将地图适配到Carto mobile SDK中的对象

Ios 将地图适配到Carto mobile SDK中的对象,ios,maps,cartodb,nutiteq,carto-mobile,Ios,Maps,Cartodb,Nutiteq,Carto Mobile,我有一个NtVectoreElements数组,如何设置贴图边界,使其适合屏幕上的每个元素?我看到了moveToFitBounds函数,但不确定如何实现它。你有没有举个例子?我以前处理过这个问题。弄清楚这一点并不是一件小事,但我可以提供一个示例片段来解决这个问题 您需要提供屏幕边界和贴图边界,这意味着绘制边界框所需的最小和最大位置 NtVectoreElements没有立即获取对象边界的方法,您需要遍历数组中的所有元素,以找到其几何体的全局最大值和最小值 下面是一个片段,用于将地图与当前加载的站

我有一个NtVectoreElements数组,如何设置贴图边界,使其适合屏幕上的每个元素?我看到了moveToFitBounds函数,但不确定如何实现它。你有没有举个例子?

我以前处理过这个问题。弄清楚这一点并不是一件小事,但我可以提供一个示例片段来解决这个问题

您需要提供屏幕边界和贴图边界,这意味着绘制边界框所需的最小和最大位置

NtVectoreElements没有立即获取对象边界的方法,您需要遍历数组中的所有元素,以找到其几何体的全局最大值和最小值

下面是一个片段,用于将地图与当前加载的站点相匹配,您只需对其进行少量修改即可满足您的用例:

-(void)fitMapToCurrentlyLoadedSites {
    int siteCount = (int)[_sitesOrderArray count];
    if (siteCount > 0) {
        if (siteCount == 1) {
            //zoom in on single site
            GenericMapMarker *siteMarker = [_sitesOrderArray objectAtIndex:0];
            NTMapPos *sitePosition = [CommonFunctions getMapPosFromCoordinate:_ntMapView coordinate:siteMarker.coordinate];
            [_ntMapView setFocusPos:sitePosition durationSeconds:0];
            [_ntMapView setZoom:15.0 durationSeconds:0];
        } else {
            //create vector of multiple sites
            NTMapPosVector* posVector = [[NTMapPosVector alloc] init];
            for (int i = 0; i < siteCount; i++) {
                GenericMapMarker *siteMarker = [_sitesOrderArray objectAtIndex:i];
                //get mapPos from coordinate
                NTMapPos *mapPos = [CommonFunctions getMapPosFromCoordinate:_ntMapView coordinate:siteMarker.coordinate];
                [posVector add:mapPos];
            }
            //create envelope of vectors
            NTMapEnvelope *envelope = [[NTMapEnvelope alloc] initWithConvexHull:posVector];
            //get mapBounds of envelope
            NTMapBounds *bounds = [envelope getBounds];

            [_ntMapView moveToFitBounds:bounds screenBounds:[self findScreenBounds] integerZoom:TRUE durationSeconds:1.0f];
        }
    }
}
-(NTScreenBounds *)findScreenBounds {
    float screenWidth = self.view.frame.size.width;
    float screenHeight = self.view.frame.size.height;
    NTScreenPos *minScreenPos = [[NTScreenPos alloc] initWithX:0.0 y:0.0];
    NTScreenPos *maxScreenPos = [[NTScreenPos alloc] initWithX:screenWidth y:screenHeight];
    return [[NTScreenBounds alloc] initWithMin:minScreenPos max:maxScreenPos];
}