var mapboxAccessToken:String = "1234"; //add your access token here
var layer:AGSMapboxLayer = new AGSMapboxLayer("mapbox.streets", mapboxAccessToken, 21);
Created
February 14, 2015 00:17
-
-
Save kriscarle/4de61b2dae2dfea67217 to your computer and use it in GitHub Desktop.
Mapbox Tiles in ArcGIS Runtime for Flex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.kriscarle.map.util { | |
import com.esri.ags.SpatialReference; | |
import com.esri.ags.geometry.Extent; | |
import com.esri.ags.geometry.MapPoint; | |
import com.esri.ags.layers.TiledMapServiceLayer; | |
import com.esri.ags.layers.supportClasses.LOD; | |
import com.esri.ags.layers.supportClasses.TileInfo; | |
import flash.net.URLRequest; | |
public class AGSMapboxLayer extends com.esri.ags.layers.TiledMapServiceLayer { | |
private var mapboxAPI:String = "https://b.tiles.mapbox.com/v4/"; | |
private var mapID:String; | |
private var mapboxAccessToken:String; | |
private var numLevels:Number = 21; | |
private var _tileInfo:TileInfo = new TileInfo(); | |
public function AGSMapboxLayer(mapID:String, mapboxAccessToken:String, numLevels:Number) { | |
super(); | |
this.mapID = mapID; | |
this.mapboxAccessToken = mapboxAccessToken; | |
this.numLevels = numLevels; | |
_tileInfo.height=256; | |
_tileInfo.width=256; | |
_tileInfo.origin=new MapPoint(-20037508.342787, 20037508.342787); | |
_tileInfo.spatialReference=new SpatialReference(102100); | |
var lods:Array = []; | |
for (var i:Number = 0; i < numLevels; i++) { | |
var resolution:Number = 156543.032 / Math.pow(2, i); | |
var scale:Number = 554678932 / Math.pow(2, i); | |
lods[i] = new LOD(i, resolution, scale); | |
} | |
_tileInfo.lods = lods; | |
setLoaded(true); | |
} | |
override public function get units():String | |
{ | |
return "esriMeters"; | |
} | |
override public function get tileInfo():TileInfo | |
{ | |
return _tileInfo; | |
} | |
override public function get fullExtent():Extent | |
{ | |
return new Extent(-20037508.342787, -20037508.342787, 20037508.342787, 20037508.342787, new SpatialReference(102100)); | |
} | |
override public function get initialExtent():Extent | |
{ | |
return new Extent(-20037508.342787, -20037508.342787, 20037508.342787, 20037508.342787, new SpatialReference(102100)); | |
} | |
override public function get spatialReference():SpatialReference | |
{ | |
return new SpatialReference(102100); | |
} | |
override protected function getTileURL(level:Number, row:Number, col:Number):URLRequest | |
{ | |
var url:String = mapboxAPI + mapID + "/" + level + "/" + col + "/"+ row +".png?access_token=" + mapboxAccessToken; | |
trace(url); | |
return new URLRequest(url); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment