目前,关于OCG,WMS的Android客户端介绍的文章还是比较少。

下面翻译一篇很好的文章,介绍了如何实现WMS图层

原文地址
http://androidgps.blogspot.com/2008/09/simple-wms-client-for-android.html

Google's maps are not the only ones of interest: for those interested in science there are many more maps out there that show things like population density, cloud images, etc.
我们不仅仅对谷歌地图感兴趣,因为有很多地图服务具有特殊的科学意义,计算人口密度,显示云图像等等。
Some of these maps are available via Web Map Service WMS interfaces as specified by the OGC. WMS is essentially a standardised interface to maps on the Web that allows a client to specify the format (e.g. PNG), the size (e.g. 320x460) and the exact geographical coordinates: and what the user gets in return in an image.
这些地图服务中一些可以通过OGC规范的WMS形式发布。WMS是一个标准化的网络地图接口,它可以让客户端以地图坐标去确认(320x460)大小的PNG瓦片,从而返回用户一个完整的地图影像。

That makes it very easy to overlay Google Maps with all sorts of imagery, particularly satellite imagery.
这让用各种图层,尤其是卫星影像覆盖谷歌地图变得非常简单。
For this we start out defining a new Overlay class, WMSClient:

private class WMSOverlay extends Overlay {  @Override  public void draw(Canvas canvas, MapView mapView,           boolean shadow) {   super.draw(canvas, mapView, shadow);   WMSLoader wmsclient = new WMSLoader();   GeoPoint[] cornerCoords = MapUtils.getCornerCoordinates(mapView.getProjection(), canvas);   Bitmap image = wmsclient.loadMap(canvas.getWidth(), canvas.getHeight(), cornerCoords[0], cornerCoords[1]);      Paint semitransparent = new Paint();   semitransparent.setAlpha(0x888);   canvas.drawBitmap(image, 0, 0, semitransparent);  }   }

It is very simple: it somehow gets a Bitmap image from a class WMSLoader, to which I come in a second. Then it simply draws that image on the canvas, making it here semitransparent, so we see the underlying Google image.
这非常简单:就是是从WMSLoader中得到一幅位图。接着将图像画在容器中,让容器半透明,谷歌的影像就会在底图上了。
To get the WMS image we first need to get the corner coordinates of the screen, which is not very difficult as the projection object has a translation function for this (0,0) is the left top corner, and the right bottom is (width(), height()).
首先我们必须得到屏幕四角的坐标,这不是非常困难,因为头因对象以及通过函数this(0,0)得到左上角的坐标,而右下角的坐标为(width(), height())。


WMSLoader:

import java.io.IOException;import java.io.InputStream;import java.net.MalformedURLException;import java.net.URL;import android.graphics.Bitmap;import android.graphics.BitmapFactory;import android.util.Log;import com.google.android.maps.GeoPoint;public class WMSLoader { public static String TAG = "WMSLoader";  public Bitmap loadMap(int width, int height, GeoPoint ul, GeoPoint lr) {  URL url = null;       try {   url = new URL(String.format("http://iceds.ge.ucl.ac.uk/cgi-bin/icedswms?"  +     "LAYERS=lights&TRANSPARENT=true&FORMAT=image/png&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&EXCEPTIONS=application/vnd.ogc.se_inimage&SRS=EPSG:4326" + "" +     "&BBOX=%f,%f,%f,%f&WIDTH=%d&HEIGHT=%d",      MapUtils.longitude(ul), MapUtils.latitude(lr),     MapUtils.longitude(lr), MapUtils.latitude(ul), width, height));  } catch (MalformedURLException e) {   Log.e(TAG, e.getMessage());  }  InputStream input = null;  try {   input = url.openStream();  } catch (IOException e) {   Log.e(TAG, e.getMessage());  }  return BitmapFactory.decodeStream(input); }

This class here has most of the URL hard-coded for proof of concept. Here we get an image from the ICEDS server, an academic WMS Server at University College London. In this case the 'lights' layer, which shows night-time light pollution - an indication of populatio density (or industrial activity). We just compose the complete URL, then open the input stream, where we get the image and pass it back to our Overlay. Bingo.

这个类可接受大多数的URL。在个示例里我们得到ICEDS server数据,学术伦敦大学学院的WMS服务器的形象。在这种情况下,'light'层,这表明夜间光污染- 一个人口的密度(或工业活动)的指示。
我们组装的完整的URL,然后打input stream,我们就得到的图像,并将它传递到我们的叠加。

(There is a thing about projections: Google Maps uses a form of Mercator, the one supported by the ICEDS server is WGS84. That means pixels will not lie exactly on top of each other, but it matters most when the image is zoomed out. We would need a server supporting the Google Maps projection to be exact....)

有一个关于 投影 的事情 :谷歌 地图 使用了 墨卡托投影 ,由 ICEDS 服务器所支持的 一个是 WGS84坐标 形式。 这意味着 像素 在匹配 准确, 我们需要 一台 准确支持 谷歌地图 的投影的地图服务。

最后图如下:


博客中关于MapUtil类的迷也没有解开,不过在评论中找到了源代码

full example of his WMS

http://code.google.com/p/android-eksempler/source/browse/trunk/AndroidElementer/src/eks/kort/KortAktivitet.java

翻译的不好 ,见笑

更多相关文章

  1. android学习笔记---59_各种图形的使用介绍,android炫酷效果的实
  2. scrollview 滚动条
  3. webView自适应屏幕大小
  4. Android(安卓)APP —— “时光摄影” 的搭建手记(一)
  5. android基础知识07:SharedPreferences和PreferenceActivity
  6. android常用控件
  7. android之显示Log
  8. Android(安卓)SimpleAdapter自定义布局显示本地资源
  9. Android(安卓)点击back键两次退出程序

随机推荐

  1. Android运行时权限,6.0—9.0多版本,多终端(
  2. 个人开发者如何通过Android应用赚外快[推
  3. 还原Android PDU彩信
  4. Android的多语言实现
  5. android 调用系统文件管理器
  6. 混合开发之ReactNative调用Android原生方
  7. 【Android车载系统 News | Tech 2】News
  8. Android之ListView详解
  9. 冰淇淋三明治喂平板电脑也很好吃吗?(影片)
  10. 从.Net到Android之八:Android宏内核和微内