的OpenLayers 3的ArcGIS缓存服务器本地文件

问题描述:

一些天前,我做了一个ArcGISCache遮阳用的OpenLayers 2.12在此文件夹和文件格式一些瓷砖:的OpenLayers 3的ArcGIS缓存服务器本地文件

_alllayers \ L04 \ R00000009 \ C00000a07.png

这意味着我的瓷砖位于“_alllayers”文件夹内,然后位于其他文件夹内,即缩放级别(L00,L01 ... L21)。在他们里面,我有一些其他文件夹的名称,如:“R00000009”,然后在这些文件夹中,我有名为“C00000a07.png”的图像。

当我做了遮阳板的的OpenLayers 2.12的OpenLayers 2.14我做的很好,作品的权利。但是,当我试图做与OpenLayers 3相同,它不起作用。

的OpenLayers 2.12/2.14的OpenLayers

<!DOCTYPE html> 
<html> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"> 
    <script src="http://maps.google.com/maps/api/js?v=3&amp;sensor=false"></script> 
    <meta name="apple-mobile-web-app-capable" content="yes"> 
    <title>OpenLayers</title> 
    <style> 
    html, body, #map { 
      margin: 0; 
      width: 100%; 
      height: 100%; 
     } 

</style> 
<script src="lib/OpenLayers.2.14.js"></script> 
<script> 
    var map, 
     cacheLayer, 
     testLayer, 
     //This layer requires meta data about the ArcGIS service. Typically you should use a 
     //JSONP call to get this dynamically. For this example, we are just going to hard-code 
     //an example that we got from here (yes, it's very big): 
     // http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer?f=json&pretty=true 
     layerInfo = { 
       "currentVersion" : 10.01, 
       "serviceDescription" : "This worldwide street map presents highway-level data for the world and street-level data for the United States, Canada, Japan, Southern Africa, and a number of countries in Europe and elsewhere. This comprehensive street map includes highways, major roads, minor roads, railways, water features, administrative boundaries, cities, parks, and landmarks, overlaid on shaded relief imagery for added context. The street map was developed by ESRI using ESRI basemap data, AND road data, USGS elevation data, and UNEP-WCMC parks and protected areas for the world, and Tele Atlas Dynamap� and Multinet� street data for North America and Europe. Coverage for street-level data in Europe includes Andorra, Austria, Belgium, Czech Republic, Denmark, France, Germany, Great Britain, Greece, Hungary, Ireland, Italy, Luxembourg, Netherlands, Northern Ireland (Belfast only), Norway, Poland, Portugal, San Marino, Slovakia, Spain, Sweden, and Switzerland. Coverage for street-level data elsewhere in the world includes China (* only), Colombia, Egypt (Cairo only), Indonesia (Jakarta only), Japan, Mexico (Mexico City only), Russia (Moscow and St. Petersburg only), South Africa, Thailand, and Turkey (Istanbul and Ankara only). For more information on this map, visit us \u003ca href=\"http://goto.arcgisonline.com/maps/World_Street_Map \" target=\"_new\"\u003eonline\u003c/a\u003e.", 
       "mapName" : "Layers", 
       "description" : "This worldwide street map presents highway-level data for the world and street-level data for the United States, Canada, Japan, Southern Africa, most countries in Europe, and several other countries. This comprehensive street map includes highways, major roads, minor roads, one-way arrow indicators, railways, water features, administrative boundaries, cities, parks, and landmarks, overlaid on shaded relief imagery for added context. The map also includes building footprints for selected areas in the United States and Europe and parcel boundaries for much of the lower 48 states.\n\nThe street map was developed by ESRI using ESRI basemap data, DeLorme base map layers, AND road data, USGS elevation data, UNEP-WCMC parks and protected areas for the world, Tele Atlas Dynamap� and Multinet� street data for North America and Europe, and First American parcel data for the United States. Coverage for street-level data in Europe includes Andorra, Austria, Belgium, Czech Republic, Denmark, France, Germany, Great Britain, Greece, Hungary, Ireland, Italy, Luxembourg, Netherlands, Norway, Poland, Portugal, San Marino, Slovakia, Spain, Sweden, and Switzerland. Coverage for street-level data elsewhere in the world includes China (* only), Colombia, Egypt (Cairo only), Indonesia (Jakarta only), Japan, Mexico, Russia, South Africa, Thailand, and Turkey (Istanbul and Ankara only). For more information on this map, visit us online at http://goto.arcgisonline.com/maps/World_Street_Map\n", 
       "copyrightText" : "Sources: ESRI, DeLorme, AND, Tele Atlas, First American, ESRI Japan, UNEP-WCMC, USGS, METI, ESRI *, ESRI Thailand, Procalculo Prosis", 
       "layers" : [ 
       { 
        "id" : 0, 
        "name" : "World Street Map", 
        "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" : -20037700, 
        "y" : 30241100 
       }, 
       "spatialReference" : { 
        "wkid" : 102100 
       }, 
       "lods" : [ 
        {'level' : 0, 'resolution' : 156543.03403606807, 'scale' : 591657528}, 
        {'level' : 1, 'resolution' : 78271.517018034036, 'scale' : 295828764}, 
        {'level' : 2, 'resolution' : 39135.758509017018, 'scale' : 147914382}, 
        {'level' : 3, 'resolution' : 19567.879254508509, 'scale' : 73957191}, 
        {'level' : 4, 'resolution' : 9783.9394949623238, 'scale' : 36978595}, 
        {'level' : 5, 'resolution' : 4891.9698797730935, 'scale' : 18489298}, 
        {'level' : 6, 'resolution' : 2445.9849398865467, 'scale' : 9244649}, 
        {'level' : 7, 'resolution' : 1222.992337651342, 'scale' : 4622324}, 
        {'level' : 8, 'resolution' : 611.49616882567102, 'scale' : 2311162}, 
        {'level' : 9, 'resolution' : 305.74808441283551, 'scale' : 1155581}, 
        {'level' : 10, 'resolution' : 152.87417449834899, 'scale' : 577791}, 
        {'level' : 11, 'resolution' : 76.436954957243259, 'scale' : 288895}, 
        {'level' : 12, 'resolution' : 38.218609770552874, 'scale' : 144448}, 
        {'level' : 13, 'resolution' : 19.109304885276437, 'scale' : 72224}, 
        {'level' : 14, 'resolution' : 9.5546524426382184, 'scale' : 36112}, 
        {'level' : 15, 'resolution' : 4.7773262213191092, 'scale' : 18056}, 
        {'level' : 16, 'resolution' : 2.3886631106595546, 'scale' : 9028}, 
        {'level' : 17, 'resolution' : 1.1943315553297773, 'scale' : 4514}, 
        {'level' : 18, 'resolution' : 0.59716577766488865, 'scale' : 2257}, 
        {'level' : 19, 'resolution' : 0.2984505969011938, 'scale' : 1128}, 
        {'level' : 20, 'resolution' : 0.1492252984505969, 'scale' : 564}, 
        {'level' : 21, 'resolution' : 0.061383456100245537, 'scale' : 282} 
       ] 
       }, 
       "initialExtent" : { 
       "xmin" : -20037507.0671618, 
       "ymin" : -20037507.0671618, 
       "xmax" : 20037507.0671618, 
       "ymax" : 20037507.0671619, 
       "spatialReference" : { 
        "wkid" : 102100 
       } 
       }, 
       "fullExtent" : { 
       "xmin" : -20037507.0671618, 
       "ymin" : -20037507.0671618, 
       "xmax" : 20037507.0671618, 
       "ymax" : 20037507.0671619, 
       "spatialReference" : { 
        "wkid" : 102100 
       } 
       }, 
       "units" : "esriMeters", 
       "supportedImageFormatTypes" : "PNG24,PNG,JPG,DIB,TIFF,EMF,PS,PDF,GIF,SVG,SVGZ,AI,BMP", 
       "documentInfo" : { 
       "Title" : "World Street Map", 
       "Author" : "ESRI", 
       "Comments" : "", 
       "Subject" : "streets, highways, major roads, railways, water features, administrative boundaries, cities, parks, protected areas, landmarks ", 
       "Category" : "transportation(Transportation Networks) ", 
       "Keywords" : "World, Global, 2009, Japan, UNEP-WCMC", 
       "Credits" : "" 
       }, 
       "capabilities" : "Map" 
      }; 
    function init() { 
     var maxExtent = new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34); 

     var layerMaxExtent = new OpenLayers.Bounds(
      layerInfo.fullExtent.xmin, 
      layerInfo.fullExtent.ymin, 
      layerInfo.fullExtent.xmax, 
      layerInfo.fullExtent.ymax 
     ); 

     var resolutions = []; 
     for (var i=0; i<layerInfo.tileInfo.lods.length; i++) { 
      resolutions.push(layerInfo.tileInfo.lods[i].resolution); 
     } 

     map = new OpenLayers.Map('map', { 
      maxExtent: maxExtent, 
      StartBounds: layerMaxExtent, 
      units: (layerInfo.units == "esriFeet") ? 'ft' : 'm', 
      resolutions: resolutions, 
      tileSize: new OpenLayers.Size(layerInfo.tileInfo.width, layerInfo.tileInfo.height),     
      projection: 'EPSG:' + layerInfo.spatialReference.wkid 
     }); 

     cacheLayer = new OpenLayers.Layer.ArcGISCache("AGSCache", 
       "http://MY_IP:MY_PORT/MY_FOLDER/Layers/_alllayers", { 
        isBaseLayer: false, 
        useArcGISServer: false,      
        resolutions: resolutions,       
        tileSize: new OpenLayers.Size(layerInfo.tileInfo.cols, layerInfo.tileInfo.rows),       
        tileOrigin: new OpenLayers.LonLat(layerInfo.tileInfo.origin.x , layerInfo.tileInfo.origin.y),       
        maxExtent: layerMaxExtent,       
        projection: 'EPSG:' + layerInfo.spatialReference.wkid 
       }); 

     testLayer = new OpenLayers.Layer.Google(
      "Google Streets", 
      {'sphericalMercator': true, numZoomLevels: 21} 
     ); 

     map.addLayers([cacheLayer, testLayer]); 

     map.addControl(new OpenLayers.Control.LayerSwitcher()); 
     map.addControl(new OpenLayers.Control.MousePosition()); 

     map.zoomToExtent(new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34)); 
    } 
    </script> 
    </head> 
    <body onload="init()"> 
     <div id="map"></div> 
     </body> 
    </html> 

