[OpenLayers-Users] Re: overlaying tiled WMS on top of bing

Andreas Hocevar ahocevar at opengeo.org
Thu Jan 26 15:43:31 EST 2012


Hi,

the problem with the maxExtent of an overlay layer is this: if not
configured, the map's maxExtent is used. If not configured on the map,
it defaults to -180, -90, 180, 90. In Web Mercator (EPSG:900913), this
is not the whole world, but a very small area west of Africa. Usually
this results in only one tile being rendered when zoomed to the world
extent, and nothing rendered at all if zoomed to the US.

When working with base maps like Bing or OSM, it is always a good idea
to set the following in the map options:

                maxExtent: new OpenLayers.Bounds(
                    -128 * 156543.03390625,
                    -128 * 156543.03390625,
                    128 * 156543.03390625,
                    128 * 156543.03390625
                ),
                maxResolution: 156543.03390625,
                numZoomLevels: 19,
                units: "m",
                projection: "EPSG:900913"

Then at least layers without a configured maxExtent will be rendered
on the whole world. If you want to restrict the area that users can
view on the map, you can configure the map's restrictedExtent. And for
layers that are not available for the whole world, configure the
layer's maxExtent - like in the fiddle I posted.

Andreas.

On Thu, Jan 26, 2012 at 8:50 PM, Kjel Anderson
<kanderson at truevectortech.com> wrote:
> That's awesome and super helpful. I'm still not sure where I went wrong. I
> believe that I did incorporate your maxExtent bit. Can you enlighten me? Or
> point me to a resource that can help me understand?
>
>
> On Thu, Jan 26, 2012 at 11:47 AM, Andreas Hocevar <ahocevar at opengeo.org>
> wrote:
>>
>> You didn't make the changes that we recommended. The key to solving
>> this is the maxExtent on the WMS layer. Here's a fiddle with a
>> simplified version of your code and your layer, to show that it works:
>> http://jsfiddle.net/ZVaXh/
>>
>> It doesn't matter if it's Bing or OSM, you have to configure your WMS
>> layer the right way.
>>
>> Andreas.
>>
>> On Thu, Jan 26, 2012 at 8:35 PM, Kjel Anderson
>> <kanderson at truevectortech.com> wrote:
>> > You know, Bing is incidental in this whole thing. I'd rather be using
>> > OSM as
>> > the background layer but I couldn't get that to work at all. Does anyone
>> > have a working example of this with any base layer?
>> >
>> >
>> > On Thu, Jan 26, 2012 at 11:32 AM, Kjel Anderson
>> > <kanderson at truevectortech.com> wrote:
>> >>
>> >> That's still not doing it but I'm noticing that the layers turns on
>> >> when I
>> >> pan to the edge of the map. What controls that?
>> >>
>> >>
>> >> On Thu, Jan 26, 2012 at 11:28 AM, Andreas Hocevar
>> >> <ahocevar at opengeo.org>
>> >> wrote:
>> >>>
>> >>> You still forgot to set the maxExtent on your WMS layer!
>> >>>
>> >>> Andreas.
>> >>>
>> >>> On Thu, Jan 26, 2012 at 8:11 PM, Kjel Anderson
>> >>> <kanderson at truevectortech.com> wrote:
>> >>> > Hmmm. No dice with these changes incorporated. I'm not sure what is
>> >>> > going
>> >>> > on. For the curious there is a live link here:
>> >>> >
>> >>> > http://truevector.skygone.net:8080/DWTEdstest/
>> >>> >
>> >>> >
>> >>> > On Thu, Jan 26, 2012 at 10:50 AM, Andreas Hocevar
>> >>> > <ahocevar at opengeo.org>
>> >>> > wrote:
>> >>> >>
>> >>> >> Hi,
>> >>> >>
>> >>> >> you put most layer options in the layer params object, and you
>> >>> >> should
>> >>> >> set the maxExtent on the WMS layer. Something like
>> >>> >>
>> >>> >>            tiled = new OpenLayers.Layer.WMS(
>> >>> >>                "dwt_lata_proj - Untiled",
>> >>> >> "http://localhost:8080/geoserver/wms",
>> >>> >>                {
>> >>> >>                    layers: 'DWT:dwt_lata_proj',
>> >>> >>                    styles: '',
>> >>> >>                    format: format,
>> >>> >>                    transparent:true,
>> >>> >>                }, {
>> >>> >>                    numZoomLevels:19,
>> >>> >>                    maxExtent: new OpenLayers.Bounds(
>> >>> >>                        -19840232, 2028971.375,
>> >>> >>                        -7262943, 11534410
>> >>> >>                    ),
>> >>> >>                    minResolution:0.5971642833948135,
>> >>> >>                    maxResolution:156543.03390625,
>> >>> >>                    singleTile: true,
>> >>> >>                    ratio: 1
>> >>> >>                }
>> >>> >>            );
>> >>> >>
>> >>> >> The above should work both with singleTile: true and without.
>> >>> >>
>> >>> >> Andreas.
>> >>> >>
>> >>> >> On Thu, Jan 26, 2012 at 7:44 PM, Kjel Anderson
>> >>> >> <kanderson at truevectortech.com> wrote:
>> >>> >> > Looking at it now I see the version that is working "best" is
>> >>> >> > with
>> >>> >> > the
>> >>> >> > wms
>> >>> >> > layer being untiled.
>> >>> >> >
>> >>> >> >   function init(){
>> >>> >> >                 // if this is just a coverage or a group of them,
>> >>> >> > disable a
>> >>> >> > few items,
>> >>> >> >                 // and default to jpeg format
>> >>> >> >                 format = 'image/png';
>> >>> >> >
>> >>> >> >
>> >>> >> >                 var bounds = new OpenLayers.Bounds(
>> >>> >> >                     -19840232, 2028971.375,
>> >>> >> >                     -7262943, 11534410
>> >>> >> >                 );
>> >>> >> >                 var options = {
>> >>> >> >                     controls: [],
>> >>> >> >                     maxResolution: 49130.03515625,
>> >>> >> >                     projection: "EPSG:900913",
>> >>> >> >                     units: 'm'
>> >>> >> >                 };
>> >>> >> >                 map = new OpenLayers.Map('map', options);
>> >>> >> >
>> >>> >> >             var road = new OpenLayers.Layer.Bing({
>> >>> >> >                 name: "Road",
>> >>> >> >                 key: apiKey,
>> >>> >> >                 type: "Road"
>> >>> >> >             });
>> >>> >> >             var hybrid = new OpenLayers.Layer.Bing({
>> >>> >> >                 name: "Hybrid",
>> >>> >> >                 key: apiKey,
>> >>> >> >                 type: "AerialWithLabels"
>> >>> >> >             });
>> >>> >> >             var aerial = new OpenLayers.Layer.Bing({
>> >>> >> >                 name: "Aerial",
>> >>> >> >                 key: apiKey,
>> >>> >> >                 type: "Aerial"
>> >>> >> >             });
>> >>> >> >
>> >>> >> >             map.addLayers([road, hybrid, aerial]);
>> >>> >> >
>> >>> >> >             tiled = new OpenLayers.Layer.WMS(
>> >>> >> >                 "dwt_lata_proj - Untiled",
>> >>> >> > "http://localhost:8080/geoserver/wms",
>> >>> >> >                 {
>> >>> >> >                     width: '512',
>> >>> >> >                     srs: 'EPSG:900913',
>> >>> >> >                     layers: 'DWT:dwt_lata_proj',
>> >>> >> >                     height: '386',
>> >>> >> >                     styles: '',
>> >>> >> >                     format: format,
>> >>> >> >                     transparent:true,
>> >>> >> >                     numZoomLevels:19,
>> >>> >> >                     minResolution:0.5971642833948135,
>> >>> >> >                     maxResolution:156543.03390625
>> >>> >> >                 },
>> >>> >> >                 {singleTile: true, ratio: 1}
>> >>> >> >             );
>> >>> >> >
>> >>> >> >             map.addLayer(untiled);
>> >>> >> >
>> >>> >> >             // build up all controls
>> >>> >> >             map.addControl(new OpenLayers.Control.PanZoomBar({
>> >>> >> >                 position: new OpenLayers.Pixel(2, 15)
>> >>> >> >             }));
>> >>> >> >             map.addControl(new OpenLayers.Control.Navigation());
>> >>> >> >             map.addControl(new
>> >>> >> > OpenLayers.Control.Scale($('scale')));
>> >>> >> >             map.addControl(new
>> >>> >> > OpenLayers.Control.MousePosition({element:
>> >>> >> > $('location')}));
>> >>> >> >             map.addControl(new
>> >>> >> > OpenLayers.Control.LayerSwitcher());
>> >>> >> >
>> >>> >> > On Thu, Jan 26, 2012 at 10:33 AM, maw269 <maw269 at gmail.com>
>> >>> >> > wrote:
>> >>> >> >>
>> >>> >> >> Is your bing layer imagery? I've had nothing but issues
>> >>> >> >> combining
>> >>> >> >> layers
>> >>> >> >> with
>> >>> >> >> Bing Imagery layers.
>> >>> >> >> Anyhow, can you post the relevant code so we could take a look?
>> >>> >> >> --Matt
>> >>> >> >>
>> >>> >> >> --
>> >>> >> >> View this message in context:
>> >>> >> >>
>> >>> >> >>
>> >>> >> >>
>> >>> >> >> http://osgeo-org.1560.n6.nabble.com/overlaying-tiled-WMS-on-top-of-bing-tp4341145p4341275.html
>> >>> >> >> Sent from the OpenLayers Users mailing list archive at
>> >>> >> >> Nabble.com.
>> >>> >> >> _______________________________________________
>> >>> >> >> Users mailing list
>> >>> >> >> Users at lists.osgeo.org
>> >>> >> >> http://lists.osgeo.org/mailman/listinfo/openlayers-users
>> >>> >> >
>> >>> >> >
>> >>> >> >
>> >>> >> > _______________________________________________
>> >>> >> > Users mailing list
>> >>> >> > Users at lists.osgeo.org
>> >>> >> > http://lists.osgeo.org/mailman/listinfo/openlayers-users
>> >>> >> >
>> >>> >>
>> >>> >>
>> >>> >>
>> >>> >> --
>> >>> >> Andreas Hocevar
>> >>> >> OpenGeo - http://opengeo.org/
>> >>> >> Expert service straight from the developers.
>> >>> >
>> >>> >
>> >>> >
>> >>> > _______________________________________________
>> >>> > Users mailing list
>> >>> > Users at lists.osgeo.org
>> >>> > http://lists.osgeo.org/mailman/listinfo/openlayers-users
>> >>> >
>> >>>
>> >>>
>> >>>
>> >>> --
>> >>> Andreas Hocevar
>> >>> OpenGeo - http://opengeo.org/
>> >>> Expert service straight from the developers.
>> >>
>> >>
>> >
>>
>>
>>
>> --
>> Andreas Hocevar
>> OpenGeo - http://opengeo.org/
>> Expert service straight from the developers.
>
>
>
> _______________________________________________
> Users mailing list
> Users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/openlayers-users
>



-- 
Andreas Hocevar
OpenGeo - http://opengeo.org/
Expert service straight from the developers.


More information about the Users mailing list