Tuesday, 26 November 2019

openlayers 2 - How tow use an ArcGISCache layer along with an ArcGIS93Rest layer?


I want to have two layers in my OpenLayers map. The BaseLayer, as well as the overlay layer are being served by ArcGIS Server.


I have a problem with ArcGIS93Rest when using ArcGISCache as basemap.


The problem is ArcGIS93Rest doesn't show up and there is no HTTP request to the service.


Is it possible to use ArcGISCache and ArcGIS93Rest together?


Here is the code :


var baseLayer = new OpenLayers.Layer.ArcGISCache("AGSCache", "http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer", {

isBaseLayer: true,
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
});
var forestLayer = new OpenLayers.Layer.ArcGIS93Rest("ForestLayer", "http://192.168.1.36:6080/arcgis/rest/services/forest_editing/MapServer/export", {
layers: "0,1,2",
TRANSPARENT: true

});

Answer



I was having problems redrawing the Dynamic map service on every pan & zoom. So to solve this problem, I just called layer.redraw(true);


The important code is as follows:


function init(){
//The max extent for spherical mercator
var maxExtent = new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34);

//Max extent from layerInfo above
var layerMaxExtent = new OpenLayers.Bounds(

layerInfo.fullExtent.xmin,
layerInfo.fullExtent.ymin,
layerInfo.fullExtent.xmax,
layerInfo.fullExtent.ymax
);

var resolutions = [];
for (var i=0; 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(256,256),
projection: mercator,
displayProjection:geographic,
eventListeners: { //set event handler
"moveend": moveEvent}

});

cacheLayer = new OpenLayers.Layer.ArcGISCache( "AGSCache",
"http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer", {
isBaseLayer: true,

//From layerInfo above
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
});

layer = new OpenLayers.Layer.ArcGIS93Rest("ArcGIS Server Layer",
"http://services.arcgisonline.com/ArcGIS/rest/services/Demographics/USA_Median_Home_Value/MapServer/export?transparent=true&",
{layers: "show:0,1,2,3,4", FORMAT:"png24", srs:3857},{singleTile: true});

//add the 2 layers
map.addLayers([cacheLayer, layer]);


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

map.setCenter(new OpenLayers.LonLat(-120, 45).transform(geographic, mercator), 4);

layer.setVisibility(true); //set visibility
}

function moveEvent(event){
layer.redraw(true); //force refresh

}

A working JS fiddle is available here: http://jsfiddle.net/devdatta/rDfUx/3/


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...