翻译代码200分送上

bunrise 2010-03-23 10:31:01
下面这段代码是OPENLAYES的源代码,本人正在研究
苦于JAVASCRIPT不是很熟练,特求高手翻译代码
要求:
每个属性的作用、方法的作用、属性方法被引用的地方、外部如何调用等等
越详细越好,JAVASCRIPT我是个很新的新手。。。
做完200分送上,高手留下QQ也行
谢谢各位,不要嫌长,大部分是老外注释
...全文
217 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
End_x 2012-03-14
  • 打赏
  • 举报
回复
用Firebug加断点调下 更好理解!毕竟是程序,不是英语!
rainsilence 2010-03-24
  • 打赏
  • 举报
回复
我虽然在你的另一个帖子里说过OpenLayers.Control.prototype.initilize.apply是调用父类构造体
但是OpenLayers.Control.prototype.activate.apply这里是调用父类的其他方法
类似于Java的super.activate
建议你从OpenLayers.Class和OpenLayers.Control入手
从表面上看OpenLayers.Class仅仅只是一个实现类功能的功能函数
而OpenLayers.Control应该是一个基类
土豆小小点 2010-03-24
  • 打赏
  • 举报
回复
天呀……看的恼火……太长了……
rainsilence 2010-03-24
  • 打赏
  • 举报
回复
这个是带有Ajax功能的控件吧。。。
Michael_76549786 2010-03-24
  • 打赏
  • 举报
回复
只是一些简单的 脚本异步操作 只不过原作 稍作封装了! 并没有用什么JS框架, 基本的脚本都是.
hao_ljp 2010-03-24
  • 打赏
  • 举报
回复
旁观。。。。。。。。。。。
SLL324 2010-03-24
  • 打赏
  • 举报
回复
四级没过的飘过
bunrise 2010-03-23
  • 打赏
  • 举报
回复
来个人回答啊。。。
另外在开100分帖
bunrise 2010-03-23
  • 打赏
  • 举报
回复

/**
* Method: request
* Sends a GetFeatureInfo request to the WMS
*
* Parameters:
* clickPosition - {<OpenLayers.Pixel>} The position on the map where the
* mouse event occurred.
* options - {Object} additional options for this method.
*
* Valid options:
* - *hover* {Boolean} true if we do the request for the hover handler
*/
request: function(clickPosition, options) {
options = options || {};
var layerNames = [];
var styleNames = [];

var layers = this.findLayers();
if(layers.length > 0) {

for (var i = 0, len = layers.length; i < len; i++) {
layerNames = layerNames.concat(layers[i].params.LAYERS);
// in the event of a WMS layer bundling multiple layers but not
// specifying styles,we need the same number of commas to specify
// the default style for each of the layers. We can't just leave it
// blank as we may be including other layers that do specify styles.
if (layers[i].params.STYLES) {
styleNames = styleNames.concat(layers[i].params.STYLES);
} else {
if (layers[i].params.LAYERS instanceof Array) {
styleNames = styleNames.concat(new Array(layers[i].params.LAYERS.length));
} else { // Assume it's a String
styleNames = styleNames.concat(layers[i].params.LAYERS.replace(/[^,]/g, ""));
}
}
}

var wmsOptions = {
url: this.url,
params: OpenLayers.Util.applyDefaults({
service: "WMS",
version: "1.1.0",
request: "GetFeatureInfo",
layers: layerNames,
query_layers: layerNames,
styles: styleNames,
bbox: this.map.getExtent().toBBOX(),
srs: this.map.getProjection(),
feature_count: this.maxFeatures,
x: clickPosition.x,
y: clickPosition.y,
height: this.map.getSize().h,
width: this.map.getSize().w,
info_format: this.infoFormat
}, this.vendorParams),
callback: function(request) {
this.handleResponse(clickPosition, request);
},
scope: this
};

var response = OpenLayers.Request.GET(wmsOptions);

if (options.hover === true) {
this.hoverRequest = response.priv;
}
} else {
// Reset the cursor.
OpenLayers.Element.removeClass(this.map.viewPortDiv, "olCursorWait");
}
},

/**
* Method: handleResponse
* Handler for the GetFeatureInfo response.
*
* Parameters:
* xy - {<OpenLayers.Pixel>} The position on the map where the
* mouse event occurred.
* request - {XMLHttpRequest} The request object.
*/
handleResponse: function(xy, request) {

var doc = request.responseXML;
if(!doc || !doc.documentElement) {
doc = request.responseText;
}
var features = this.format.read(doc);

this.events.triggerEvent("getfeatureinfo", {
text: request.responseText,
features: features,
request: request,
xy: xy
});

// Reset the cursor.
OpenLayers.Element.removeClass(this.map.viewPortDiv, "olCursorWait");
},

