openscales2.0 user-defined TMS

瀏覽次數:103 次
跳到第一則未讀訊息

qi chen

未讀,
2012年3月9日 凌晨3:22:562012/3/9
收件者:openscales-dev
Hi,
I rewrite the function getURL and initGriddedTiles in TMS.as to
fit for the rule of my tiles generated. But it doesn't provide
initGriddedTiles to override in openscales2.0. Is there any other
solution to solve user-defined TMS with different Projection and
different way of generting tiles.
diffirence:
this.maxExtent.bottom>>>this.maxExtent.top

Thanks in andvance.




MyTMS1.2.as Code:

override public function getURL(bounds:Bounds):String {
if(this.url == ""){
return "";
}
if(this.url.lastIndexOf("/") != (this.url.length - 1)){
this.url += "/";
}
var res:Number = this.map.resolution;
if(this._tileOrigin==null) {
this._tileOrigin = new
Location(this.maxExtent.left,this.maxExtent.top);
}
var x:Number = Math.round((bounds.left - this.maxExtent.left) /
(res * this.tileWidth));
var y:Number = Math.round((this.maxExtent.top - bounds.top) /
( res* this.tileHeight));
var z:Number = (this._serverResolutions!=null) ?
this._serverResolutions.indexOf(res) : this.map.zoom;

if(x < 0 || y < 0 || z < 0){
return "";
}
var url:String = this.url + pScales[z] + "/" + x + "/" + y
+"."+this._format;
return url;
}
override public function initGriddedTiles(bounds:Bounds,
clearTiles:Boolean=true):void {
var viewSize:Size = this.map.size;
var minRows:Number = Math.ceil(viewSize.h/this.tileHeight) +
Math.max(1, 2 * this.buffer);
var minCols:Number = Math.ceil(viewSize.w/this.tileWidth) +
Math.max(1, 2 * this.buffer);
var extent:Bounds = this.maxExtent;
var resolution:Number = this.map.resolution;
var tilelon:Number = resolution * this.tileWidth;
var tilelat:Number = resolution * this.tileHeight;
var offsetlon:Number = bounds.left - extent.left;
var tilecol:Number = Math.floor(offsetlon/tilelon) - this.buffer;
var tilecolremain:Number = offsetlon/tilelon - tilecol;
var tileoffsetx:Number = -tilecolremain * this.tileWidth;
var tileoffsetlon:Number = extent.left + tilecol * tilelon;
var offsetlat:Number = extent.top-bounds.top;
var tilerow:Number = Math.ceil(offsetlat/tilelat) - this.buffer;
var tilerowremain:Number = offsetlat/tilelat-tilerow+1;
var tileoffsety:Number = -tilerowremain * this.tileHeight;
var tileoffsetlat:Number = extent.top - tilerow * tilelat;

tileoffsetx = Math.round(tileoffsetx);
tileoffsety = Math.round(tileoffsety);
this.origin = new Location(tileoffsetx, tileoffsety);

var startX:Number = tileoffsetx;
var startLon:Number = tileoffsetlon;
var rowidx:int = 0;

if(this.grid == null) {
this.grid = new Vector.<Vector.<ImageTile>>();
}
do {
var row:Vector.<ImageTile>;
if(this.grid.length==rowidx) {
row = new Vector.<ImageTile>;
this.grid.push(row);
} else {
row = this.grid[rowidx];
}
rowidx=++rowidx;

tileoffsetlon = startLon;
tileoffsetx = startX;
var colidx:int = 0;
do {
var tileBounds:Bounds = new Bounds(tileoffsetlon,
tileoffsetlat,
tileoffsetlon + tilelon,
tileoffsetlat + tilelat);
var x:Number = tileoffsetx;
x -= int(this.map.layerContainer.x);

var y:Number = tileoffsety;
y -= int(this.map.layerContainer.y);

var px:Pixel = new Pixel(x, y);
var tile:ImageTile;
if(row.length==colidx) {
tile = this.addTile(tileBounds, px);
row.push(tile);
} else {
tile = row[colidx];
if(clearTiles)
tile.clearAndMoveTo(tileBounds, px, false);
else
tile.moveTo(tileBounds, px, false);
}
colidx=++colidx;

tileoffsetlon += tilelon;
tileoffsetx += this.tileWidth;
} while ((tileoffsetlon <= bounds.right + tilelon * this.buffer)
|| colidx < minCols)

tileoffsetlat -= tilelat;
tileoffsety += this.tileHeight;
} while((tileoffsetlat >= bounds.bottom - tilelat * this.buffer) ||
rowidx < minRows)

//shave off exceess rows and colums
this.removeExcessTiles(rowidx, colidx);

//now actually draw the tiles
this.spiralTileLoad();
}