正如我所说的,这工作正常。但是当我尝试在OpenLayers 3上做同样的事情时,我不能。我不知道为什么要求像有服务的图像。

的OpenLayers 3

<!DOCTYPE html> 
<html> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"> 
    <script src="http://maps.google.com/maps/api/js?v=3&amp;sensor=false"></script> 
    <meta name="apple-mobile-web-app-capable" content="yes"> 
    <title>OpenLayers</title> 
    <style> 
    html, body, #map { 
      margin: 0; 
      width: 100%; 
      height: 100%; 
     } 

    </style> 
    <script src="lib/OpenLayers.3.js"></script> 
<script> 
    function init(){ 
     var url = 'http://MY_IP:MY_PORT/MY_FOLDER/Layers/_alllayers'; 

     var layers = [ 
      new ol.layer.Tile({ 
       source: new ol.source.OSM() 
      }), 
      new ol.layer.Tile({ 
       extent: [-20037507.0671618,-20037507.0671618,20037507.0671618,20037507.0671619], 
       source: new ol.source.TileArcGISRest({ 
        url: url 
       }) 
      }) 
     ]; 

     var map = new ol.Map({ 
      layers: layers, 
      target: 'map', 
      view: new ol.View({ 
       center: [-20037700, 30241100], 
       zoom: 1 
      }) 
     }); 
    } 
    </script> 
    </head> 
    <body onload="init()"> 
    <div id="map"></div> 
    </body> 
