adding ArcGIS (AGS) Tile Cache Layer, great contribution from Azavea, thanks, p=dmiddlecamp, r=me (closes #3030)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@11693 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
bartvde
2011-03-11 00:54:25 +00:00
parent c0ae33e457
commit 3ce239208f
8 changed files with 1452 additions and 0 deletions

View File

@@ -0,0 +1,208 @@
<html>
<head>
<script src="../../lib/OpenLayers.js"></script>
<script src="../../lib/OpenLayers/Layer/ArcGISCache.js" type="text/javascript"></script>
<script src="ArcGISCache.json" type="text/javascript"></script>
<script type="text/javascript">
var isMozilla = (navigator.userAgent.indexOf("compatible") == -1);
var layer;
var name = 'Test Layer';
var url = "http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer";
var options = { };
function test_Layer_ARCGISCACHE_constructor (t) {
t.plan( 1 );
var layer = new OpenLayers.Layer.ArcGISCache(name, url, options);
t.ok( layer instanceof OpenLayers.Layer.ArcGISCache, "returns OpenLayers.Layer.ArcGISCache object" );
}
function test_Layer_ARCGISCACHE_autoConfigure (t) {
t.plan( 5 );
var layerInfo = capabilitiesObject;
//initialize the layer using the JSON object from an arcgis server
//SEE: ArcGISCache.json
var layer = new OpenLayers.Layer.ArcGISCache(name, url, {
layerInfo: layerInfo
});
t.ok( layer instanceof OpenLayers.Layer.ArcGISCache, "returns OpenLayers.Layer.ArcGISCache object" );
t.ok( layer.projection = 'EPSG:' + layerInfo.spatialReference.wkid, "projection is set correctly");
t.ok( layer.units = 'm', "map units are set correctly");
t.ok( layer.resolutions && layer.resolutions.length == 20, "resolutions are initialized from LOD objects properly");
if (layerInfo.tileInfo) {
if (layerInfo.tileInfo.width && layerInfo.tileInfo.height) {
var tileSize = new OpenLayers.Size(layerInfo.tileInfo.width, layerInfo.tileInfo.height);
t.ok((layer.tileSize.width == tileSize.width) && (layer.tileSize.height == tileSize.height), "tile size is set properly");
}
else {
var tileSize = new OpenLayers.Size(layerInfo.tileInfo.cols, layerInfo.tileInfo.rows);
t.ok((layer.tileSize.width == tileSize.width) && (layer.tileSize.height == tileSize.height), "tile size is set properly");
}
}
}
/**
* lets make sure we're getting the correct urls back with a basic auto-configure setup
*/
function test_Layer_ARCGISCACHE_autoConfigure_URLS(t) {
var layerInfo = capabilitiesObject;
//initialize the layer using the JSON object from an arcgis server
//SEE: ArcGISCache.json
var layer = new OpenLayers.Layer.ArcGISCache(name, url, {
layerInfo: layerInfo
});
var map = new OpenLayers.Map('map', {
maxExtent: layer.maxExtent,
units: layer.units,
resolutions: layer.resolutions,
numZoomLevels: layer.numZoomLevels,
tileSize: layer.tileSize,
projection: layer.displayProjection,
StartBounds: layer.initialExtent
});
map.addLayers([layer]);
//this set represents a few edge cases, and some more specific cases, it is by no means exhaustive,
var urlSets = [
{
bounds: new OpenLayers.Bounds(-36787612.973083,-22463925.368666, 43362420.398053,17611091.316902),
url: "http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer/tile/0/0/0"
},
{
bounds: new OpenLayers.Bounds(-31793889.951914,4589319.785415, 8281126.733654,24626828.128199),
url: "http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer/tile/1/0/0"
},
{
bounds: new OpenLayers.Bounds(-24639873.181971,12676071.933457, -4602364.839187,22694826.104849),
url: "http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer/tile/2/0/0"
},
{
bounds: new OpenLayers.Bounds(-15521241.455665,11580270.695961, 4516266.887119,21599024.867353),
url: "http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer/tile/2/0/1"
},
{
bounds: new OpenLayers.Bounds(-9265879.5435993,2870892.9335638, -8639707.4078873,3183979.0014198) ,
url: "http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer/tile/7/54/35"
},
{
bounds: new OpenLayers.Bounds(-10741909.131798,4684560.1640365, -10585366.09787,4762831.6810005),
url: "http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer/tile/9/195/119"
},
{
bounds: new OpenLayers.Bounds(-13668958.106938,4456961.2611504, -13512415.07301,4535232.7781144),
url: "http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer/tile/9/198/82"
}
];
t.plan( urlSets.length );
for(var i=0;i<urlSets.length;i++)
{
var o = urlSets[i];
map.zoomToExtent(o.bounds, true);
var resultUrl = layer.getURL(o.bounds);
t.ok( resultUrl == o.url, "correct tile returned for " + o.bounds);
}
}
/**
* Test the formatting for the 'direct' urls, especially when not auto-configuring the layer
*/
function test_Layer_ARCGISCACHE_direct(t) {
var roadsUrl = 'http://serverx.esri.com/arcgiscache/DG_County_roads_yesA_backgroundDark/Layers/_alllayers';
var urlSets = [
{
bounds: new OpenLayers.Bounds(289244.67443386,4317153.7421985, 306178.04163392,4325620.4257985),
url: roadsUrl + "/L00/R0000029e/C0000027f.png"
},
{
bounds: new OpenLayers.Bounds(308658.51534463,4303230.0164352, 325591.88254469,4311696.7000352),
url: roadsUrl + "/L00/R000002a0/C00000282.png"
},
{
bounds: new OpenLayers.Bounds(311136.39626998,4318933.8711555, 311678.26402038,4319204.8050307) ,
url: roadsUrl + "/L05/R000051e0/C00004e52.png"
}
];
t.plan( urlSets.length );
//perform the exact setup from the arcgiscache_direct example
// First 4 variables extracted from conf.xml file
// Tile layers & map MUST have same projection
var proj='EPSG:26915';
// Layer can also accept serverResolutions array
// to deal with situation in which layer resolution array & map resolution
// array are out of sync
var mapResolutions = [33.0729828126323,16.9333672000677,8.46668360003387,4.23334180001693,2.11667090000847,1.05833545000423];
// For this example this next line is not really needed, 256x256 is default.
// However, you would need to change this if your layer had different tile sizes
var tileSize = new OpenLayers.Size(256,256);
// Tile Origin is required unless it is the same as the implicit map origin
// which can be effected by several variables including maxExtent for map or base layer
var agsTileOrigin = new OpenLayers.LonLat(-5120900,9998100);
// This can really be any valid bounds that the map would reasonably be within
var mapExtent = new OpenLayers.Bounds(289310.8204,4300021.937,314710.8712,4325421.988);
var map = new OpenLayers.Map('map', {
maxExtent:mapExtent,
controls: [
new OpenLayers.Control.Navigation(),
new OpenLayers.Control.LayerSwitcher(),
new OpenLayers.Control.PanZoomBar(),
new OpenLayers.Control.MousePosition()]
});
var layer = new OpenLayers.Layer.ArcGISCache('Roads', roadsUrl, {
tileOrigin: agsTileOrigin,
resolutions: mapResolutions,
sphericalMercator: true,
maxExtent: mapExtent,
useArcGISServer: false,
isBaseLayer: true,
projection: proj
});
map.addLayers([layer]);
map.zoomToExtent(new OpenLayers.Bounds(-8341644, 4711236, -8339198, 4712459));
for(var i=0;i<urlSets.length;i++)
{
var o = urlSets[i];
map.zoomToExtent(o.bounds, true);
var resultUrl = layer.getURL(o.bounds);
t.ok( resultUrl == o.url, "correct tile returned for " + o.bounds);
}
}
/**
* Check our utility function for generating tile indexes against a file cache
*/
function test_Layer_ARCGISCACHE_zeroPad(t) {
t.plan(4);
var layer = new OpenLayers.Layer.ArcGISCache('test', null, { });
//some tile examples
t.ok('00000001' == layer.zeroPad(1, 8, 16), 'zeroPad should generate tile indexes properly ');
t.ok('00000020' == layer.zeroPad(32, 8, 16), 'zeroPad should generate tile indexes properly ');
t.ok('00000100' == layer.zeroPad(256, 8, 16), 'zeroPad should generate tile indexes properly ');
t.ok('00001000' == layer.zeroPad(4096, 8, 16), 'zeroPad should generate tile indexes properly ');
}
</script>
</head>
<body>
<div id="map" style="width:500px;height:550px;"></div>
</body>
</html>

View File

@@ -0,0 +1,334 @@
var capabilitiesObject = {
"currentVersion" : 10.01,
"serviceDescription" : "This map is designed to be used as a base map by GIS professionals and as a reference map by anyone. The base map includes administrative boundaries, cities, water features, physiographic features, parks, landmarks, highways, roads, railways, airports, and buildings overlaid on land cover and shaded relief imagery for added context. The map was compiled from a variety of best available sources from several data providers, including the U.S. Geological Survey, Food and Agriculture Organization of the United Nations, National Park Service, Tele Atlas, AND, and ESRI. The base map currently provides coverage for the world down to a scale of ~1:1m and coverage for the continental United States and Hawaii to a scale of ~1:20k. The base map also includes detailed maps for selected cities in the United States including Portland, Oregon and Philadephia, Pennsylvania. The base map was designed and developed by ESRI based on the topographic map templates that are available through the ArcGIS Resource Centers. For more information on this map, visit us \u003ca href=\"http://goto.arcgisonline.com/maps/World_Topo_Map \" target=\"_new\"\u003eonline\u003c/a\u003e.",
"mapName" : "Layers",
"description" : "This map is designed to be used as a base map by GIS professionals and as a reference map by anyone. The base map includes administrative boundaries, cities, water features, physiographic features, parks, landmarks, highways, roads, railways, airports, and buildings overlaid on land cover and shaded relief imagery for added context. The map was compiled from a variety of best available sources from several data providers, including the U.S. Geological Survey, Food and Agriculture Organization of the United Nations, National Park Service, Tele Atlas, AND, and ESRI. The base map currently provides coverage for the world down to a scale of ~1:1m and coverage for the continental United States and Hawaii to a scale of ~1:20k. The base map also includes detailed maps for selected cities in the United States including Portland, Oregon and Philadephia, Pennsylvania. The base map was designed and developed by ESRI based on the topographic map templates that are available through the ArcGIS Resource Centers. For more information on this map, visit us online at http://goto.arcgisonline.com/maps/World_Topo_Map",
"copyrightText" : "Sources: USGS, FAO, NPS, EPA, ESRI, DeLorme, TANA, other suppliers",
"layers" : [
{
"id" : 0,
"name" : "Topographic Info",
"parentLayerId" : -1,
"defaultVisibility" : true,
"subLayerIds" : [1, 2, 3, 4],
"minScale" : 0,
"maxScale" : 0
},
{
"id" : 1,
"name" : "Elevation (m)",
"parentLayerId" : 0,
"defaultVisibility" : true,
"subLayerIds" : null,
"minScale" : 0,
"maxScale" : 0
},
{
"id" : 2,
"name" : "Elevation (ft)",
"parentLayerId" : 0,
"defaultVisibility" : true,
"subLayerIds" : null,
"minScale" : 0,
"maxScale" : 0
},
{
"id" : 3,
"name" : "Slope",
"parentLayerId" : 0,
"defaultVisibility" : true,
"subLayerIds" : null,
"minScale" : 0,
"maxScale" : 0
},
{
"id" : 4,
"name" : "Aspect",
"parentLayerId" : 0,
"defaultVisibility" : true,
"subLayerIds" : null,
"minScale" : 0,
"maxScale" : 0
},
{
"id" : 5,
"name" : "Places Info",
"parentLayerId" : -1,
"defaultVisibility" : true,
"subLayerIds" : [6, 7, 8, 9],
"minScale" : 0,
"maxScale" : 0
},
{
"id" : 6,
"name" : "Place Names (Country Level)",
"parentLayerId" : 5,
"defaultVisibility" : true,
"subLayerIds" : null,
"minScale" : 0,
"maxScale" : 80000000
},
{
"id" : 7,
"name" : "Place Names (State Level)",
"parentLayerId" : 5,
"defaultVisibility" : true,
"subLayerIds" : null,
"minScale" : 80000001,
"maxScale" : 1500000
},
{
"id" : 8,
"name" : "Place Names (County Level)",
"parentLayerId" : 5,
"defaultVisibility" : true,
"subLayerIds" : null,
"minScale" : 1500001,
"maxScale" : 400000
},
{
"id" : 9,
"name" : "Place Names (City Level)",
"parentLayerId" : 5,
"defaultVisibility" : true,
"subLayerIds" : null,
"minScale" : 399999,
"maxScale" : 0
},
{
"id" : 10,
"name" : "Scale Descriptions",
"parentLayerId" : -1,
"defaultVisibility" : true,
"subLayerIds" : [11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26],
"minScale" : 0,
"maxScale" : 0
},
{
"id" : 11,
"name" : "Level 15 ~1:18K",
"parentLayerId" : 10,
"defaultVisibility" : true,
"subLayerIds" : null,
"minScale" : 25000,
"maxScale" : 15001
},
{
"id" : 12,
"name" : "Level 14 ~1:36K",
"parentLayerId" : 10,
"defaultVisibility" : true,
"subLayerIds" : null,
"minScale" : 50000,
"maxScale" : 25001
},
{
"id" : 13,
"name" : "Level 13 ~1:72K",
"parentLayerId" : 10,
"defaultVisibility" : true,
"subLayerIds" : null,
"minScale" : 100000,
"maxScale" : 50001
},
{
"id" : 14,
"name" : "Level 12 ~1:144K",
"parentLayerId" : 10,
"defaultVisibility" : true,
"subLayerIds" : null,
"minScale" : 288000,
"maxScale" : 100000
},
{
"id" : 15,
"name" : "Level 11 ~1:288K",
"parentLayerId" : 10,
"defaultVisibility" : true,
"subLayerIds" : null,
"minScale" : 575000,
"maxScale" : 288000
},
{
"id" : 16,
"name" : "Level 10 ~1:577K",
"parentLayerId" : 10,
"defaultVisibility" : true,
"subLayerIds" : null,
"minScale" : 1150000,
"maxScale" : 575000
},
{
"id" : 17,
"name" : "Level 9 ~1:1.15M",
"parentLayerId" : 10,
"defaultVisibility" : true,
"subLayerIds" : null,
"minScale" : 2200000,
"maxScale" : 1150000
},
{
"id" : 18,
"name" : "Level 8 ~1:2.3M",
"parentLayerId" : 10,
"defaultVisibility" : true,
"subLayerIds" : null,
"minScale" : 4500000,
"maxScale" : 2200000
},
{
"id" : 19,
"name" : "Level 7 ~1:4.5M",
"parentLayerId" : 10,
"defaultVisibility" : true,
"subLayerIds" : null,
"minScale" : 9000000,
"maxScale" : 4500000
},
{
"id" : 20,
"name" : "Level 6 ~1:9.2M",
"parentLayerId" : 10,
"defaultVisibility" : true,
"subLayerIds" : null,
"minScale" : 18000000,
"maxScale" : 9000000
},
{
"id" : 21,
"name" : "Level 5 ~1:18M ",
"parentLayerId" : 10,
"defaultVisibility" : true,
"subLayerIds" : null,
"minScale" : 36000000,
"maxScale" : 18000000
},
{
"id" : 22,
"name" : "Level 4 ~1:36M",
"parentLayerId" : 10,
"defaultVisibility" : true,
"subLayerIds" : null,
"minScale" : 72000000,
"maxScale" : 36000000
},
{
"id" : 23,
"name" : "Level 3 ~1:72M",
"parentLayerId" : 10,
"defaultVisibility" : true,
"subLayerIds" : null,
"minScale" : 75500000,
"maxScale" : 70000000
},
{
"id" : 24,
"name" : "Level 2 ~1:147M",
"parentLayerId" : 10,
"defaultVisibility" : true,
"subLayerIds" : null,
"minScale" : 290000000,
"maxScale" : 147000000
},
{
"id" : 25,
"name" : "Level 1 ~1:292M",
"parentLayerId" : 10,
"defaultVisibility" : true,
"subLayerIds" : null,
"minScale" : 295000000,
"maxScale" : 150000000
},
{
"id" : 26,
"name" : "Level 0 ~1:584M",
"parentLayerId" : 10,
"defaultVisibility" : true,
"subLayerIds" : null,
"minScale" : 0,
"maxScale" : 295000000
},
{
"id" : 27,
"name" : "Citations",
"parentLayerId" : -1,
"defaultVisibility" : true,
"subLayerIds" : null,
"minScale" : 0,
"maxScale" : 0
}
],
"tables" : [
],
"spatialReference" : {
"wkid" : 102100
},
"singleFusedMapCache" : true,
"tileInfo" : {
"rows" : 256,
"cols" : 256,
"dpi" : 96,
"format" : "JPEG",
"compressionQuality" : 90,
"origin" : {
"x" : -20037508.342787,
"y" : 20037508.342787
},
"spatialReference" : {
"wkid" : 102100
},
"lods" : [
{"level" : 0, "resolution" : 156543.033928, "scale" : 591657527.591555},
{"level" : 1, "resolution" : 78271.5169639999, "scale" : 295828763.795777},
{"level" : 2, "resolution" : 39135.7584820001, "scale" : 147914381.897889},
{"level" : 3, "resolution" : 19567.8792409999, "scale" : 73957190.948944},
{"level" : 4, "resolution" : 9783.93962049996, "scale" : 36978595.474472},
{"level" : 5, "resolution" : 4891.96981024998, "scale" : 18489297.737236},
{"level" : 6, "resolution" : 2445.98490512499, "scale" : 9244648.868618},
{"level" : 7, "resolution" : 1222.99245256249, "scale" : 4622324.434309},
{"level" : 8, "resolution" : 611.49622628138, "scale" : 2311162.217155},
{"level" : 9, "resolution" : 305.748113140558, "scale" : 1155581.108577},
{"level" : 10, "resolution" : 152.874056570411, "scale" : 577790.554289},
{"level" : 11, "resolution" : 76.4370282850732, "scale" : 288895.277144},
{"level" : 12, "resolution" : 38.2185141425366, "scale" : 144447.638572},
{"level" : 13, "resolution" : 19.1092570712683, "scale" : 72223.819286},
{"level" : 14, "resolution" : 9.55462853563415, "scale" : 36111.909643},
{"level" : 15, "resolution" : 4.77731426794937, "scale" : 18055.954822},
{"level" : 16, "resolution" : 2.38865713397468, "scale" : 9027.977411},
{"level" : 17, "resolution" : 1.19432856685505, "scale" : 4513.988705},
{"level" : 18, "resolution" : 0.597164283559817, "scale" : 2256.994353},
{"level" : 19, "resolution" : 0.298582141647617, "scale" : 1128.497176}
]
},
"initialExtent" : {
"xmin" : -45223792.233066,
"ymin" : -22882589.2065154,
"xmax" : 45223792.233066,
"ymax" : 22882589.2065155,
"spatialReference" : {
"wkid" : 102100
}
},
"fullExtent" : {
"xmin" : -20037507.0671618,
"ymin" : -19971868.8804086,
"xmax" : 20037507.0671618,
"ymax" : 19971868.8804086,
"spatialReference" : {
"wkid" : 102100
}
},
"units" : "esriMeters",
"supportedImageFormatTypes" : "PNG24,PNG,JPG,DIB,TIFF,EMF,PS,PDF,GIF,SVG,SVGZ,AI,BMP",
"documentInfo" : {
"Title" : "World Topo Map",
"Author" : "ESRI",
"Comments" : "",
"Subject" : "",
"Category" : "",
"Keywords" : "",
"Credits" : ""
},
"capabilities" : "Map,Query,Data"
};

View File

@@ -133,6 +133,7 @@
<li>Layer.html</li>
<li>Layer/ArcIMS.html</li>
<li>Layer/ArcGIS93Rest.html</li>
<li>Layer/ArcGISCache.html</li>
<li>Layer/Bing.html</li>
<li>Layer/EventPane.html</li>
<li>Layer/FixedZoomLevels.html</li>