Local Tiled Layer

Download Sample Application

Local tiled layers display map content from a tile package file that is available locally on your machine. A tile package represents a snapshot of your map at one point in time so the package works well with maps that do not change frequently, such as street maps or terrain. The layer can continue to display map content even when the machine does not have any network connectivity because all the map content is available locally in the tile package.

//get path of tile package
NSString *tilePackagePath = [[NSBundle mainBundle] pathForResource:@"Campus" ofType:@"tpk"];
        
//add local tiled layer to map and set delegate to know when layer loads or fails to load
AGSLocalTiledLayer *localTiledLayer = [AGSLocalTiledLayer localTiledLayerWithPath:tilePackagePath];
localTiledLayer.delegate = self;
[self.mapView addMapLayer:localTiledLayer withName:@"Campus"];

Sample Code

//SWIFT SAMPLE CODE
/*
Copyright 2014 Esri

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import Cocoa
import ArcGIS

class LocalTiledLayerSwiftSample: NSViewController, AGSLayerDelegate {

    @IBOutlet weak var mapView:AGSMapView!
    
    //MARK: - awakeFromNib
    
    // -------------------------------------------------------------------------------
    //  awakeFromNib
    // -------------------------------------------------------------------------------
    override func awakeFromNib() {
    
        //get path of tile package
        let tilePackagePath = NSBundle.mainBundle().pathForResource("Campus", ofType:"tpk")
        
        //add local tiled layer to map and set delegate to know when layer loads or fails to load
        let localTiledLayer = AGSLocalTiledLayer(path: tilePackagePath)
        localTiledLayer.delegate = self
        self.mapView.addMapLayer(localTiledLayer, withName:"Campus")
    }
    
    
    //MARK: - Layer Delegate
    
    // -------------------------------------------------------------------------------
    //  layerDidLoad:layer
    // -------------------------------------------------------------------------------
    func layerDidLoad(layer: AGSLayer!) {
        println("Layer \(layer.name) loaded..")
    }
    
    // -------------------------------------------------------------------------------
    //  layer:didFailToLoadWithError:error
    // -------------------------------------------------------------------------------
    func layer(layer: AGSLayer!, didFailToLoadWithError error: NSError!) {
        if let viewWindow = self.view.window {
            let alert = NSAlert()
            alert.messageText = "Layer '\(layer.name)' failed to load"
            alert.informativeText = error.localizedDescription
            alert.beginSheetModalForWindow(viewWindow, modalDelegate:self, didEndSelector:nil, contextInfo:nil)
        }
    }
    
}
//OBJECTIVE C SAMPLE CODE
/*
 Copyright 2013 Esri
 
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at
 
 http://www.apache.org/licenses/LICENSE-2.0
 
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */

#import "LocalTiledLayerSample.h"

@interface LocalTiledLayerSample ()

@end

@implementation LocalTiledLayerSample

#pragma mark - awakeFromNib

// -------------------------------------------------------------------------------
//  awakeFromNib
// -------------------------------------------------------------------------------
- (void)awakeFromNib {
    
    //get path of tile package
    NSString *tilePackagePath = [[NSBundle mainBundle] pathForResource:@"Campus" ofType:@"tpk"];
    
    //add local tiled layer to map and set delegate to know when layer loads or fails to load
    AGSLocalTiledLayer *localTiledLayer = [AGSLocalTiledLayer localTiledLayerWithPath:tilePackagePath];
    localTiledLayer.delegate = self;
	[self.mapView addMapLayer:localTiledLayer withName:@"Campus"];
}


#pragma mark - Layer Delegate

// -------------------------------------------------------------------------------
//  layerDidLoad:layer
// -------------------------------------------------------------------------------
- (void)layerDidLoad:(AGSLayer *)layer {
    NSLog(@"Layer %@ loaded..",layer.name);
}

// -------------------------------------------------------------------------------
//  layer:didFailToLoadWithError:error
// -------------------------------------------------------------------------------
- (void)layer:(AGSLayer *)layer didFailToLoadWithError:(NSError *)error {
    NSAlert *alert = [[NSAlert alloc] init];
    [alert setMessageText:[NSString stringWithFormat:@"Layer '%@' failed to load",layer.name]];
    [alert setInformativeText:[NSString stringWithFormat:@"%@",error]];
    [alert beginSheetModalForWindow:self.view.window modalDelegate:self didEndSelector:nil contextInfo:nil];
}

@end
//OBJECTIVE C SAMPLE CODE
/*
 Copyright 2013 Esri
 
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at
 
 http://www.apache.org/licenses/LICENSE-2.0
 
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */

#import <Cocoa/Cocoa.h>

@interface LocalTiledLayerSample : NSViewController <AGSLayerDelegate>

@property (strong) IBOutlet AGSMapView *mapView;

@end
Feedback on this topic?