參照别人的加入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方法,有兴趣的能够一步一步看到转换的源代码,这里就不赘述了

转载于:https://www.cnblogs.com/blfbuaa/p/7131586.html

OpenLayers学习笔记2——坐标转换问题相关推荐

  1. OpenLayers学习笔记5——使用jQuery UI实现查询并标注(UI篇)

    近期事情非常多,老板给的压力也非常大.经常出差,另外项目和个人研究还都要跟上,本月要交论文,还要写专利,仅仅能抽时间来学习其它的东西了. 关于OpenLayers的在博客中不会写太多详细的实现(网上有 ...

  2. OpenLayers学习笔记高级篇(一、openlayers画点线面)

    话不多说直接上代码: <!doctype html> <html xmlns=http://www.w3.org/1999/xhtml> <head> <me ...

  3. OpenLayers学习笔记中级篇(一、各种地图的加载)

    学习了前面的初级篇,相信大家对OplenLayers已经有了一个初步的认识,下面我们再继续深入学习OpenLayers的相关功能! 我们这节主要是加载各种各样的地图,包括在线服务的地图,比如天地图.高 ...

  4. OpenLayers 学习笔记(一)

    前言 这两学习到了地图开发,去搜了一下免费开源平台有好多,其中以百度,高德,OpenLayers这三个使用最多,这次主要是以OpenLayers进行学习记录本文基本都是自己在du来的在线记录 Open ...

  5. OpenLayers学习笔记高级篇(二、地图控件)

    在OpenLayers 3中,地图控件指的是下图标注的这些,包括缩放按钮,标尺,版权说明,指北针等等. 他们不会随着地图的移动而移动,一直处于一个固定的位置. 在实现上,并不是在画布上绘制的,而是使用 ...

  6. OpenLayers学习笔记6——使用jQuery UI实现查询并标注(功能实现篇)

    本篇博客接上篇是关于OpenLayers的地图标注及弹出窗(marker+popup),先来看下效果图: 本篇参考了博客:[openlayers]CSS3样式的Popups

  7. OpenLayers学习笔记高级篇(四、地图开发实战之地图要素的增删改查)

    一切都准备好了,现在终于可以通过ol3加载配置好的数据了.上一节中最后的预览结果,大家已经看到了,此处我们自己通过ol来实现这个预览页面,直接上代码如下: 1.加载Geoserver发布的wfs地图服 ...

  8. OpenLayers学习笔记7——使用javaBean实现用户登录

    之前的开发是采用phpStorm,前端:html+css+javascript+jquery,服务器端:php:但是这个前后台交互要通过ajax来实现数据交互,中间遇到了跨域的问题,卡了两天虽然解决了 ...

  9. openlayers地图旋转_地图切换动画#openlayers入门笔记#

    本博客合集是我的openlayers学习笔记,希望能帮助到刚开始接触openlayers的同学 @commnet 所用openlayers版本:v5.3.0 @commnet 阅读本文前需要对前端知识 ...

最新文章

  1. python----面试题(一)
  2. hadoop,hbase,hive安装全记录
  3. spring心得5--构造器注入@设置控制@案例加注解剖析
  4. 开发IOT WiFi设备时,需要测试的几种情况
  5. 基于Boost::beast模块的单元测试程序
  6. Web Storage API的介绍和使用
  7. CF1034E Little C Loves 3 III(神仙构造+FWT_OR卷积)
  8. 苹果双系统运行oracle失败,oracle 11gR2 RAC for linux x86_64 grid运行root.sh 失败问题处理...
  9. “.NET研究”谈谈C# 4.0新特性“缺省参数”的实现
  10. Linux笔记-rpm与yum的基本概念
  11. hadoop记录topk
  12. mongodb常用操作命令(待续)
  13. Collat​​e SQL命令概述
  14. 【网易云课堂---轻松读书:番茄工作法】
  15. iOS 8.0正式公布啦
  16. Android沉浸式
  17. 运维的升级打怪之路v2版
  18. 领导者都具备的四大思维能力
  19. 声纹识别demo_声纹识别 iOS SDK 文档
  20. php实现数字英文验证码,php 英文、数字验证码的完整代码

热门文章

  1. python详细安装教程3.7.0-Python 3.7.0安装教程(附安装包) | 我爱分享网
  2. python网站开发实例-【9】Python接口开发:flask Demo实例
  3. python爬虫吧-python爬虫-爬取百度贴吧帖子加图片
  4. python 编程入门-实验一 Python程序设计入门
  5. python 难度-python上手难度算较低
  6. python基础包括什么-python中f是什么
  7. python编程能干什么-Python编程一般可以用来做什么
  8. 零基础python从入门到精通 pdf-跟老齐学Python从入门到精通.pdf
  9. python学习费用-python学习,是看免费视频自学,还是报个收费班学习好?
  10. 0基础学python-如何从零基础自学Python?