/**
* Method: setMap
* Set the map property for the control.
*
* Parameters:
* map - {<OpenLayers.Map>}
*/
setMap: function(map) {
this.handler.setMap(map);
OpenLayers.Control.prototype.setMap.apply(this, arguments);
},

CLASS_NAME: "OpenLayers.Control.WMSGetFeatureInfo"
});
bunrise 2010-03-23
  • 打赏
  • 举报
回复

/**
* @requires OpenLayers/Control.js
* @requires OpenLayers/Handler/Click.js
* @requires OpenLayers/Handler/Hover.js
* @requires OpenLayers/Request.js
*/
OpenLayers.Control.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Control, {

/**
* APIProperty: hover
* {Boolean} Send GetFeatureInfo requests when mouse stops moving.
* Default is false.
*/
hover: false,

/**
* APIProperty: maxFeatures
* {Integer} Maximum number of features to return from a WMS query. This
* sets the feature_count parameter on WMS GetFeatureInfo
* requests.
*/
maxFeatures: 10,

/**
* Property: layers
* {Array(<OpenLayers.Layer.WMS>)} The layers to query for feature info.
* If omitted, all map WMS layers with a url that matches this <url> or
* <layerUrl> will be considered.
*/
layers: null,

/**
* Property: queryVisible
* {Boolean} If true, filter out hidden layers when searching the map for
* layers to query. Default is false.
*/
queryVisible: false,

/**
* Property: url
* {String} The URL of the WMS service to use. If not provided, the url
* of the first eligible layer will be used.
*/
url: null,

/**
* Property: layerUrls
* {Array(String)} Optional list of urls for layers that should be queried.
* This can be used when the layer url differs from the url used for
* making GetFeatureInfo requests (in the case of a layer using cached
* tiles).
*/
layerUrls: null,

/**
* Property: infoFormat
* {String} The mimetype to request from the server
*/
infoFormat: 'text/html',

/**
* Property: vendorParams
* {Object} Additional parameters that will be added to the request, for
* WMS implementations that support them. This could e.g. look like
* (start code)
* {
* radius: 5
* }
* (end)
*/
vendorParams: {},

/**
* Property: format
* {<OpenLayers.Format>} A format for parsing GetFeatureInfo responses.
* Default is <OpenLayers.Format.WMSGetFeatureInfo>.
*/
format: null,

/**
* Property: formatOptions
* {Object} Optional properties to set on the format (if one is not provided
* in the <format> property.
*/
formatOptions: null,

/**
* APIProperty: handlerOptions
* {Object} Additional options for the handlers used by this control, e.g.
* (start code)
* {
* "click": {delay: 100},
* "hover": {delay: 300}
* }
* (end)
*/
handlerOptions: null,

/**
* Property: handler
* {Object} Reference to the <OpenLayers.Handler> for this control
*/
handler: null,

/**
* Property: hoverRequest
* {<OpenLayers.Request>} contains the currently running hover request
* (if any).
*/
hoverRequest: null,

/**
* Constant: EVENT_TYPES
*
* Supported event types (in addition to those from <OpenLayers.Control>):
* getfeatureinfo - Triggered when a GetFeatureInfo response is received.
* The event object has a *text* property with the body of the
* response (String), a *features* property with an array of the
* parsed features, an *xy* property with the position of the mouse
* click or hover event that triggered the request, and a *request*
* property with the request itself.
*/
EVENT_TYPES: ["getfeatureinfo"],

/**
* Constructor: <OpenLayers.Control.WMSGetFeatureInfo>
*
* Parameters:
* options - {Object}
*/
initialize: function(options) {
// concatenate events specific to vector with those from the base
this.EVENT_TYPES =
OpenLayers.Control.WMSGetFeatureInfo.prototype.EVENT_TYPES.concat(
OpenLayers.Control.prototype.EVENT_TYPES
);

options = options || {};
options.handlerOptions = options.handlerOptions || {};

OpenLayers.Control.prototype.initialize.apply(this, [options]);

if(!this.format) {
this.format = new OpenLayers.Format.WMSGetFeatureInfo(
options.formatOptions
);
}

if (this.hover) {
this.handler = new OpenLayers.Handler.Hover(
this, {
'move': this.cancelHover,
'pause': this.getInfoForHover
},
OpenLayers.Util.extend(this.handlerOptions.hover || {}, {
'delay': 250
}));
} else {
this.handler = new OpenLayers.Handler.Click(this,
{click: this.getInfoForClick}, this.handlerOptions.click || {});
}
},

/**
* Method: activate
* Activates the control.
*
* Returns:
* {Boolean} The control was effectively activated.
*/
activate: function () {
if (!this.active) {
this.handler.activate();
}
return OpenLayers.Control.prototype.activate.apply(
this, arguments
);
},

/**
* Method: deactivate
* Deactivates the control.
*
* Returns:
* {Boolean} The control was effectively deactivated.
*/
deactivate: function () {
return OpenLayers.Control.prototype.deactivate.apply(
this, arguments
);
},

/**
* Method: getInfoForClick
* Called on click
*
* Parameters:
* evt - {<OpenLayers.Event>}
*/
getInfoForClick: function(evt) {
// Set the cursor to "wait" to tell the user we're working on their
// click.
OpenLayers.Element.addClass(this.map.viewPortDiv, "olCursorWait");
this.request(evt.xy, {});
},

/**
* Method: getInfoForHover
* Pause callback for the hover handler
*
* Parameters:
* evt - {Object}
*/
getInfoForHover: function(evt) {
this.request(evt.xy, {hover: true});
},

/**
* Method: cancelHover
* Cancel callback for the hover handler
*/
cancelHover: function() {
if (this.hoverRequest) {
this.hoverRequest.abort();
this.hoverRequest = null;
}
},

/**
* Method: findLayers
* Internal method to get the layers, independent of whether we are
* inspecting the map or using a client-provided array
*/
findLayers: function() {

var layers = [];

var candidates = this.layers || this.map.layers;
var layer, url;
for(var i=0, len=candidates.length; i<len; ++i) {
layer = candidates[i];
if(layer instanceof OpenLayers.Layer.WMS &&
(!this.queryVisible || layer.getVisibility())) {
url = layer.url instanceof Array ? layer.url[0] : layer.url;
// if the control was not configured with a url, set it
// to the first layer url
if(!this.url) {
this.url = url;
}
if(this.urlMatches(url)) {
layers.push(layer);
}
}
}

return layers;
},

/**
* Method: urlMatches
* Test to see if the provided url matches either the control <url> or one
* of the <layerUrls>.
*
* Parameters:
* url - {String} The url to test.
*
* Returns:
* {Boolean} The provided url matches the control <url> or one of the
* <layerUrls>.
*/
urlMatches: function(url) {
var matches = OpenLayers.Util.isEquivalentUrl(this.url, url);
if(!matches && this.layerUrls) {
for(var i=0, len=this.layerUrls.length; i<len; ++i) {
if(OpenLayers.Util.isEquivalentUrl(this.layerUrls[i], url)) {
matches = true;
break;
}
}
}
return matches;
},

KK3K2005 2010-03-23
  • 打赏
  • 举报
回复
物有本末 事有终始
自认为是JS很新的新手就先去看JS的语法,关键字的东西
看熟练了 自己在多写写 写的多了 在看好的源代码

另外上面代码中本身的注释已经写的很好很规范了 直接GOOGLE翻译下就可以了
webphoenix 2010-03-23
  • 打赏
  • 举报
回复
牵涉到很多个其他的js,单纯一个js不好分析
thinkinginAOCP 2010-03-23
  • 打赏
  • 举报
回复
看了下 openplayer的网站,
汗!~
thinkinginAOCP 2010-03-23
  • 打赏
  • 举报
回复
LZ可以把你的QQ留下!~
thinkinginAOCP 2010-03-23
  • 打赏
  • 举报
回复
js代码还是有兴趣的,貌似关联代码 N多

/**
* @requires OpenLayers/Control.js
* @requires OpenLayers/Handler/Click.js
* @requires OpenLayers/Handler/Hover.js
* @requires OpenLayers/Request.js
*/
那边有多少文件;
bunrise 2010-03-23
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 amos1989 的回复:]
这么长...200分都不想干....
[/Quote]

如果你能干,你说要多少?
amos1989 2010-03-23
  • 打赏
  • 举报
回复
这么长...200分都不想干....
bunrise 2010-03-23
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 nightsky_0911 的回复:]
ExtJS 的代码,自己去找些ExtJS 看看吧
[/Quote]

不是这个东西
nightsky_0911 2010-03-23
  • 打赏
  • 举报
回复
ExtJS 的代码,自己去找些ExtJS 看看吧

87,922

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