OpenLayers学习笔记2——坐标转换问题
参照别人的添加marker的demo来改造时,发现无论怎样更改经纬度,都是停留在同一个位置。过了一两天突然想起可能是坐标参考的问题,尝试搜了一下,果然是这个问题。问题是这样子的:
WMTS中地图的坐标参考系是102100(具体是哪个不清楚),如下图所示:

而我在初始化地图时设置的参数如下图所示:projection属性设置的是‘EPSG:102100’,displayProjection属性设置的是‘EPSG:4326’,也即经纬度显示。
projection
{String} Set in the map options to specify the default projection for layers added to this map. When using a projection other than EPSG:4326 (CRS:84, Geographic) or EPSG:3857 (EPSG:900913, Web Mercator), also set maxExtent, maxResolution or resolutions. Default is “EPSG:4326”. Note that the projection of the map is usually determined by that of the current baseLayer (see baseLayer and getProjectionObject).
displayProjection
{OpenLayers.Projection} Requires proj4js support for projections other than EPSG:4326 or EPSG:900913/EPSG:3857. Projection used by several controls to display data to user. If this property is set, it will be set on any control which has a null displayProjection property at the time the control is added to the map.

因此如果要利用经纬度进行定位标记的话,需要进行坐标转换,即EPSG:4326—>EPSG:102100,主要用到OpenLayers.LonLat的transform函数,代码如下:
- //坐标转换
- function corTransform(lon, lat) {
- var proj = new OpenLayers.Projection("EPSG:4326");
- var lonlat = new OpenLayers.LonLat(lon, lat);
- lonlat.transform(proj, this.map.getProjectionObject());
- return lonlat;
- }
OpenLayers.LonLat的transform函数代码:
- /**
- * APIMethod: transform
- * Transform the LonLat object from source to dest. This transformation is
- * *in place*: if you want a *new* lonlat, use .clone() first.
- *
- * Parameters:
- * source - {<OpenLayers.Projection>} Source projection.
- * dest - {<OpenLayers.Projection>} Destination projection.
- *
- * Returns:
- * {<OpenLayers.LonLat>} Itself, for use in chaining operations.
- */
- transform : function (source , dest) {
- var point = OpenLayers.Projection.transform(
- {'x' : this.lon , 'y' : this.lat} , source , dest);
- this.lon = point.x;
- this.lat = point.y;
- return this;
- } ,
通过查看源代码会发现它调用的是OpenLayers.Projection的transform方法,有兴趣的可以一步一步看到转换的源码,这里就不赘述了
- 顶
- 2
- 踩
OpenLayers学习笔记2——坐标转换问题的更多相关文章
- OpenLayers学习笔记4——使用jQuery UI实现測量对话框
OpenLayers学习最好的方式就是跟着其自带的演示样例进行学习,另外对web前端的开发设计要了解,慢慢积累,这样在一般的小项目中应该是足够用了. 本篇參照量測demo实现对话框形式的量測,抛砖引玉 ...
- openlayers 学习笔记一
1. 创建地图,加载控件 var map = new OpenLayers.Map("map", { projection: new OpenLayers.Projection(& ...
- OpenLayers学习笔记5——使用jQuery UI实现查询并标注(UI篇)
近期事情非常多,老板给的压力也非常大.经常出差,另外项目和个人研究还都要跟上,本月要交论文,还要写专利,仅仅能抽时间来学习其它的东西了. 关于OpenLayers的在博客中不会写太多详细的实现(网上有 ...
- OpenLayers学习笔记3——使用jQuery UI美化界面设计
PC端软件在开发是有较多的界面库能够选择,比方DevExpress.BCG.DotNetBar等,能够非常方便快捷的开发出一些炫酷的界面,近期在学习OpenLayers.涉及到web前端开发,在设计界 ...
- openlayers 学习笔记之1
1. 为Web Gis客户端开发的javascript 框架 百度文库中的教程:入门经典> 1) 初始化map: map = new OpenLayers.Map(mapContainerNam ...
- OpenLayers学习笔记(十)— 动态加载JSON数据模拟航迹线
在openlayers 3 上,加载本地json数据,动态绘制航迹线,以飞机当前位置为地图中心,此例子是模拟DEMO 本文链接:动态加载JSON数据模拟航迹线 作者:狐狸家的鱼 GitHub:八至 前 ...
- OpenLayers学习笔记(九)— 限制地图显示范围
openlayers 3 地图上限制地图显示及拖动范围,坐标系是4326转3857,中心经纬度精确到小数点后六位,减少误差 GitHub:八至 作者:狐狸家的鱼 本文链接:ol3-限制地图显示及拖动范 ...
- OpenLayers学习笔记(八)— 类似比例尺的距离环(二)
openlayers 3 地图上创建一个距离环,始终以地图中心为中心,每个环之间的距离类似比例尺,随地图缩放而变化. 添加具有覆盖整个范围的特征的虚拟层,其可以被设置为围绕地图中心的环. 这篇是上一篇 ...
- OpenLayers学习笔记(七)— 类似比例尺的距离环(一)
openlayers 3 地图上创建一个距离环,始终以地图中心为中心,每个环之间的距离类似比例尺,随地图缩放而变化. 添加具有覆盖整个范围的特征的虚拟层,其可以被设置为围绕地图中心的环.注意,根据地图 ...
随机推荐
- vue render & JSX
vue在绝大多数使用template是没问题的,但在某些场合下,使用render更适合. 一.render函数 1.createElement 参数 createElement 可接受三个参数 1){ ...
- [sql] view plain copy
[sql] view plain copy CREATE TABLE SYS_USER ( USER_CODE VARCHAR( 36 ) NOT NULL, LOGIN_NAME VARCHAR( ...
- Unity---UNet学习(2)----简单mmo游戏实现
1.实现步骤 新建空物体Controller,添加Network Manager.HUD组件. 创建Player模型,添加Inentity组件. Player添加脚本控制移动,只有当为本地用户才执行. ...
- Angular输入框内按下回车会触发其它button的点击事件的解决方法
方法:给button按钮添加type=“botton”属性
- Linux表面工作
https://www.cnblogs.com/welhzh/p/5899875.html 1.显示文本文件的内容 /etc/issue #登录前提示 /etc/motd #登录后提示 ssh ...
- iOS获取手机型号、iOS获取当前app的名称和版本号
NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary]; CFShow(infoDictionary); // ap ...
- myeclipse非正常关闭解决方法
http://blog.csdn.net/xb12369/article/details/24960347
- 16-----client、offset、scroll 系列
1.client 代码如下: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> ...
- Java文件与io——缓冲流
对文件或其它目标频繁的读写操作,效率低,性能差. 使用缓冲流的好处,能够更高效的读写信息,原理是将数据先缓冲起来,然后一起写入或者读取出来. BufferedInputStream:为另一个输入流添加 ...
- (转)运维老鸟教你安装centos6.5如何选择安装包
运维老鸟教你安装centos6.5如何选择安装包 原文:http://blog.51cto.com/oldboy/1564620 近来发现越来越多的运维小伙伴们都有最小化安装系统的洁癖,因此,找老男孩 ...