Google earth WMS view scales

I have had a few emails over the last week who are wanting to increase the usability of my WMS reflector script. One of the items that keeps popping up is the lack of integrating the standard GIS view scales. That is, only certain layers are available at certain scales.

At the application level it is very easy to specify the max/min scales in say Mapserver or Arcims, but this creates more problems inside GE if you are requesting a layer that may not exist.

The workaround isn’t as nice as i would like, but it does the job. We will use the ratio variable as the pseudo-scale factor. The way i calculated a rough “maxscale” was to,

1. Echo $ratio1

[code lang=”PHP”]$ratio1 = ($coords[2] – $coords[0]);
echo $ratio1;[/code]2. Jump to the required zoom level and submit the bbox coordinates inside a browser to grab the echo’d output
3. The first number echo’d (such as 0.00251) is the value we need to add some simple ratio checking (Dont forget to comment the echo in step 1 out else you will get errors inside GE)
4. First create a new array counter $n,

[code lang=”PHP”]$n = 0;[/code]5. When declaring the WMS server arrays add your favourite bit of logic to compare against the ratio and rinse and repeat against all WMS servers in the $WMS array.

[code lang=”PHP”]if ($ratio1 <= 0.0025) {
$name[$n] = "Layername";
$WMS[$n] = “http://…/servlet/com.esri.wms.Esrimap?ServiceName=earth&VERSION=1.1.0&REQUEST=GetMap&SRS=EPSG:4326&WIDTH=”.$width.”&HEIGHT=”.$height.”&LAYERS=layername…”;
$n++;
} [/code] All this extra code will do will use the coordinate ratio to determine whether a server/layer should be accessible. If not, it will not be returned in the KML and so you will have a seamless, intuitive way that WMS layers can be added to GE.Some further avenues of hacking could include,

  • limiting WMS servers to a specific geographic area (ie. only requext layer A if between coords X1,Y1,X2,Y2 and at a ratio less than B)
  • adding an image layer using the WMS getLegendGraphic request to create a dynamic legend for your WMS layers

The original source for this entry can be found here