用户操作
[即时聊天] [发私信] [加为好友]
粟卫民ID:suen
141282次访问,排名564好友37人,关注者81
爱好技术,爱好开源,在华工学过计算机,在武测学过GIS,国家认证系统分析师,曾负责或参与中国科学院开放基金、国家基础测绘科技计划、国家自然科学基金、××市人防指挥地理信息系统、境界数据建库、地图网站等多个项目。因热心GIS技术传播而获得“CSDN地理信息专家”称号,虽然自己觉得离专家的差距还很大,但一直在努力,^-^。
suen的文章
原创 39 篇
翻译 5 篇
转载 41 篇
评论 65 篇
小粟的公告
终于完成GeoWeb开源社区(http://www.gisdev.cn)的搭建和初步测试,请大家注册用户,测试,并提出宝贵意见。
最近评论
douweibin:我也建了一个群 群号是 51824242 也做您的后备群用吧 呵呵
sparkwong3:#common22 发表于2008-08-07 15:54:58 IP: 119.40.19.*
不知道你注意到没有 百度地图其实用的是mapbar的图片引擎

对的
chenshengbj:你好!我想问一下,怎么用GDAL类库对栅格影像进行矢量化?GDAL提供矢量多边形的最小外包矩形的接口吗?我的邮箱是chenshengbj@163.com,希望给我好消息。我继续这几个功能。
xbt746:呵呵,为什么不用postgresql试试
xbt746:呵呵,为什么不用postgresql试试
文章分类
收藏
    相册
    我的照片
    GIS
    .NET开源GIS翻译WiKi
    GeoWeb开源社区
    GIS空间站
    GIS论坛
    中科院地理所
    国家测绘局
    我的旧BLOG归档
    存档
    软件项目交易
    订阅我的博客
    XML聚合  FeedSky
    订阅到鲜果
    订阅到Google
    订阅到抓虾
    订阅到BlogLines
    订阅到Yahoo
    订阅到GouGou
    订阅到飞鸽
    订阅到Rojo
    订阅到newsgator
    订阅到netvibes

    转载 OpenLayers 项目分析[转](三):BaseTypes收藏

    新一篇: OpenLayers 项目分析[转](三):BaseTypes (续) | 旧一篇: OpenLayers 项目分析[转](二):源代码总体结构分析

    (三)BaseTypes :定义底层类与定制JS内置类

    为了让更多的人看到这篇好文章,我把它转载到这里,这篇文章转载自http://www.3snews.net/html/24/10624-17449.html,原文作者如觉得不妥,可联系我删除之。

      

     

        先说基类型BaseTypes下,OpenLyers构建的“自己”的类。它们分别是:OpenLayers. LonLat、OpenLayers. Pixel、OpenLayers.Size、OpenLayers. Element、OpenLayers. Bounds和OpenLayers. Class。下面分别介绍:

      OpenLayers. LonLat:经纬度类,其实例为地图提供一经度、纬度对,即位置。有两个属性lon(x-axis coodinate )和lat(y-axis coordinate )。这里说明一下,怎么经纬度又与x轴坐标、y轴坐标纠缠在一起?是这样:当地图是在地理坐标投影下,它就是经纬度;不然就是地图上的x/y轴坐标。除构造函数外,实现了五个函数:

    toShortString:function() 把坐标转换为字符串;

    clone:function()  复制一个LonLat对象;

    Add:function(lon,lat)  改变现有地图的位置;

      return new OpenLayers.LonLat(this.lon + lon, this.lat + lat);

    equals:function(ll)  判断传入的lon,lat对是否与当前的相等;

    wrapDateLine:function(maxExtent)  复制下(lon,lat),指定为边界的最大范围。

     

      OpenLayers. Pixel:像素类,在显示器上以(x,y)坐标的的形式呈现像素位置。有两个属性x坐标、y坐标,提供四个成员函数:

    clone:function() 拷贝像素;

    equals:function(px)  判断两像素是否相等;

    add:function(x,y)  改变(x,y)使其成为新像素;

    return new OpenLayers.Pixel(this.x + x, this.y + y);

    offset:function(px)  调用add()使像素位置发生偏移。

      newPx = this.add(px.x, px.y);

     

      OpenLayers.Size:也有两个属性,宽度width、高度height。实现了两个成员函数:clone:function()和equals:function(sz)不多说了。

     

      OpenLayers. Element:在这个名称空间下,开发者写了好多API,有visible、toggle、hide、show、remove、getHeight、getDimensions和getStyle,以实现元素的显示、隐藏、删除、取得高度,取得范围等功能。以getHeight函数为例我们看看它的代码:

      /**

         * APIFunction: getHeight

         *  

         * Parameters:

         * element - {DOMElement}

         * 

         * Returns:

         * {Integer} The offset height of the element passed in

         */

        getHeight: function(element) {

            element = OpenLayers.Util.getElement(element);

            return element.offsetHeight;

        }

    这里涉及到文档对象模型DOM的一些东西,函数本身很简单,最后返回元素的高度。

     

      OpenLayers. Bounds:在这个类中,数据以四个浮点型数left, bottom, right, top 的格式存储,它是一个像盒子一样的范围。它实现了三个描述一个Bound的函数:toString、toArray和toBBOX。其中,toString的代码如下:

      /** 

         * APIMethod: toString

         * 

         * Returns:

         * {String} String representation of bounds object. 

         *          (ex.<i>"left-bottom=(5,42) right-top=(10,45)"</i>)

         */

        toString:function() {

            return ( "left-bottom=(" + this.left + "," + this.bottom + ")"

                     + " right-top=(" + this.right + "," + this.top + ")" );

        }

    结果类似于"left-bottom=(5,42) right-top=(10,45)"

      三个Bound数据来源函数:fromString、fromArray和fromSize;

    五个获取对象属性的函数:getWidth、getHeight、getSize、getCenterPixel、getCenterLonLat;

    余下还有:add:function(x,y),extend:function(object),containsLonLat,containsPixel,contains,intersectsBounds,containsBounds,determineQuadrant,wrapDateLine。以函数extend为例,看看源码。

        extend:function(object) {

            var bounds = null;

            if (object) {

                switch(object.CLASS_NAME) {

                    case "OpenLayers.LonLat":    

                        bounds = new OpenLayers.Bounds    (object.lon, object.lat, object.lon, object.lat);

                        break;

                    case "OpenLayers.Geometry.Point":

                        bounds = new OpenLayers.Bounds(object.x, object.y,object.x, object.y);

                        break;                 

                    case "OpenLayers.Bounds":   

                        bounds = object;

                        break;

                }

                if (bounds) {

                    if ( (this.left == null) || (bounds.left < thi                     s.left)) {

                         this.left = bounds.left;}

                    if ( (this.bottom == null) || (bounds.bottom <                     this.bottom) ) {

                        this.bottom = bounds.bottom;} 

                    if ( (this.right == null) || (bounds.right > t                    his.right) ) {

                        this.right = bounds.right;}

                    if ( (this.top == null) || (bounds.top > this.                    top) ) { 

                        this.top = bounds.top;}

                }

            }

        }

    可以看出,对Bounds的扩展可以有三种形式:point, lonlat, 或者bounds,计算的条件是零坐标是在屏幕的左上角。

     

      OpenLayers. Class:这个类是OpenLayers 中的“大红人”,只要创建其他类就得用它,同时也实现了多重继承。用法如下:

      单继承创建:class = OpenLayers.Class(prototype);

      多继承创建:class = OpenLayers.Class(Class1, Class2, prototype);

        净说底层类了,对js内置类的扩展下回写。

     

     

     

    欢迎转载,请注明出处。

    发表于 @ 2008年05月08日 13:19:03|评论(loading...)|编辑

    新一篇: OpenLayers 项目分析[转](三):BaseTypes (续) | 旧一篇: OpenLayers 项目分析[转](二):源代码总体结构分析

    评论:没有评论。

    发表评论  


    当前用户设置只有注册用户才能发表评论。如果你没有登录,请点击登录
    Csdn Blog version 3.1a
    Copyright © 小粟