OpenLayers.Layer.KaMap is now working much better. The TIGER example which was just a hack before is now working properly, and there's an actual scale calculation being performed based on params passed into the constructor of 'units' and 'resolution', both of which are determined by the mapfile. The only limitation yet to be tackled is that maxResolution on the map must split the map up such that 0,0 is a tile corner. This requires subclassing more (or perhaps all) of the Layer.Grid functions, so I'm off to do that now.
git-svn-id: http://svn.openlayers.org/trunk/openlayers@763 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
+7
-2
@@ -16,10 +16,15 @@
|
|||||||
var ol_wms = new OpenLayers.Layer.WMS( "OpenLayers WMS",
|
var ol_wms = new OpenLayers.Layer.WMS( "OpenLayers WMS",
|
||||||
"http://labs.metacarta.com/wms/vmap0?", {layers: 'basic'} );
|
"http://labs.metacarta.com/wms/vmap0?", {layers: 'basic'} );
|
||||||
var ka_wms = new OpenLayers.Layer.KaMap( "KaMap",
|
var ka_wms = new OpenLayers.Layer.KaMap( "KaMap",
|
||||||
"http://www.h2guide.com/my-ka-map/h2tile.php?" , { map: 'h2guide', g: 'background' }, new OpenLayers.LonLat(0,0));
|
"http://freemap.in/~crschmidt/ka-map/ka-map-0.2-20060208/htdocs/tile.php?" , { map: 'gmap', g: 'roads' }, 'degrees', 72 );
|
||||||
|
var jpl_wms = new OpenLayers.Layer.WMS( "NASA Global Mosaic",
|
||||||
|
"http://wms.jpl.nasa.gov/wms.cgi",
|
||||||
|
{layers: "modis,global_mosaic"});
|
||||||
|
|
||||||
|
|
||||||
map.addLayers([ol_wms, ka_wms]);
|
|
||||||
|
|
||||||
|
map.addLayers([jpl_wms, ka_wms]);
|
||||||
map.addControl(new OpenLayers.Control.LayerSwitcher());
|
map.addControl(new OpenLayers.Control.LayerSwitcher());
|
||||||
map.setCenter(new OpenLayers.LonLat(0, 0), 0);
|
map.setCenter(new OpenLayers.LonLat(0, 0), 0);
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -13,13 +13,13 @@
|
|||||||
function init(){
|
function init(){
|
||||||
var map = new OpenLayers.Map('map', {'maxResolution': 1.2/4, controls:[]});
|
var map = new OpenLayers.Map('map', {'maxResolution': 1.2/4, controls:[]});
|
||||||
|
|
||||||
var ka_wms = new OpenLayers.Layer.KaMap( "KaMap", "http://maps.dmsolutions.ca/demo/us_streets/tile.php", {map:'tiger04', g:'__base__'}, new OpenLayers.LonLat(0,0));
|
var ka_wms = new OpenLayers.Layer.KaMap( "KaMap", "http://maps.dmsolutions.ca/demo/us_streets/tile.php", {map:'tiger04', g:'__base__'});
|
||||||
ka_wms.setTileSize(new OpenLayers.Size(300,300));
|
ka_wms.setTileSize(new OpenLayers.Size(300,300));
|
||||||
map.addLayers([ka_wms]); // , ka_wms, kamap_wms]);
|
map.addLayers([ka_wms]); // , ka_wms, kamap_wms]);
|
||||||
map.addControl(new OpenLayers.Control.LayerSwitcher());
|
map.addControl(new OpenLayers.Control.LayerSwitcher());
|
||||||
map.addControl(new OpenLayers.Control.MouseToolbar());
|
map.addControl(new OpenLayers.Control.MouseToolbar());
|
||||||
map.addControl(new OpenLayers.Control.PanZoomBar());
|
map.addControl(new OpenLayers.Control.PanZoomBar());
|
||||||
map.setCenter(new OpenLayers.LonLat(-70, 30), 2);
|
map.setCenter(new OpenLayers.LonLat(-96, 35), 2);
|
||||||
}
|
}
|
||||||
// -->
|
// -->
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -6,10 +6,16 @@
|
|||||||
* @class
|
* @class
|
||||||
*/
|
*/
|
||||||
OpenLayers.Layer.KaMap = Class.create();
|
OpenLayers.Layer.KaMap = Class.create();
|
||||||
|
|
||||||
|
|
||||||
OpenLayers.Layer.KaMap.prototype =
|
OpenLayers.Layer.KaMap.prototype =
|
||||||
Object.extend( new OpenLayers.Layer.Grid(), {
|
Object.extend( new OpenLayers.Layer.Grid(), {
|
||||||
metaTileHeight: 6,
|
|
||||||
metaTileWidth: 6,
|
units: 'degrees',
|
||||||
|
scales: {inches: 1, feet: 12, miles: 63360.0, meters: 39.3701, kilometers: 39370.1, degrees: 4374754},
|
||||||
|
|
||||||
|
|
||||||
|
resolution: 72,
|
||||||
|
|
||||||
DEFAULT_PARAMS: {
|
DEFAULT_PARAMS: {
|
||||||
i: 'jpeg',
|
i: 'jpeg',
|
||||||
@@ -18,9 +24,10 @@ OpenLayers.Layer.KaMap.prototype =
|
|||||||
|
|
||||||
// this.cellSize = newScale/(oMap.resolution * inchesPerUnit[oMap.units]);
|
// this.cellSize = newScale/(oMap.resolution * inchesPerUnit[oMap.units]);
|
||||||
// kaMap.prototype.geoToPix = function( gX, gY ) { var pX = gX / this.cellSize; var pY = -1 * gY / this.cellSize; }
|
// kaMap.prototype.geoToPix = function( gX, gY ) { var pX = gX / this.cellSize; var pY = -1 * gY / this.cellSize; }
|
||||||
initialize: function(name, url, params, origin) {
|
initialize: function(name, url, params, units, resolution) {
|
||||||
this.kaOrigin = origin;
|
|
||||||
var newArguments = new Array();
|
var newArguments = new Array();
|
||||||
|
if (units) this.units = units;
|
||||||
|
if (resolution) this.resolution = resolution;
|
||||||
newArguments.push(name, url, params);
|
newArguments.push(name, url, params);
|
||||||
OpenLayers.Layer.Grid.prototype.initialize.apply(this, newArguments);
|
OpenLayers.Layer.Grid.prototype.initialize.apply(this, newArguments);
|
||||||
this.params = (params ? params : {});
|
this.params = (params ? params : {});
|
||||||
@@ -33,13 +40,13 @@ OpenLayers.Layer.KaMap.prototype =
|
|||||||
},
|
},
|
||||||
addTile:function(bounds,position) {
|
addTile:function(bounds,position) {
|
||||||
var zoom = this.map.getZoom();
|
var zoom = this.map.getZoom();
|
||||||
var resolution = this.map.getResolution();
|
var maxRes = this.map.maxResolution;
|
||||||
var scale = 128000000 / Math.pow(2, zoom);
|
var mapRes = this.map.getResolution();
|
||||||
// 1280000 is an empirical value for a specific tile server, not yet figured out the right way to do this in general.
|
var scale = (((this.tileSize.w * this.map.maxResolution * this.resolution) * (this.scales[this.units])) / this.tileSize.w) / Math.pow(2, zoom);
|
||||||
// This will probably be based on map.maxResolution.
|
|
||||||
var cellSize = new OpenLayers.Size(resolution*this.tileSize.w, resolution*this.tileSize.h);
|
var cellSize = new OpenLayers.Size(mapRes*this.tileSize.w, mapRes*this.tileSize.h);
|
||||||
var pX = Math.floor(((bounds.left + this.kaOrigin.lon) / cellSize.w) * this.tileSize.w);
|
var pX = Math.floor(((bounds.left) / cellSize.w) * this.tileSize.w);
|
||||||
var pY = -Math.floor(((bounds.top+this.kaOrigin.lat) / cellSize.h) * this.tileSize.h);
|
var pY = -Math.floor(((bounds.top) / cellSize.h) * this.tileSize.h);
|
||||||
var url = this.getFullRequestString(
|
var url = this.getFullRequestString(
|
||||||
{ t: pY,
|
{ t: pY,
|
||||||
l: pX,
|
l: pX,
|
||||||
|
|||||||
Reference in New Issue
Block a user