Несколько дней назад я сделал ArcGISCache козырька с OpenLayers 2.12 с некоторыми плитки в этой папке и формат файла:OpenLayers 3 ArcGIS Cache Сервер Локальные файлы
_alllayers \ L04 \ R00000009 \ C00000a07.png
Это означает, что мои плитки находятся внутри папки «_alllayers», а затем внутри других папок, что означает Zoom Level (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&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 (Hong Kong 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 (Hong Kong 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 Hong Kong, 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&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 ошибки и это тип URL, который он пытается найти:
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}
Edit:
Наконец я решил! Я создал Java на Java, которая преобразует все имена папок и изображений.
Я пытался понять шаблон, который имеет имена папок и изображений, и, наконец, я понял, что первая буква папок означает строки (R -> row), а первая буква изображений означает столбцы (C ->).
Как только вы удалили первую букву, просто нужно было преобразовать это число с шестнадцатеричным в десятичное число и сохранить файл или папку с этим новым именем.
Если кому-то нужна помощь, я буду рад помочь.