Steven M. Ottens wrote:
> Cameron Shorter wrote:
>
>>Steven M. Ottens wrote:
>>
>>>Hi all,
>>>
>>>I finished my initial tiling scheme:
>>>http://jana.geodan.nl/steveno/tiling/demo/tiling/
>>>
>>>It has a few problems:
>>>1. you need to set the initial map extent in the correct scale level,
>>>there's no check on the scale level of the initial map extent
>>
>>Have you got ideas on how we should address this?
>
> I fixed it by introducing the following check at the end of this.init in
> Extent.js:
> if(extent.res[0] !=extent.res[1]) extent.checkBbox();
> Where I assume that extent.res should be the same horizontal as
> vertical. This is valid on projected systems, but I don't know about
> lat/long systems.
I know this assumption doesn't work for the Mercator projection used by
Google Map layers. (The X axis is linear, Y asix is not).
> The checkBbox function is similar to the centerAt:
> this.checkBbox = function() {
> var center = this.getCenter();
> var half = new Array(this.size[0]/2, this.size[1]/2);
> var res = this.getFixedScale();
> this.lr = new Array(center[0]+half[0]*res, center[1]-half[1]*res);
> this.ul = new Array(center[0]-half[0]*res, center[1]+half[1]*res);
> }
> The getFixedScale function returns a fixed scale level in case of a set
> of zoomLevels, and the normal max res; Math.max(res[0],res[1]) when no
> zoomLevels are present. So it probably should get another name.
>
>>>2. TileSize is hardcoded at 200px
>>
>>As we discussed before, this should eventually be moved to the Context
>>document.
>>But we should confirm this with the WMS-C list (if you have not done
>>so already).
>>Reasoning:
>>1. A WMS-C will know it's own zoom levels and will advertise it's zoom
>>levels from a WMS-C GetCapabilities request.
>>2. Results of a WMS-C GetCapability requests are used to build a
>>Context document.
>
> I've introduced some hacks to cope with the lack of wms-c capabilities
> docs. The tileSize and zoomLevels etc should indeed be defined by the
> WMS-C context doc.
>
>>>3. Can't seem to get fixPNG working for IE.
>>>4. Haven't checked it for lat long systems.
>>>
>>>Apart from the new code (TiledWmsLayer and TileExtent and
>>>wmsc_GetMap.xsl) there are two modifications in existing code:
>>>Extent.js has now getFixedScale() and setFixedScale() and checks for
>>>fixedScales in centerAt()
>>>Als MapContainerBase allows now for configuring zoomLevels in the
>>>config.xml
>>>
>>>Steven
>>
>>Where is the locic for ZoomIn/ZoomOut and getExetent()?
>>For Google/Yahoo/... maps, the logic is provided by these libraries
>>and is tied to the layer.
>>So I'd argue that the logic for zooming should be tied to the base Layer.
>
> Since I only support 1 set of zoomLevels there's no real problem there.
> The zoomLevels are defined in the MapPane and all layers are forced to
> use it. The zoom and extent logic is in extent.js Two extra functions
> are introduced to take care of this:
> getFixedScale and setFixedScale.
>
>>What are we going to do when we have 2 layers with different zoom levels?
>
> I don't know. I'd argue nothing and discuss with OL people for a neat
> solutions which we can use once we include OL. The proper solution
> probably will involve using multiple sets of zoomlevels and scale tiles
> on the clientside when needed. It's a new problem which has to be
> discussed in the WMS-C standard/OWSContext one, so I advise not to rush
> this.
>
> Steven
>
>
>
>
> ------------------------------------------------------------------------
>
> /*
> Author: Mike Adair mike.adairATccrs.nrcan.gc.ca
> License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
> $Id: Extent.js 2140 2006-06-27 10:03:26Z steven $
> */
>
>
> var Rearth = 6378137.0; // Radius of the earth (sphere); different from Proj value?
> var degToMeter = Rearth*2*Math.PI/360;
> //var mbScaleFactor = 72 * 39.3701; //PixelsPerInch*InchesPerMapUnit; magic numbers
> //need to determine magic number for lat/lon
> var mbScaleFactor = 3571.428; //magic number, for Geoserver SLD compatibility
> // 1/0.00028 (0.28 mm "is a common actual size for
> // contemporary display" as written in the SLD specification ...
>
> /*
> * FD 2005/03/04 : minScale et maxScale
> * DGR : should be in config ?
> */
> var minScale = 1000;
> var maxScale = 200000;
>
> /**
> * A tool designed to handle geography calculations for widgets which render
> * the model in 2D.
> * Use of this tool requires that it's model implements get/setWindowHeight/Width
> * methods.
> * Encapsulates all geography and image size aspects of a geographic object
> * displayed in a rectangular area on the screen.
> * All coordinates are handled as points which is a 2 element array, where x is
> * the first element and y is the second. Coordinates are either pixel and lixel
> * (pl) relative to the top left of the extent or projection XY values (xy).
> *
> * @constructor
> * @param model the model document that this extent represents
> * @param initialRes (optional) if supplied the extent resolution will be set to this value
> */
> function Extent( model, initialRes ) {
> this.model = model;
>
> //TBD: calculate this dynamically by the init extent.
>
> this.id = model.id + "_MbExtent" + mbIds.getId();
>
> this.getBbox = function() {
> var bbox = this.model.getBoundingBox();
> return bbox;
> }
>
> this.setBbox = function(bbox){
> size = this.getSize();
> res = Math.max((bbox[2] - bbox[0])/size[0], (bbox[3] - bbox[1])/size[1]);
> scale=this.getFixedScale(res);
> center = new Array((bbox[1]-bbox[3])/2,(bbox[0]-bbox[2])/2);//center=horizontal,vertical
> half = new Array(size[0]/2,size[1]/2);
> bbox = new Array(center[0]-half[0]*scale, center[1]-half[1]*scale, center[0]+half[0]*scale,center[1]+half[1]*scale);
> this.model.setBoundingBox(bbox);
> }
>
> this.getSize = function() {
> size= new Array();
> size[0] = this.model.getWindowWidth();
> size[1] = this.model.getWindowHeight();
> return size;
> }
>
> this.setSize = function(size){
> this.model.setWindowWidth(size[0]);
> this.model.setWindowHeight(size[1]);
> }
> //this.checkExtent = function(res) {
> //alert(res);
> //}
> this.getFixedScale = function(res) {
> if (this.zoomLevels){
> if (!res) {
> this.setResolution( new Array(this.model.getWindowWidth(), this.model.getWindowHeight() ) );
> res = Math.max(this.res[0],this.res[1]);
>
> }
> var zoomLevels = this.zoomLevels.sort(function sort(a,b){return b-a});
> var i=0;
> while(zoomLevels[i] >= res){
> i++;
> }
> if(i==0) {
> alert("zoom level is out of bounds");
> i=1;
> }
> if(i==this.zoomLevels.length) {
> alert("maximum zoom level reached");
> }
> this.fixedScale = zoomLevels[i-1];
> }
> else this.fixedScale = Math.max(this.res[0],this.res[1]);
> return this.fixedScale;
>
> }
>
> this.setFixedScale = function(enabled,zoomLevels){
> if(enabled) {
> this.zoomLevels = zoomLevels;
> }
> else this.zoomLevels = null;
> }
> this.size = new Array();
> this.res = new Array();
> this.zoomBy = 4;
>
> this.checkBbox = function() {
> var center = this.getCenter();
> var half = new Array(this.size[0]/2, this.size[1]/2);
> var res = this.getFixedScale();
> this.lr = new Array(center[0]+half[0]*res, center[1]-half[1]*res);
> this.ul = new Array(center[0]-half[0]*res, center[1]+half[1]*res);
> }
> /**
> * Returns the XY center of this extent
> * @return array of XY for th center of the extent
> */
> this.getCenter = function() {
> return new Array((this.ul[0]+this.lr[0])/2, (this.ul[1]+this.lr[1])/2);
> }
>
> /**
> * Returns XY coordinates for given pixel line coords w.r.t. top left corner
> * @param pl pixel line in extent to calculate
> * @return point array of XY coordinates
> */
> this.getXY = function(pl) {
> //switch(this.model.getSRS()) {
> // case "EPSG:GMAPS": //@TODO Cleanup this hack
> // gmap=this.model.getParam("gmap");
> // if(gmap){
> // p=new GPoint(pl[0],pl[1]);
> // latlng=gmap.fromDivPixelToLatLng(p);
> // latlng=new Array(latlng.lng(),latlng.lat());
> // }
> // else alert("Extent: gmap not defined");
> // break;
> // default:
> // latlng=new Array(this.ul[0]+pl[0]*this.res[0],this.ul[1]- pl[1]*this.res[1]);
> // break;
> //}
> latlng=new Array(this.ul[0]+pl[0]*this.res[0],this.ul[1]- pl[1]*this.res[1]);
> return latlng;
> }
>
> /**
> * Returns pixel/line coordinates for given XY projection coords
> * @param xy projection XY coordinate to calculate
> * @return point array of pxiel/line coordinates w.r.t. top left corner
> */
> this.getPL = function(xy) {
> //switch(this.model.getSRS()) {
> // case "EPSG:GMAPS": //@TODO Cleanup this hack
> // return xy;
> //}
>
> var p = Math.floor( (xy[0]-this.ul[0])/this.res[0] );
> var l = Math.floor( (this.ul[1]-xy[1])/this.res[1] );
> return new Array(p,l);
> }
>
> /**
> * Adjust the extent so that it is centered at given XY coordinate with given
> * resolution. Extent width and height remain fixed. Optionally check to
> * ensure that it doesn't go beyond available extent.
> *
> * @param center projection XY coordinate to center at
> * @param newres resolution to display at
> * @param limitExtent ensure that the extent doesn't go beyond available bbox (TBD: not complete/tested)
> * @return none
> */
> this.centerAt = function(center, newres, limitExtent) {
> var half = new Array(this.size[0]/2, this.size[1]/2);
> /*
> * FD 2005/03/04 : respect de minScale et maxScale
> * DGR : scale constraints
> var nRmin= minScale/mbScaleFactor;
> var nRmax= maxScale/mbScaleFactor;
> if (newres < nRmin) {
> newres= nRmin ;
> }
> if (newres > nRmax) {
> newres= nRmax ;
> }
> */
> if (this.zoomLevels) {
> newres=this.getFixedScale(newres);
> }
> this.lr = new Array(center[0]+half[0]*newres, center[1]-half[1]*newres);
> this.ul = new Array(center[0]-half[0]*newres, center[1]+half[1]*newres);
>
> //make sure the request doesn't extend beyond the available model
> //TBD this block not tested
> if ( limitExtent ) {
> var xShift = 0;
> if ( this.lr[0] > ContextExtent.lr[0] ) xShift = ContextExtent.lr[0] - this.lr[0];
> if ( this.ul[0] < ContextExtent.ul[0] ) xShift = ContextExtent.ul[0] - this.ul[0];
> this.lr[0] += xShift;
> this.ul[0] += xShift;
>
> var yShift = 0;
> if ( this.lr[1] < ContextExtent.lr[1] ) yShift = ContextExtent.lr[1] - this.lr[1];
> if ( this.ul[1] > ContextExtent.ul[1] ) yShift = ContextExtent.ul[1] - this.ul[1];
> this.lr[1] += yShift;
> this.ul[1] += yShift;
> }
>
> this.model.setBoundingBox( new Array(this.ul[0], this.lr[1], this.lr[0], this.ul[1]) );
> //this.setResolution(size);
> this.setSize(newres);
> }
>
> /**
> * Adjust the extent to the given bbox. Resolution is recalculated.
> * Extent width and height remain fixed.
> * @param ul upper left coordinate of bbox in XY projection coords
> * @param lr lower right coordinate of bbox in XY projection coords
> */
> this.zoomToBox = function(ul, lr) { //pass in xy
> var center = new Array((ul[0]+lr[0])/2, (ul[1]+lr[1])/2);
> newres = Math.max((lr[0] - ul[0])/this.size[0], (ul[1] - lr[1])/this.size[1]);
> this.centerAt( center, newres );
> }
> /**
> * Adjust the width and height to that bbox is displayed at specified resolution
> * @param res the resolution to be set
> */
> //TBD update the model doc
> this.setSize = function(res) { //pass in a resolution and width, height are recalculated
> this.res[0] = this.res[1] = res;
> this.size[0] = (this.lr[0] - this.ul[0])/this.res[0];
> this.size[1] = (this.ul[1] - this.lr[1])/this.res[1];
> this.width = Math.ceil(this.size[0]);
> this.height = Math.ceil(this.size[1]);
> }
>
> /**
> * Adjust the resolution so the bbox fits in the specified width and height
> * @param size width, height array passed in
> */
> //TBD update the model doc
> this.setResolution = function(size) { //pass in a width, height and res is recalculated
> this.size[0] = size[0];
> this.size[1] = size[1];
> this.res[0] = (this.lr[0] - this.ul[0])/this.size[0];
> this.res[1] = (this.ul[1] - this.lr[1])/this.size[1];
> this.width = Math.ceil(this.size[0]);
> this.height = Math.ceil(this.size[1]);
> }
>
> /**
> * Returns the map scale denominator for the current extent resolution
> * @return map scale denominator
> */
> this.getScale = function() {
> var pixRes = null;
> switch(this.model.getSRS()) {
> case "EPSG:GMAPS":
> break;
> case "EPSG:4326": //all projection codes in degrees
> case "EPSG:4269":
> pixRes = this.res[0]*degToMeter;
> break;
> default: //all projection codes in meters
> pixRes = this.res[0];
> break;
> }
> return mbScaleFactor*pixRes;
> }
>
> /**
> * Sets the model's resolution from mapScale input value. The map center
> * remains fixed.
> * @param scale map scale denominator value
> */
> this.setScale = function(scale) {
> var newRes = null;
> /*
> * FD 2005/03/04
> * On contraint l'echelle min et max de l'application.
> * A externaliser dans le fichier de config de l'application ;-)
> * DGR : should be in the config
> if (scale < minScale) {
> scale= minScale ;
> }
> if (scale > maxScale) {
> scale= maxScale ;
> }
> */
> switch(this.model.getSRS()) {
> case "EPSG:4326": //all projection codes in degrees
> case "EPSG:4269":
> //convert to resolution in degrees
> newRes = scale/(mbScaleFactor*degToMeter);
> break;
> default: //all projection codes in meters
> newRes = scale/mbScaleFactor;
> break;
> }
> this.centerAt(this.getCenter(), newRes );
> }
>
>
> /**
> * Initialization of the Extent tool, called as a loadModel event listener.
> * @param extent the object being initialized
> * @param initialRes (optional) if supplied the extent resolution will be set to this value
> */
> this.init = function(extent, initialRes) {
> var bbox = extent.model.getBoundingBox();
> extent.ul = new Array(bbox[0],bbox[3]);
> extent.lr = new Array(bbox[2],bbox[1]);
> /*
> TBD: when called as a listener this gets a bbox array passed in, not initialRes value
> if ( initialRes ) {
> extent.setSize( initialRes );
> } else {
> extent.setResolution( new Array(extent.model.getWindowWidth(), extent.model.getWindowHeight() ) );
> }
> */
> extent.setResolution( new Array(extent.model.getWindowWidth(), extent.model.getWindowHeight() ) );
> if(extent.res[0] !=extent.res[1]) extent.checkBbox();
> }
> if ( initialRes ) this.init(this, initialRes);
>
>
> this.firstInit = function(extent, initialRes) {
> extent.init(extent, initialRes);
> //TBD: this causes 2 paint() calls on initial load, not sure why it's here - MA
> //extent.zoomToBox(extent.ul,extent.lr);
> }
>
> }
>
>
>
--
Cameron Shorter
http://cameron.shorter.net
|