[OpenLayers-Users] Controls not working

Eric Lemoine eric.c2c at gmail.com
Wed Apr 2 02:43:47 EDT 2008


On Wed, Apr 2, 2008 at 2:04 AM, G. Paolo Sanino V.
<research at leviathanchile.org> wrote:
> Hi All,
>
>  I am new at OpenLayers and I think this is awesome. I am trying to build a
>  small GIS for an ONG using the same layers used on the Openlayers homepage.
>  The big step will be to connect it to a database to store the markers. But in
>  a later step.
>  I am so sorry to bother you with such a question. It may be very simple but I
>  have had nightmares looking for a solution... Here is my problem:
>
>  I have gotten two layers working using "map.addlayer()" for each layer instead
>  of using "map.addlayers()" for all. I do not know why, if I use "AddLayers",
>  I only get a blank map (white) with only the blue buttons on the left up
>  corner.

Doesn't "map.addLayers([jpl_wms, ol_wms]);" work?

>  Also, and maybe related, I got the center and zoom of the map working,
>  however, the next controls do not work/show in the map:
>  ScaleLine, MousePosition, OverviewMap.
>
>  Here is my code (from: http://www.cmmrleviathan.org/ciencia_GIS2.htm):
>
>  <script type="text/javascript">
>  var map, ol_wms, jpl_wms;
>  function init(){
>  map = new OpenLayers.Map('map', {'maxResolution': 1.40625/2});
>  jpl_wms = new OpenLayers.Layer.WMS( "Mapa
>  Satelital","http://labs.metacarta.com/wms-c/Basic.py?", {layers: 'satellite',
>  format: 'image/png' } );
>  map.addLayer(jpl_wms);
>  ol_wms = new OpenLayers.Layer.WMS( "Mapa
>  Vectorial", "http://labs.metacarta.com/wms-c/Basic.py?", {layers: 'basic',
>  format: 'image/png' } );
>  map.addLayer(ol_wms);
>  map.setCenter(new OpenLayers.LonLat(-79, -29), 2);
>  map.addControl(new OpenLayers.Control.LayerSwitcher());
>  map.addControl(new OpenLayers.Control.ScaleLine());
>  map.addControl(new OpenLayers.Control.MousePosition());
>  map.addControl(new OpenLayers.Control.OverviewMap());
>  }
>  </script>

I copied/pasted your code in OpenLayers' wms.html example and it just
worked. The controls are there.

When I load your web page in FF, FireBug shows this error:

OpenLayers.Control.ScaleLine is not a constructor
map.addControl(new OpenLayers.Control.ScaleLine());

It seems to me that you're missing controls in your OpenLayers.js
build. You can try to use
http://dev.openlayers.org/nightly/OpenLayers.js instead of your
(custom) OpenLayers.js build to make sure that's your problem.

Cheers,

--
Eric



More information about the Users mailing list