0

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
});
  • Currently I'm having a hard time understanding what you are doing. IS your ArcGIS Map Service cached? What is the version of the ArcGIS Server? And why do you want to use both? If you tell us what you are trying to achieve, we'll be better placed to help you. – Devdatta Tengshe Sep 24 '13 at 3:23
  • @DevdattaTengshe Okay. One is ArcGIS Map Service cached and the other is dynamic Map. – OammieR Sep 24 '13 at 3:48
  • I've been able to get both the layers to display, but there is still some problem, since the layer seem to jump around. Once I've a proper example, I'll post it here. – Devdatta Tengshe Sep 24 '13 at 5:37
  • Just wanted to warn you, that I'm not sure why this weird behavior was happening; It is possible that my answer might be a hack, at best. If I were you, I would also post this to the OpenLayers mailing list. – Devdatta Tengshe Sep 24 '13 at 7:17
2

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<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(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/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.