openscale加载wms服务的参数,geoserver只认EPSG:4326??
原来一直用得美国states地图测试,今天用自己的地图发现wms组件地图访问不了,难道自geoserver从2.0升级到2.3之后,地图服务打不开了????不过美国的states地图依然正常啊。发现有两个参数没传对,bbox和projection
通过查看源码,发现projection,bbox是不能通过<wms id=”” projection=””>的形式传送的。这倒不是geoserver2.3的问题,原来用2.0测试的时候,调用的一直是美国的states地图,他那个地图默认的就是EPSG:4326的。另外bbox也是通过工程crecomplete对应的初始化函数,调用zoomtoextent(new Bounds(…))的方式来实现的。
不过后来发现是geoserver只认EPSG:4326的问题。
因为我这次用得地图在geoserver中用的都是EPSG:2311而我这次这个地图好像不是EPSG:4326的,用EPSG:2311通过layer view可以正确预览,但如果在<wms id…中设置projection=”EPSG:2311″,发现geoserver始终收不到我的projection参数,因此地图不显示,但预览美国的states地图,可正常显示。因此,怀疑geoserver2.3只能处理EPSG:4326的地图。
经过反复测试,把我原来geoserver中配置的每个图层重新设置一下即可。layer->选择图层->data选项->其中,declare srs输入:EPSG:4326 (原来必须输入EPSG:2311,才可正常预览,否则带非常厉害的重影边框),然后在下面的选框srs handling中选择第2项,reproject
native to declared,然后选择下面的连接,计算两类坐标,然后提交即可(如果第一次不变经纬度坐标,提交一次后再计算一次即可),然后预览图层正常。然后把各图层按此方法重新配置,将原来layer group设置EPSG:4326,重新获取坐标(重新获取后,坐标系变为unknown,不影响使用) ,预览layer group ,正常(如还不行,可将layergroup图层全删除再配)。
注:据此猜测,所有图层,即使不是EPSG:4326的,实际上都可以输入:EPSG:4326,然后srs handling选择第2项,然后获取2类坐标,然后提交,预览应该正常(这样可避开原来设置EPSG2311坐标预览的弯路,那是没有办法的办法,当初连地图预览都不正常,呵呵!!),openscales中访问应该也正常。原来只输入了EPSG:4326,但是没有选第2项,所以有严重重影。
这种方法可以避免这种现象,不过还有待以后验证。
EPSG:4326看到的好像是经纬度坐标,EPSG:2311看到的好像是平面坐标。
代码如下:
<gis:map ….
<gis:WMS
id=”wms1″
name=”xxgis”
url=”http://localhost:8080/geoserver/ws_xxx/wms”
layers=”ws_xxx:group_xx”
version=”1.1.0″
/>
默认显示地图全图及中心位置,靠代码实现,
<s:Application xmlns:fx=”http://ns.adobe.com/mxml/2009″
xmlns:s=”library://ns.adobe.com/flex/spark”
xmlns:mx=”library://ns.adobe.com/flex/mx”
xmlns:gis=”http://openscales.org”
xmlns:components=”components.*”
xmlns:local=”*”
xmlns:autocomplete=”org.openscales.fx.autocomplete.*”
minWidth=”955″ minHeight=”600″ creationComplete=”initmap()”>
private function initmap():void
{
var bds:Bounds=new Bounds(113.50877136292033,34.86444331782237,114.43016589274663,35.70853643034173,”EPSG:4326″);
map1.map.zoomToExtent(bds);
}
以下为看的作者的源码,看的头晕,也没啥效果,不过保留1下了:
WMS.as WMS extends Grid
this._tileProvider = new WMSTileProvider(url, this._version, layers, this.projection, styles, format);
WMSTileProvider extends OGCTileProvider
public function WMSTileProvider(url:String,
version:String,
layer:String,
projection:*,
style:String = “”,
format:String = “image/jpeg”)
{
//call the constructor of the mother class OGCTileProvider
super(url,”WMS”,version,”GetMap”);
}
override public function getTile(bounds:Bounds, center:Pixel, layer:Layer):ImageTile
{
var url:String = this.buildGETQuery(bounds, null);
var img:ImageTile = new ImageTile(layer, center, bounds, url, new Size(this._width, this._height));
if(layer is WMS && (layer as WMS).method != null)
img.method = (layer as WMS).method;
return img;
}
override os_internal function buildGETQuery(bounds:Bounds, params:Object):String {
var str:String = super.buildGETQuery(bounds, params);
// Mandatory LAYERS parameter
str += “LAYERS=” + ((this._layer != null) ? this._layer : ”) + “&”;
// Mandatory STYLES parameter
str += “STYLES=” + ((this._style != null) ? this._style : ”) +’&’;
// Mandatory CRS or SRS parameter
if(this.version==”1.3.0″) {
str += “CRS=” + this._projection.srsCode + “&”;
} else {
str += “SRS=” + this._projection.srsCode + “&”;
}
// Mandatory BBOX parameters
// Lon/Lat if less than 1.3.0 or if axis order of the projection is East/North, lat/lon otherwise
if(this.version==”1.3.0″
&& !this.projection.lonlat){
str += “BBOX=” + bounds.bottom+”,”+ bounds.left +”,”+ bounds.top +”,”+ bounds.right+”&”;
}else {
str += “BBOX=” + bounds.left+”,”+ bounds.bottom +”,”+ bounds.right +”,”+ bounds.top+”&”;
}
// Mandatory HEIGHT and WIDTH parameters
str += “WIDTH=” + this._width + “&”;
str += “HEIGHT=” + this._height + “&”;
// Mandatory FORMAT parameters
str += “FORMAT=” + this._format + “&”;
str += “TRANSPARENT=” + this._transparent.toString().toUpperCase() + “&”;
if (this._bgcolor != null && this._bgcolor != “”)
str += “BGCOLOR=” + this._bgcolor + “&”;
if (this._exceptions != null && this._exceptions != “”)
str += “EXCEPTIONS=” + this._exceptions + “&”;
str += “TILED=” + this._tiled + “&”;
return str.substr(0, str.length-1);
}
OGCTileProvider extends HTTPTileProvider
protected function buildGETParams():String{
var str:String = “”;
if (this._service != null)
str += “SERVICE=” + this._service + “&”;
if (this._version != null)
str += “VERSION=” + this._version + “&”;
if (this._request != null)
str += “REQUEST=” + this._request + “&”;
return str;
}
HTTPTileProvider implements ITileProvider
public interface ITileProvider
{
/**
* This method fetches the server and return the appropriate ImageTile
*
* @param bounds Bounding box for the required tile (in map coordinates)
* @param position Center pixel of the required tile
* @param the layer that needs the tile
* @return an ImageTile representing the tile
*/
function getTile(bounds:Bounds, center:Pixel, layer:Layer):ImageTile;
}
public class ImageTile extends Tile
public function ImageTile(layer:Layer, position:Pixel, bounds:Bounds, url:String, size:Size) {
super(layer, position, bounds, url, size);
// otherwise you’ll get seams between tiles 🙁
//this.cacheAsBitmap = true;
}
override public function draw():Boolean {
if(!super.draw()) {
return false;
}
if (this.url == null) {
this.url = this.layer.getURL(this.bounds);
if(this.layer.security)
this.url = this.layer.security.getFinalUrl(this.url);
}
if(this.url==null) {
if (_request) {
_request.destroy();
_request = null;
}
return false;
}
if (_request) {
_request.destroy();
}
this.loading = true;
_request = new DataRequest(this.url, onTileLoadEnd, onTileLoadError,method);
if(_request.method == URLRequestMethod.POST){
_request.postContent = new URLVariables(this.url);
}
_request.security = this.layer.security;
_request.proxy = this.layer.proxy;
if(this.layer.security==null) {
_request.send();
} else {
this.layer.security.addWaitingRequest(_request);
}
return true;
}
public class Tile extends Sprite
public function Tile(layer:Layer, position:Pixel, bounds:Bounds, url:String, size:Size) {
this.layer = layer;
this.position = position;
this.bounds = bounds;
this.url = url;
this.size = size;
}
public function get onLoadStart():Function {
return this._onLoadStart;
}
public function set onLoadStart(value:Function):void {
this._onLoadStart = value;
}
public function get onLoadEnd():Function {
return this._onLoadEnd;
}
public function set onLoadEnd(value:Function):void {
this._onLoadEnd = value;
}
public class DataRequest extends AbstractRequest {
/**
* @constructor
*/
public function DataRequest(url:String,
onComplete:Function,
onFailure:Function=null,
method: String = null) {
super(true, url, onComplete, onFailure);
if(method!=null && method!=””)
this.method = method;
}
}
public class AbstractRequest implements IRequest
private var _onComplete:Function = null;
private var _onFailure:Function = null;
public function AbstractRequest(SWForImage:Boolean,
url:String,
onComplete:Function,
onFailure:Function=null) {
this._uid = UID.gen_uid();
// Create a loader for a SWF or an image (Loader), or for an URL (URLLoader)
this._loader = (SWForImage) ? new Loader() : new URLLoader();
_loader.addEventListener(IOErrorEvent.IO_ERROR,function(event:Event):void{
event.stopImmediatePropagation();
if (this._onFailure == null)
this._onFailure = onFailure;
if(this._onFailure)
this._onFailure.apply(this,[event]);
});
this.url = url;
this._onComplete = onComplete;
this._onFailure = onFailure;
this._addListeners();
}
private function _addListeners():void {
try {
this.loaderInfo.addEventListener(Event.COMPLETE, this._loadEnd, false, int.MAX_VALUE, true);
this.loaderInfo.addEventListener(IOErrorEvent.IO_ERROR, this._loadEnd, false, int.MAX_VALUE, true);
// IOErrorEvent.IO_ERROR must be listened to avoid this following error:
// IOErrorEvent non pris en charge : text=Error #2124: Le type du fichier chargé est inconnu.
this.loaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR, this._loadEnd, false, int.MAX_VALUE, true);
// SecurityErrorEvent.SECURITY_ERROR must be listened for the cross domain errors
/*if (this._onComplete != null) {
this.loaderInfo.addEventListener(Event.COMPLETE, this._onComplete);
}*/
if (this._onFailure != null) {
this.loaderInfo.addEventListener(IOErrorEvent.IO_ERROR, this._onFailure);
this.loaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR, this._onFailure);
}
} catch (e:Error) {
// Empty catch is evil, but here it’s fair.
}
}
private function _loadEnd(event:Event=null):void {
if (event==null || (event.type == TimerEvent.TIMER)) {
if (this._onFailure != null) {
this._onFailure(new IOErrorEvent(IOErrorEvent.IO_ERROR));
}
this.destroy(); // called last since the listeners will be removed
} else {
if (event.type == Event.COMPLETE) {
this._isCompleted = true;
if (this._onComplete != null) {
this._onComplete(new RequestEvent
(event.type,this.url,event.target,event.bubbles,event.cancelable));
}
}
else if (this._onFailure == null) {
switch (event.type) {
case IOErrorEvent.IO_ERROR:
case SecurityErrorEvent.SECURITY_ERROR:
Trace.error(event.toString());
break;
}
}
}
}
转载自:https://blog.csdn.net/wxljmy77/article/details/8834908