Home > openlayers > OpenLayers TMS limit zoom and extent

OpenLayers TMS limit zoom and extent

June 1Hits:3
Advertisement

I have a custom map which I get from a mbtiles file with the bounds -13,25,49,60 and zoom from 4 to 10.The display div is dynamic, I mean that it depends on window size and the extent restriction works but still tries to load images around the map if the display div is bigger.
How can I limit the zooming out below 4? Here is my code:

var map; var fromProjection = new OpenLayers.Projection("EPSG:4326");   // Transform from WGS 1984 var toProjection   = new OpenLayers.Projection("EPSG:900913"); // to Spherical Mercator Projection var extent= new OpenLayers.Bounds(-13,25,49,60).transform( fromProjection, toProjection); var mbTiles = new OpenLayers.Layer.TMS("base", "base.php", {     getURL: mbtilesURL,     type:'png',     transitionEffect: "resize",     isBaseLayer: true,  }); function mbtilesURL (bounds) {     var db = "img/map/base.mbtiles";     var res = this.map.getResolution();     var x = Math.round ((bounds.left - this.maxExtent.left) / (res * this.tileSize.w));     var y = Math.round ((this.maxExtent.top - bounds.top) / (res * this.tileSize.h));     var z = this.map.getZoom();     return this.url+"?db="+db+"&z="+z+"&x="+x+"&y="+((1 << z) - y - 1); } map = new OpenLayers.Map('map', {     projection: new OpenLayers.Projection("EPSG:900913"),     displayProjection: new OpenLayers.Projection("EPSG:4326"),     layers: [mbTiles],     restrictedExtent : extent,     numZoomLevels: 11,     controls: [         new OpenLayers.Control.Navigation({             dragPanOptions: {                 enableKinetic: true             }         }),     new OpenLayers.Control.PanZoom(),     new OpenLayers.Control.Attribution()     ] }); var position = new OpenLayers.LonLat(9.4679,37.6831).transform( fromProjection, toProjection); var zoom = 4; map.setCenter(position, zoom ); map.zoomToMaxExtent(); var switcherControl = new OpenLayers.Control.LayerSwitcher(); map.addControl(switcherControl); switcherControl.maximizeControl(); 

I made it work! Had to add :

   resolutions: [4891.969809,2445.984905,1222.992452,611.4962262,305.7481131,152.8740565] 

and to add to z+4 to get to right zoom level. I used this site http://simonmercier.net/blog/?p=88 to get the right resolutions to use.

Answers

I made it work! Had to add :

resolutions: [4891.969809,2445.984905,1222.992452,611.4962262,305.7481131,152.8740565]

and to add to z+4 to get to right zoom level.

I used this site http://simonmercier.net/blog/?p=88 to get the right resolutions to use.

