[OpenLayers-Users] Zooming with multiple kamap layers
Alexandre Dube
adube at mapgears.com
Mon Jul 28 10:44:34 EDT 2008
Hi Mike,
Both your layers are base layers. Only one base layer can be displayed
at a time. It is wrong to set the visibility to true to an other base
layer.
Just add isBaseLayer: false to your second layer and it will become an
overlay. Or add the layerSwitcher control to switch the base layer.
Here's your modified code. I use the "get some info" button to help me
keep track of some important infos about my layers. Hope this helps.
Alexandre Dube
Mapgears
adube at mapgears.com
------------------------------------------------------------------
<html>
<head>
<title>OpenLayers Example</title>
<script src="http://www.openlayers.org/api/OpenLayers.js"></script>
<script type="text/javascript">
var map;
function init(){
var options = {
controls: [],
maxExtent: new OpenLayers.Bounds(-180,-90,180,90),
scales:
[100000000,50000000,25000000,10000000,5000000,2500000,1000000],
numZoomLevels: 8,
tileSize: new OpenLayers.Size(200,200),
projection: "EPSG:4326",
units: "dd"
};
map = new OpenLayers.Map('map',options);
var ly1 = new OpenLayers.Layer.KaMap(
"World Map",
"http://clima.ominiverdi.org/ka-map/htdocs/tile.php",
{
i:"JPEG",
map:"cvs",
g:"World Map",
version:"6"
}
);
var ly2 = new OpenLayers.Layer.KaMap(
"Places",
"http://clima.ominiverdi.org/ka-map/htdocs/tile.php",
{
i:"PNG",
map:"cvs",
g:"Places",
version:"6"
},
{
isBaseLayer: false
}
);
map.addLayers([ly1,ly2]);
map.zoomToExtent(new OpenLayers.Bounds(-180,-90,180,90));
map.addControl(new OpenLayers.Control.Navigation());
map.addControl(new OpenLayers.Control.LayerSwitcher());
map.addControl(new OpenLayers.Control.PanZoomBar());
map.addControl(new OpenLayers.Control.MousePosition());
//ly2.setVisibility(true);
}
// Bouton get some info
function disp_alert()
{
var i;
var sToAlert = "";
if (map.layers){
for (i=0;i<map.layers.length;i++) {
sToAlert += i + " : ";
if (map.layers[i].params != null) {
sToAlert += map.layers[i].params.layers + "\n";
}
else if (map.layers[i].isVector) {
sToAlert += "Layer de type Vector" + "\n";
}
sToAlert += " isBaseLayer : " + map.layers[i].isBaseLayer;
sToAlert += " inRange : " + map.layers[i].inRange;
sToAlert += " Visibility : " + map.layers[i].getVisibility();
sToAlert += " Projection : " + map.layers[i].projection;
sToAlert += "\n";
}
}
alert(
"Left : " + map.getExtent().left + "\n" +
"Bottom : " + map.getExtent().bottom + "\n" +
"Right : " + map.getExtent().right + "\n" +
"Top : " + map.getExtent().top + "\n" +
"Scale : " + map.getScale() + "\n" +
"Projection : " + map.getProjection() + "\n" +
"Nb de layers direct : " + map.layers.length + "\n" +
"Map center : " + map.getCenter() + "\n" +
"\n" + sToAlert
);
}
</script>
</head>
<body onload="init()">
<div style="width:50%; height:50%" id="map"></div>
<input type="button" id="disp_alert" onclick="disp_alert()"
value="get some info" />
</body>
</html>
Mike Leahy wrote:
> Ok - here's a better demonstration of this problem. Copy this into an
> html file...open it in a browser, then zoom in. You'll see what I'm
> talking about. This is using the World Map and Places layers from one
> of the ka-map demos hosted by omniverdi.org. Is it something I'm doing
> wrong with the OL code, or maybe a bug in OL's kamap layer object?
>
> Regards,
> Mike
>
> =======================================================================
>
> <html>
> <head>
> <title>OpenLayers Example</title>
> <script
> src="http://www.openlayers.org/api/OpenLayers.js"></script>
> </head>
> <body>
> <div style="width:100%; height:100%" id="map"></div>
> <script defer="defer" type="text/javascript">
> var options = {
> maxExtent: new OpenLayers.Bounds(-180,-90,180,90),
> scales:
> [100000000,50000000,25000000,10000000,5000000,2500000,1000000],
> numZoomLevels: 8,
> tileSize: new OpenLayers.Size(200,200),
> projection: "EPSG:4326",
> units: "dd"
> };
> var map = new OpenLayers.Map('map',options);
>
> var ly1 = new OpenLayers.Layer.KaMap("World Map",
> "http://clima.ominiverdi.org/ka-map/htdocs/tile.php",
> {i:"JPEG",map:"cvs",g:"World Map",version:"6"}
> );
> var ly2 = new OpenLayers.Layer.KaMap("Places",
> "http://clima.ominiverdi.org/ka-map/htdocs/tile.php",
> {i:"PNG",map:"cvs",g:"Places",version:"6"}
> );
>
> map.addLayers([ly1,ly2]);
> map.zoomToExtent(new OpenLayers.Bounds(-180,-90,180,90));
> ly2.setVisibility(true);
> </script>
> </body>
> </html>
>
>
>
>
> Mike Leahy wrote:
>
>> Hello list,
>>
>> I've been working on an application that uses Ka-Map, but I think I
>> might consider adopting OpenLayers for the client-side part. I have
>> been able to setup a map that loads two layers (see sample HTML below).
>> When the map initially starts, I call roads.setVisibility(true);, and
>> I see the roads layer overlaid on top of the aerial photography layer.
>> It looks fine at that point...panning works fine. Once I zoom in or
>> out, however, the base layer (the photography) does what is expected,
>> but the roads layer just defaults to its original extent, and remains at
>> the initial zoom level. Is there something I need to do to tie the
>> roads layer to the zoom event?
>>
>> If this is a known issue, or if I'm just missing something, maybe
>> someone can point me in the right direction. I'm using OpenLayers 2.6
>> (should I try SVN?). The tile.php script is something that I have
>> integrated into my application on the server - it's generally based on
>> the one from kamap (checked out of svn about a month ago), but I don't
>> think it's the source of this issue (i.e., if I make the roads layer the
>> base layer on its own, it works fine).
>>
>> Thanks in advance for any help,
>> Mike
>>
>> ======================================================================
>>
>> <html>
>> <head>
>> <title>OpenLayers Example</title>
>> <script
>> src="https://localhost/application/js/lib/OpenLayers.js"></script>
>> </head>
>> <body>
>> <div style="width:100%; height:100%" id="map"></div>
>> <script defer="defer" type="text/javascript">
>> var options = {
>> maxExtent: new
>> OpenLayers.Bounds(1327479,4883397,1415461,5034462),
>> scales: [200000,150000,100000,75000,50000,25000,10000,5000],
>> numZoomLevels: 8,
>> tileSize: new OpenLayers.Size(400,300),
>> projection: "EPSG:4326",
>> units: "m"
>> };
>> var map = new OpenLayers.Map('map',options);
>> var aerials = new OpenLayers.Layer.KaMap("mymap",
>> "https://localhost/application/tile.php",
>> {layers:"0",i:"AGG_JPEG",map:"mymap",g:"Aerial
>> Photography",sid:"somesessionid"}
>> );
>> var roads = new OpenLayers.Layer.KaMap("mymap",
>> "https://localhost/application/tile.php",
>>
>> {layers:"160",i:"alpha",map:"mymap",g:"Roads",sid:"somesessionid"},
>> {numZoomLevels:8,scales:
>> [200000,150000,100000,75000,50000,25000,10000,5000]}
>> );
>> map.addLayers([aerials,roads]);
>> map.zoomToExtent(new
>> OpenLayers.Bounds(1373558,4988812,1404038,5011460));
>> roads.setVisibility(true);
>> </script>
>> </body>
>> </html>
>>
>>
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>
--
Alexandre Dube'
Mapgears
www.mapgears.com
More information about the Users
mailing list