【问题标题】:Fit map to objects in Carto mobile SDK使地图适合 Carto 移动 SDK 中的对象
【发布时间】:2018-03-10 07:37:21
【问题描述】:

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

【问题讨论】:

    标签: ios maps cartodb nutiteq carto-mobile


    【解决方案1】:

    我以前处理过这个问题。解决这个问题并非易事,但我可以提供一个解决此问题的示例 sn-p。

    您需要提供屏幕边界和地图边界,即绘制边界框所需的最小和最大位置。

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

    这是一个适合当前加载站点的地图的 sn-p,您应该只需要对其进行少量修改以适合您的用例:

    -(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];
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-11
      相关资源
      最近更新 更多