</html> 

当我尝试加载此的OpenLayers 3遮阳板,我可以在控制台一些404的错误看,这是它试图找到的网址类型:

http://MY_IP:MY_PORT/MY_FOLDER/Layers/_alllayers/?F=image&FORMAT=PNG32&TRANSPARENT=true&SIZE=256%2C256&BBOX=-20037508.342789244%2C0%2C0%2C20037508.342789244&BBOXSR=3857&IMAGESR=3857&DPI=90 

漂亮的打印

http://MY_IP:MY_PORT/MY_FOLDER/Layers/_alllayers/?F=image 
&FORMAT=PNG32 
&TRANSPARENT=true 
&SIZE=256%2C256 
&BBOX=-20037508.342789244%2C0%2C0%2C20037508.342789244 
&BBOXSR=3857 
&IMAGESR=3857 
&DPI=90 

所以,我的问题是:

- 为什么的OpenLayers 3要求的图像(砖)就像是一个服务的背后?

- 我可以在OpenLayers 3中使用我的瓷砖吗?

我试图与这个模式更改URL:

http://MY_IP:MY_PORT/MY_FOLDER/Layers/_alllayers/ImageServer 
http://MY_IP:MY_PORT/MY_FOLDER/Layers/_alllayers/ImageServer/export 
http://MY_IP:MY_PORT/MY_FOLDER/Layers/_alllayers/Tiles/{z}/{x}/{y} 

编辑:

最后我已经解决了!我在Java中创建了一个可以转换所有这些文件夹和图片名称的程序。

我试图理解文件夹和图像名称的模式,最后我意识到文件夹的第一个字母意味着行(R - >行)和图像的第一个字母表示列( C - >栏)。

删除第一个字母后,只需将该数字十六进制转换为十进制,然后用该新名称保存该文件或文件夹即可。

如果有人需要一些帮助,我会很乐意提供帮助。

ol.source.ArcGISRest适用于ArcGIS服务器磁贴服务。对于ArcGISCache,您需要使用带有自定义tileUrlFunctiontileLoadFunctionol.source.TileImageol.source.XYZ。我更喜欢后者,因为那样我就不必转换平铺坐标。类似于

function replacer(match, letter, value) { 
    var str = Number(value).toString(letter == 'L' ? 10 : 16); 
    var len = letter == 'L' ? 2 : 8; 
    while (str.length < len) { 
    str = '0' + str; 
    } 
    return letter + str; 
} 

var source = new ol.source.XYZ({ 
    url: 'http://MY_IP:MY_PORT/MY_FOLDER/Layers/_alllayers/L{z}/R{x}/C{y}.png', 
    tileLoadFunction: function(image, url) { 
    image.getImage().src = url 
     .replace(/(L)([0-9]+)/, replacer) 
     .replace(/(R)([0-9]+)/, replacer) 
     .replace(/(C)([0-9]+)/, replacer); 
    } 
});