ArcGIS Runtime SDK for iOS(四) ---使用geometry的原始数据重绘折线

2016.4.15 武汉 小雨
by SevenJohs.

  • 概述
    通过已经绘制的线的基础上,得到JSON数据,使用geometry的JSON字符串的原始数据重绘折线。
  • 内容

    • 绘制出断点折线;
    • 不使用定时器一次性画出;
    • 使用定时器重绘。
  • 绘制出断点折线

/**
 *  绘制线条
 */
-(void)drawPolyLine{

    _pointIndex = 0;

    _polyline = nil;
    _polylineSymbol = [AGSSimpleLineSymbol simpleLineSymbolWithColor:[UIColor blueColor] width:4];
    [self timerDefination];

}

/**
 *  更新PolyLine,使其绘制出每隔20个点,绘制出独立的线段。
 */
-(void)updatePloyline {

    if(!_mutPointArr || [_mutPointArr count] <= _pointIndex) {
        return;
    }

    if(!_polyline) {
        _polyline = [[AGSMutablePolyline alloc]init];
        [_polyline addPathToPolyline];
    }

//    if(_pointIndex%2 == 0 ){
//        [_polyline addPathToPolyline];
//        
//    }

    [_polyline addPointToPath:_mutPointArr[_pointIndex]];

    if(_pointIndex>0) {
        if(!_graphic) {
            [_graphicLayer removeGraphic:_graphic];
        }

    }

    //设置折线属性
        _graphic = [AGSGraphic graphicWithGeometry:_polyline symbol:_polylineSymbol attributes:nil infoTemplateDelegate:nil];
    [_graphicLayer addGraphic:_graphic];




    _pointIndex++;


}
  • 不使用定时器一次性画出
-(void)drawTrack {

    if(!_mapView || ![_mapView loaded]){
        return;
    }

    NSDictionary* geoJSON = [_polyline encodeToJSON];

    NSString* jsonStr = [geoJSON description];

    _trackDataLine = [AGSPolyline polylineWithJSON:geoJSON];

    NSInteger paths = [_trackDataLine numPaths];
    AGSMutablePolyline* trackLine = [[AGSMutablePolyline alloc]init];
    [trackLine addPathToPolyline];

    for (int path = 0; path < paths; path++) {
        NSInteger numPntOnPath = [_trackDataLine numPointsInPath:path];
        for (int i = 0; i < numPntOnPath; i++) {
            AGSPoint* pnt = [_trackDataLine pointOnPath:path atIndex:i];
            AGSPoint* newPnt = [AGSPoint pointWithX:pnt.x+0.01 y:pnt.y spatialReference:_mapView.spatialReference];
            [trackLine addPointToPath:newPnt];
        }
        [trackLine addPathToPolyline];
    }

    if(![trackLine isEmpty]){
        AGSSimpleLineSymbol* symbol = [AGSSimpleLineSymbol simpleLineSymbolWithColor:[UIColor purpleColor] width:5];
        AGSGraphic* graphic = [AGSGraphic graphicWithGeometry:trackLine symbol:symbol attributes:nil infoTemplateDelegate:nil];
        [_graphicLayer addGraphic:graphic];
    }

    _timer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(updateTrack) userInfo:nil repeats:YES];
    [_timer fire];
}
  • 使用定时器重绘。
-(void)updateTrack{

    if(_currentPath == 0 && _currentIndex == 0){
        [_trackLine addPathToPolyline];
    }

    NSInteger paths = [_trackDataLine numPaths];
    if(_currentPath>= paths){
        [self stopTimer];
        return;
    }
    NSInteger numPntOnPath = [_trackDataLine numPointsInPath:_currentPath];
    if(_currentIndex >= numPntOnPath){
        _currentPath++;
        _currentIndex = 0;
        [_trackLine addPathToPolyline];
        return;
    }else{
        AGSPoint* pnt = [_trackDataLine pointOnPath:_currentPath atIndex:_currentIndex];
        AGSPoint* newPnt = [AGSPoint pointWithX:pnt.x+0.02 y:pnt.y spatialReference:_mapView.spatialReference];
        [_trackLine addPointToPath:newPnt];
        _currentIndex++;
    }

    if(![_trackLine isEmpty]){
        if(_trackGraphic){
            [_graphicLayer removeGraphic:_trackGraphic];
        }

        AGSSimpleLineSymbol* symbol = [AGSSimpleLineSymbol simpleLineSymbolWithColor:[UIColor orangeColor] width:5];
        _trackGraphic = [AGSGraphic graphicWithGeometry:_trackLine symbol:symbol attributes:nil infoTemplateDelegate:nil];
        [_graphicLayer addGraphic:_trackGraphic];
    }
}

END
回家了~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值