[OpenLayers-Users] Fixed Scales & minScale problem

Alexandre Dube adube at mapgears.com
Thu Sep 4 10:29:04 EDT 2008


Hi everybody ( including myself :) ),

  This e-mail is the conclusion of my little problem.  I just want to 
share my solution and at the same time ask what others think about it.

  I wanted to use fixed map scales & minScale & maxScale at the same 
time.  Found out that I couldn't, so instead I specified scales: [25000, 
10000] ( for example ) directly in the layer options and it worked.

  Now, I didn't want to write every scales to every layers.  What if I 
want to change the map scales ?  That would be long to change every 
scales in layers...  So I did this (very simple, but useful) :

=============== code start ==============

/**
 * Method: getScales
 * Returns a array of scales
 *
 * Parameters:
 * nFrom -  integer               The index where to start in map.scales 
array
 * nTo -    integer               The index where to end in map.scales array
 *
 * Returns:
 * {Array}  An array of scales from the map.scales array
 */
OpenLayers.Map.prototype.getScales = function (nFrom, nTo) {
    var aToReturn = new Array();
    var i=0;

    for(nFrom; nFrom<=nTo; nFrom++)
        aToReturn[i++] = this.scales[nFrom];
    return aToReturn;
}

        // map
        var oMapOptions = {
            controls: [], units: 'm', maxResolution: 156543.0339,
            maxExtent: new OpenLayers.Bounds( -1192709.604, -204908.6926,
                                              1172293.7082, 2338511.3665),
            projection: new OpenLayers.Projection("EPSG:32198"),
            numZoomLevels: 11,
            scales: [13000000, 8000000, 4000000, 2000000, 1000000,
                      500000, 250000, 100000, 50000, 25000, 10000]
        };

        oMap = new OpenLayers.Map( 'map', oMapOptions );

        // wfs layer
        olWFSReg = new OpenLayers.Layer.WFS( // 1M, 500K, 250K
            "Régions admin. - WFS", sMSURL,
            { typename: "BDGA_REGIO_S_POLY_1M", map: sBDGAMapPath },
            { extractAttributes: true, typename: "BDGA_REGIO_S_POLY_1M",
              styleMap: oRegStyleMap, scales: oMap.getScales(4,6) });

=============== code end ==============

That's all, folks !

Alexandre

Alexandre Dube wrote:
> Ok, I tried this and it worked :
>
>         olWFSRoads = new OpenLayers.Layer.WFS(
>             "Routes - WFS", sMSURL,
>             { typename: "BDGA_ROUTE_L_ARC", map: sBDGAMapPath },
>             { extractAttributes: true,
>               numZoomLevels: 2, scales: [25000, 10000],      // 
> <----------------------------
>               //minScale: 25000,
>               typename: "BDGA_ROUTE_L_ARC", styleMap: oStyleMap
>             }
>         );
>
> Is this a good workaround ?
>
> Alexandre Dube wrote:
>   
>> I saw this in Layer.js at line 690 ( OL 2.6 )
>>
>> // Do not use the scales/resolutions at the map level if
>> // minScale/minResolution and maxScale/maxResolution are
>> // specified at the layer level
>>
>> Ok ?  But I want to use both.  I don't understand why we can't set a 
>> minScale to a layer at the same time we specify our own scale ranges.  I 
>> mean, I work for some of my layers and other not...  I'm confused !
>>
>> Is there a way around ?
>>
>> Alexandre
>>
>> Alexandre Dube wrote:
>>   
>>     
>>> Hi everybody,
>>>
>>>   I've got a strange behavior in my OL application.  I've got some 
>>> layers with simple params like minScale/maxScale like the following :
>>>
>>> // layer
>>>         olWFSRoads = new OpenLayers.Layer.WFS(
>>>             "Routes - WFS", sMSURL,
>>>             { typename: "BDGA_ROUTE_L_ARC", map: sBDGAMapPath },
>>>             { extractAttributes: true, minScale: 25000,
>>>               typename: "BDGA_ROUTE_L_ARC", styleMap: oStyleMap
>>>             }
>>>         );
>>> // ----------------------------------------
>>>
>>>   I use the following map options :
>>>
>>> // old way
>>>         var oMapOptions = {
>>>             controls: [],
>>>             units: 'm',
>>>             maxResolution: 156543.0339,
>>>             maxExtent: new OpenLayers.Bounds(
>>>                 -1192709.604,
>>>                 -204908.6926,
>>>                 1172293.7082,
>>>                 2338511.3665
>>>             ),
>>>             projection: new OpenLayers.Projection("EPSG:32198")
>>>         };
>>> // ----------------------------------------
>>>
>>>   I want to use more rounded scale numbers, like the following :
>>>
>>> // new way
>>>
>>>         var oMapOptions = {
>>>             controls: [],
>>>             units: 'm',
>>>             maxResolution: 156543.0339,
>>>             maxExtent: new OpenLayers.Bounds(
>>>                 -1192709.604,
>>>                 -204908.6926,
>>>                 1172293.7082,
>>>                 2338511.3665),
>>>             projection: new OpenLayers.Projection("EPSG:32198"),
>>>             numZoomLevels: 11,
>>>             scales:  [13000000, 8000000, 4000000, 2000000, 
>>> 1000000,                   // <---------------
>>>                       500000, 250000, 100000, 50000, 25000, 10000]
>>>         };
>>> // ----------------------------------------
>>>
>>> The problem is, some of my layer loses their minScale value ( like the 
>>> one above, olWFSRoads ).  It's changed to 13000000 as soon as it's added 
>>> to the map !  I have an other WMS layer that does the same thing, and 
>>> some others don't...  But they have the same params.
>>>
>>> Is this a bug or I'm missing something new when I set scales : [...] as 
>>> a new map option ?
>>>
>>>   
>>>     
>>>       
>>   
>>     
>
>
>   


-- 
Alexandre Dubé
Mapgears
www.mapgears.com




More information about the Users mailing list