MyTMS2.0.as:
private var pScales:Array =
[2311070,1155535,577801,288892,144446,72223,36111,18055,9028,4514,2257];//
比例尺倒数数组
override public function getURL(bounds:Bounds):String {
if(this.url == ""){
return "";
}
if(this.url.lastIndexOf("/") != (this.url.length - 1)){
this.url += "/";
}

var res:Number =
this.getSupportedResolution(this.map.resolution).value;
if(this._tileOrigin==null) {
this._tileOrigin = new
Location(this.maxExtent.left,this.maxExtent.top);
}
var x:Number = Math.round((bounds.left - this.maxExtent.left) /
(res * this.tileWidth));
//this.maxExtent.bottom>>>>this.maxExtent.top
var y:Number = Math.round((this.maxExtent.top - bounds.top) / (res
* this.tileHeight));
var z:Number =
this.getZoomForResolution(this.map.resolution.reprojectTo(this.projection).value);

if(x < 0 || y < 0 || z < 0){
return "";
}
var url:String = this.url + pScales[z] + "/" + x + "/" + y
+"."+this._format;
return url;
}


Application .mxml
<?xml version="1.0" encoding="utf-8"?>

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"

xmlns:s="library://ns.adobe.com/flex/spark"

xmlns="http://openscales.org"
creationComplete="application1_creationCompleteHandler(event)"

preinitialize="application1_preinitializeHandler(event)"

xmlns:mx="library://ns.adobe.com/flex/mx" width="100%"

height="100%" xmlns:controls="whh.flex.controls.*"
fontSize="12" xmlns:local="*"
xmlns:layer="org.openscales.core.layer.*">

<fx:Script>

<![CDATA[
import mx.controls.Alert;
import mx.events.FlexEvent;

import org.openscales.core.basetypes.Resolution;
import org.openscales.geometry.basetypes.Bounds;
import org.openscales.proj4as.Proj4as;
import org.openscales.proj4as.ProjProjection;

protected function
application1_creationCompleteHandler(event:FlexEvent):void
{
fxMap.map.zoomToExtent(new
Bounds(104.794034072,28.188257672,108.779398394,30.769057832,"EPSG:
4610"));
}


protected function
application1_preinitializeHandler(event:FlexEvent):void
{
ProjProjection.defs["EPSG:4610"] = "+title=long/
lat:GCS_Xian_1980 +proj=longlat +a=6378140.0 +b=6356755.2881575283
+ellps=GCS_Xian_1980 +datum=D_Xian_1980 +units=degrees +no_defs";
}

]]>

</fx:Script>



<s:VGroup width="100%" height="100%">
<Map id="fxMap" width="100%" height="100%"

maxExtent="104.08538323954,27.3088842461203,111.412855392868,33.0118696477743"
projection="EPSG:4610">
<DragHandler/>
<WheelHandler/>
<layer:MyFxTMS id="baseTMS" url="http://222.178.118.102:8080/output/
cache/IMGMAP_256x256/"
resolutions="0.006919035281092258, 0.003459517640546129,
0.001729859114804133, 8.649041095359745E-4, 4.3245205476798724E-4,
2.1622602738399362E-4, 1.0811151675869727E-4, 5.4054261446049104E-5,
2.7028627656324084E-5, 1.3514313828162042E-5, 6.757156914081021E-6"
tileHeight="256" tileWidth="256" format="jpg"
projection="EPSG:4610"/>

<ScaleLine id="scaleLine" x="{width-150}" y="{height-150}"/>
<MousePosition id="mousePosition" x="{width-250}"
y="{height-80}"
displayProjection="EPSG:4610" availableProjSrsList="EPSG:
4610"/>
<PanZoom id="panZoom" x="10" y="10" />
</Map>
</s:VGroup>
</s:Application>



hdam

未讀,
2013年1月21日 下午3:11:062013/1/21
收件者:opensca...@googlegroups.com
I have OSM world images, and it looks like the map is cut-off at roughly 40 deegree South.  Any ideas what might be wrong?

Thanks,
...-H
回覆所有人
回覆作者
轉寄
0 則新訊息