Gis 屏幕坐标到纬度和经度
在开放层库中,以下是用于将屏幕坐标转换为纬度和经度的方法。我无法理解这个方法封装的逻辑Gis 屏幕坐标到纬度和经度,gis,latitude-longitude,openlayers,Gis,Latitude Longitude,Openlayers,在开放层库中,以下是用于将屏幕坐标转换为纬度和经度的方法。我无法理解这个方法封装的逻辑 getLatLonFromPoint: function (point) { var center = this.getCenter(); //map center lat/lon var res = this.getResolution(); //pre defined by the user. Represents the change in lat long per
getLatLonFromPoint: function (point) {
var center = this.getCenter();
//map center lat/lon
var res = this.getResolution();
//pre defined by the user. Represents the change in lat long per screen unit at the given zoom level
var size = this.getSize();
//this is the width and height of the div in which the map has to be displayed
var delta_x = point.x - (size.w / 2);
var delta_y = point.y - (size.h / 2);
return new OpenLayers.LatLon(
center.lat - delta_y * res,
center.lon + delta_x * res );
}
getLatLonFromPoint:函数(点){
var center=this.getCenter();
//地图中心lat/lon
var res=this.getResolution();
//由用户预定义。表示给定缩放级别下每个屏幕单位的lat long变化
var size=this.getSize();
//这是必须显示地图的div的宽度和高度
var delta_x=点x-(尺寸w/2);
var delta_y=点y-(尺寸h/2);
返回新的OpenLayers.LatLon(
center.lat-delta_y*res,
center.lon+delta_x*res);
}
有人可以提供一些指针吗?该函数根据地图的当前分辨率、当前地图中心点的纬度和经度以及所选点与地图中心的距离计算指定点的纬度和经度 var center = this.getCenter(); //map center lat/lon var res = this.getResolution(); //pre defined by the user. Represents the change in lat long ... var size = this.getSize(); var center=this.getCenter(); //地图中心lat/lon var res=this.getResolution(); //由用户预定义。表示lat long中的更改。。。 var size=this.getSize(); 上面的代码位收集了计算所需的信息:当前地图视图的中心点(这将为我们提供中心点上的lat/lon)、当前地图分辨率以及用户屏幕上的当前地图大小(可能受屏幕大小等影响) 然后计算如下: //this is the width and height of the div in which the map has to be displayed var delta_x = point.x - (size.w / 2); var delta_y = point.y - (size.h / 2); //这是必须显示地图的div的宽度和高度 var delta_x=点x-(尺寸w/2); var delta_y=点y-(尺寸h/2); 首先取x坐标(以像素为单位)并减去贴图的宽度(以像素为单位)。这给了我们一个新的x坐标,其中0是地图的中心像素。delta-x现在应该是介于-(size.w/2)到+(size.w/2)之间的像素值。 然后我们对y公司做同样的事情。 所以delta-x和delta-y现在是笛卡尔坐标,原点在地图的中心 return new OpenLayers.LatLon( center.lat - delta_y * res, center.lon + delta_x * res ); 返回新的OpenLayers.LatLon( center.lat-delta_y*res, center.lon+delta_x*res); 我们需要将delta-x和delta-y从像素转换为lat/lon。首先,我们用当前分辨率乘以delta-x和delta-y。这给了我们正确的比例,但没有正确的原点。添加center.lat和center.lon adusts,根据当前显示的地图提供lat/lon 最后,“new OpenLayers.LatLon”调用只是将上述计算封装在一个LatLon对象中,这样就可以将其作为LatLon对象从函数中返回 编辑:处理像素时,x坐标的增加通常意味着“向右移动”,y坐标的增加通常意味着“向上移动”。在地图上,当你增加经度时,你通常会“向右移动”。然而,纬度是颠倒的;当你增加纬度时,你通常会在地图上“向下移动”
因此,纬度的工作方向与屏幕上的正常y坐标方案相反。因此,在最终计算中,center.lat使用减号,center.lon使用加号。该函数根据地图的当前分辨率以及当前地图中心点的纬度和经度计算指定点的纬度和经度,以及所选点与地图中心的距离 var center = this.getCenter(); //map center lat/lon var res = this.getResolution(); //pre defined by the user. Represents the change in lat long ... var size = this.getSize(); var center=this.getCenter(); //地图中心lat/lon var res=this.getResolution(); //由用户预定义。表示lat long中的更改。。。 var size=this.getSize(); 上面的代码位收集了计算所需的信息:当前地图视图的中心点(这将为我们提供中心点上的lat/lon)、当前地图分辨率以及用户屏幕上的当前地图大小(可能受屏幕大小等影响) 然后计算如下: //this is the width and height of the div in which the map has to be displayed var delta_x = point.x - (size.w / 2); var delta_y = point.y - (size.h / 2); //这是必须显示地图的div的宽度和高度 var delta_x=点x-(尺寸w/2); var delta_y=点y-(尺寸h/2); 首先取x坐标(以像素为单位)并减去贴图的宽度(以像素为单位)。这给了我们一个新的x坐标,其中0是地图的中心像素。delta-x现在应该是介于-(size.w/2)到+(size.w/2)之间的像素值。 然后我们对y公司做同样的事情。 所以delta-x和delta-y现在是笛卡尔坐标,原点在地图的中心 return new OpenLayers.LatLon( center.lat - delta_y * res, center.lon + delta_x * res ); 返回新的OpenLayers.LatLon( center.lat-delta_y*res, center.lon+delta_x*res); 我们需要将delta-x和delta-y从像素转换为lat/lon。首先,我们用当前分辨率乘以delta-x和delta-y。这给了我们正确的比例,但没有正确的原点。添加center.lat和center.lon adusts,根据当前显示的地图提供lat/lon 最后,“new OpenLayers.LatLon”调用只是将上述计算封装在一个LatLon对象中,这样就可以将其作为LatLon对象从函数中返回 编辑:处理像素时,x坐标的增加通常意味着“向右移动”,y坐标的增加通常意味着“向上移动”。在地图上,当你增加经度时,你通常会“向右移动”。然而,纬度是颠倒的;当你增加纬度时,你通常会在地图上“向下移动”
因此,纬度的工作方向与屏幕上的正常y坐标方案相反。因此,在最终的计算中,center.lat使用负号,center.lon使用加号。我重新排列了现有的注释,添加了一些注释,并添加了一些空白。希望你会发现这一点更清楚
getLatLonFromPoint: function (point) {
// point is the x and y screen coordinate
// map center lat/lon
var center = this.getCenter();
// pre defined by the user. Represents the change in lat long per screen unit at the given zoom level
var res = this.getResolution();
// this is the width and height of the screen (div) in which the map has to be displayed
var size = this.getSize();
// this is the distance of the point from the center of the screen (div)
var delta_x = point.x - (size.w / 2);
var delta_y = point.y - (size.h / 2);
// return the latitude and longitude
// these are calculated from the center lat/lon using the
// screen distances which are scaled (multiplied) by the resolution
return new OpenLayers.LatLon(
center.lat - delta_y * res,
center.lon + delta_x * res );
}
我重新整理了现有的评论,添加了更多的评论,并添加了一些空白。希望你会发现这一点更清楚
getLatLonFromPoint: function (point) {
// point is the x and y screen coordinate
// map center lat/lon
var center = this.getCenter();
// pre defined by the user. Represents the change in lat long per screen unit at the given zoom level
var res = this.getResolution();
// this is the width and height of the screen (div) in which the map has to be displayed
var size = this.getSize();
// this is the distance of the point from the center of the screen (div)
var delta_x = point.x - (size.w / 2);
var delta_y = point.y - (size.h / 2);
// return the latitude and longitude
// these are calculated from the center lat/lon using the
// screen distances which are scaled (multiplied) by the resolution
return new OpenLayers.LatLon(
center.lat - delta_y * res,
center.lon + delta_x * res );
}
试试这个:
map.events.register("mousemove", map, function(e) {
var position = this.events.getMousePosition(e);
var p = map.getLonLatFromPixel(new OpenLayers.Pixel(position.x, position.y));
// your longitude value = p.lon;
// your latitude value = p.lat;
});
试试这个:
map.events.register("mousemove", map, function(e) {
var position = this.events.getMousePosition(e);
var p = map.getLonLatFromPixel(new OpenLayers.Pixel(position.x, position.y));
// your longitude value = p.lon;
// your latitude value = p.lat;
});
你能告诉我为什么把center.lat添加到delta中,而把center.lon添加到delta中吗