Related Articles

  • OpenLayers TMS limit zoom and extentJune 1

    I have a custom map which I get from a mbtiles file with the bounds -13,25,49,60 and zoom from 4 to 10.The display div is dynamic, I mean that it depends on window size and the extent restriction works but still tries to load images around the map if

  • In OpenLayers zoom to extent of all overlaysFebruary 18

    In Openlayers I can zoom to the bounding box of all layers like this: map.zoomToExtent(); I can also zoom to the bounding box of a single layer: map.zoomToExtent(layer_name.getDataExtent()); Is there an easy way of zooming to the extent of all layers

  • Can we request new OpenLayers WMS image for an extent without moving the map?July 3

    Can we request new OpenLayers WMS image for an extent without moving the map center ? Reading OpenLayers code, OpenLayers move map center to new extent, and THEN do HTTP request to get the image. Is it possible to instruct the map to HTTP load certai

  • Using AndNav tiles storage as input for OpenLayers.TMSAugust 12

    Is there a possibility to use map tiles from AndNav (created wit Mobile Atlas Creator) that are in format: Mapnik\12\2241\1369.png.andnav (I know that 12 is the zoom level but don't have idea what is 2241 and 1369...) as an input for OpenLayers.TMS l

  • OpenLayers/GeoServer layer zooms in and then out again - I Added VIDEO OF PROBLEMFebruary 10

    I have a strange ZOOM behavior. I am using GeoServer 2.6.1/OpenLayers 2.13.1. I have a layer I created from a MrSid file and am serving as a wms layer. Lets call it the "problematic" layer. When I serve this "problematic" layer alone,

  • Openlayers-2 restrict zoom levels relative to restricted extentJanuary 18

    I have a web application that uses Openlayers 2.13.1 to open a map with many zoom levels defined by a resolutions array. Each user can have a different restricted extent where the user can move inside. I implement it by the openlayers map option rest

  • Limit Zoom on WMTS Layer using Openlayers 2.12September 20

    I'm implementing a baselayer to be used by a Plone addon (collective.geo.openlayers). My implementation specifically creates a layer and returns it to the addon, which enables many different layers to be configured through a webinterface. I got it wo

  • Limit Zooming Geometry Features in OpenLayersOctober 17

    I draw flag feature on my map as follows: myVectorLayer = new OpenLayers.Layer.Vector("Flag Geometry", { renderers: renderer, isBaseLayer: true, projection: new OpenLayers.Projection("EPSG:900913"), styleMap: new OpenLayers.StyleMap({

  • OpenLayers 3 Zoom to extent only working in debug?June 15

    I am using gpx data to display routes with open layers 3 and my attempts of zooming to fit the gps trace have been thus far unsuccessful. I only ever got it working in debug mode on firefox, where it always zooms correctly, however when just loading

  • OpenLayers - Switching to Google Basemap causes a flicker as it zooms to extentJune 25

    I created and example based off of the spherical-mercator example example and placed it here. I made the bing road layer the default. If you zoom in on a location and then switch to a google layer you'll see the map go to full extent and then zoom to

  • How to limit vertically the extent of an OpenLayers map?

    How to limit vertically the extent of an OpenLayers map?August 5

    When I pan north, the map goes out and I see the white background of my HTML. I want to pan vertically and the map to block when it reaches the top (or bottom, respectively). I have tried to put bounds, but this solution puts also bounds horizontally

  • Openlayers TMS default imageApril 3

    In OpenLayers, when a tile is missing in a TMS layer, a semi-transparent pink rectangle shows in its place. Is there a way to load some default image, like one saying "No data for this region under this zoom" instead? One possibility is to reque

  • Using Google Maps with OpenLayers for some zoom levelsJuly 2

    I've had a search on here to see if this has come up but I've not found anything, sorry if this is a duplicate. I'm trying to use the Google Maps layers with an OpenLayers site, but not for all zoom levels. What I want to do is use the NASA global mo

  • Speed up OpenLayers TMSMarch 19

    Hopefully someone can help. I'm using OpenLayers and have a TMS layer with local tiles stored. When drawing the tiles it seems slow, I see the tiles load one by one. Is there a way to make getURL request multiple tiles at once? Thanks --------------S

  • zoom to extent of several vector layersMarch 20

    I'm trying to zoom to the extent of several vector layers data. I've tried to create a new OpenLayers.Bounds bounds and to add a 'loadend' for each OpenLayers.Layer.Vector to increase bounds, but then I don't know where to put map.zoomToExtent(bounds

  • TileStache + OpenLayers TMS - Tiles are rendered disorderly

    TileStache + OpenLayers TMS - Tiles are rendered disorderlyMay 25

    I newly turned to TileStache to render Mapnik tiles because of the caching option. Before, I was using Mapnik python bindings only and it was working perfectly. Now that I use TileStache, the tiles are rendered randomly at wrong position in wrong ord

  • OpenLayers Allow Further Zoom Out?

    OpenLayers Allow Further Zoom Out? November 20

    See attached picture. This is how it is when the page loads. I'm currently using map.zoomToMaxExtent(); Everything is working pretty well but I'd like to zoom out more/see the whole world using OSM/Google Map Layers: is this even possible? Note that

  • OpenLayers-3 setting zoom so layers fit in map windowJune 11

    Is there a way to dynamically set the zoom level so that the current layers always fit within the width of the map frame on page load? Currently the zoom level is set statically such that when using a full resolution monitor the application loads per

  • How to disable a base layer in OpenLayers based on zoom level September 20

    I have a map which overlays Open Street Map data on imagery for Pennsylvania. As a baselayer to the roads (and eventually other layers) I have two baselayers - Blue Marble NG and USGS EROS 1ft imagery. I would like to be able to combine these two lay

  • Mapserver, TMS, Scales zoom levels and how to deal with all of itJune 12

    I have a whole bunch of data in my db that I need to draw at different zoom levels using Mapserver. Everything uses a 4326 SRID. My (custom) client, will fetch the data using 20 TMS zoom levels and images of 256x256 pixels. In fact, for every zoom le

Copyright (C) 2017 ceus-now.com, All Rights Reserved. webmaster#ceus-now.com 14 q. 0.347 s.