[OpenLayers-Users] setCenter problem

Tyler Durden tylersticky at gmail.com
Fri Aug 3 09:22:20 EDT 2007


On 8/3/07, Christopher Schmidt <crschmidt at metacarta.com> wrote:

> Is your center outside the maxextent of your map? Can you give example
> HTML demonstrating this?

OK,

// javascript
MyMap = function() {
    this.bounds = new OpenLayers.Bounds(-11.535, 36.095, -4.535, 43.095);
    this.options = { maxResolution : 0.015693359375,
                     numZoomLevels : 12,
                     projection    : "EPSG:4326",
                     maxExtent     : this.bounds}
}

MyMap.prototype.init = function() {
    this.map = new OpenLayers.Map('map', this.options);
    this.layer_continente = new OpenLayers.Layer.WMS("continente",
"http://localhost:8080/", {"layers":"continente",
"format":"image/png"});
    this.map.addLayer(this.layer_continente);
    this.map.zoomToMaxExtent();
}

MyMap.prototype.location = function(lon, lat, zoom) {
    this.map.setCenter(new OpenLayers.LonLat(parseFloat(lon),
parseFloat(lat)), zoom);
}


// jquery
$(document).ready(function() {
    map = new NDriveMap();
    map.init();
});


<!-- HTML -->
<ul>
  <li>
    <div class="street"><a href="#"
onclick="map.location(-16.8768702503,32.6551515064, 8);">Rua Tenente
Domingos Joao Cardoso</a></div>
  </li>
  <li>
    <div class="street"><a href="#"
onclick="map.location(-16.9361853754,32.6718896314, 8);">Estrada
Comandante Camacho de Freitas</a></div>
  </li>
  <li>
    <div class="street"><a href="#"
onclick="map.location(-16.9354987504,32.6718963814, 8);">Estrada
Comandante Camacho de Freitas</a></div>
  </li>
</ul>

The strange part, is it applies zooming but not the lat and lon.

Thanks,
Tyler



More information about the Users mailing list