根据经纬度坐标获取对应的切片算法

根据经纬度坐标获取对应的切片算法,含天地图、谷歌等。

Javascript:

  1 function getPoints2()
  2 {
  3     var topTileFromX  = -180;
  4     var topTileFromY  =  90;
  5
  6     var tdtScale={18:5.36441802978515E-06,17:1.07288360595703E-05,16:2.1457672119140625E-05,15:4.29153442382814E-05,14:8.58306884765629E-05,13:0.000171661376953125,12:0.00034332275390625,11:0.0006866455078125,10:                  0.001373291015625,9:0.00274658203125,8:0.0054931640625,7:0.010986328125,6:0.02197265625,5:0.0439453125,4:0.087890625,3:0.17578125,2:0.3515625,1:0.703125};
  7
  8     var strList = document.getElementById("content").value;
  9
 10
 11     var oStringList = strList.split(‘,‘);
 12     var level  = oStringList[0];
 13     var lon    =  oStringList[1];
 14     var lat   =  oStringList[2];
 15
 16
 17        var coef =  tdtScale[level]*256;
 18
 19     var x_num =  Math.round((lon - topTileFromX) / coef);
 20     var y_num =  Math.round((topTileFromY - lat) / coef);
 21
 22    //  var dir =  "http://t7.tianditu.com/DataServer?T=vec_c&";
 23     // var server = "l="+String(level)+"&"+"x="+String(x_num)+"&"+"y="+String(y_num);
 24
 25
 26     var  dir = "http://t1.tianditu.cn/vec_c/wmts?SERVICE=WMTS&REQUEST=GetTile&STYLE=default&VERSION=1.0.0&LAYER=vec&TILEMATRIXSET=c&";
 27      var server = "TILEMATRIX="+String(level)+"&"+"TILEROW="+String(y_num)+"&"+"TILECOL="+String(x_num)+"&FORMAT=tiles";
 28
 29
 30      var imageDir = dir+server;
 31
 32
 33     // alert(imageDir);
 34
 35      var imgDiv = document.getElementById("map");
 36      imgDiv.style.backgroundImage =  "url("+imageDir+")";
 37
 38
 39
 40 }
 41
 42
 43 function lon2Mercator(px)
 44 {
 45     var x = px * 20037508.3427892 / 180;
 46     return x;
 47 }
 48
 49  function lat2Mercator(py)
 50         {
 51
 52             var y;
 53             y = Math.log(Math.tan((90 + py) * Math.PI / 360)) / (Math.PI / 180);
 54
 55             y = y * 20037508.3427892 / 180;
 56
 57             return y;
 58         }
 59
 60 function getPoints3()
 61 {
 62
 63
 64     var topTileFromX  = -20037508.3427892;
 65     var topTileFromY  =  20037508.3427892;
 66
 67     var tdtScale={18:0.597164283559817,17:1.19432856685505,16:2.38865713397468,15:4.77731426794937,14:9.55462853563415,13:19.1092570712683,12:38.2185141425366,11:76.4370282850732,10:152.8740565704,9:305.7481128,8:611.49622628138,7:1222.99245256249,6:2445.98490512499,5:4891.96981024998,4:9783.93962049996,3:19567.8792409999,2:39135.7584820001,1:78271.5169639999};
 68
 69     var strList = document.getElementById("content").value;
 70
 71
 72     var oStringList = strList.split(‘,‘);
 73     var level  = oStringList[0];
 74     var lon    =  oStringList[1];
 75     var lat    =  oStringList[2];
 76
 77     lon = lon2Mercator(parseFloat(lon));
 78     lat = lat2Mercator(parseFloat(lat));
 79
 80        var coef =  tdtScale[level]*256;
 81
 82     var x_num =  Math.round((lon - topTileFromX) / coef);
 83     var y_num =  Math.round((topTileFromY - lat) / coef);
 84
 85    //  var dir =  "http://t7.tianditu.com/DataServer?T=vec_c&";
 86     // var server = "l="+String(level)+"&"+"x="+String(x_num)+"&"+"y="+String(y_num);
 87
 88
 89     //var  dir = "http://t0.tianditu.cn/vec_w/wmts?SERVICE=WMTS&REQUEST=GetTile&STYLE=default&VERSION=1.0.0&LAYER=vec&TILEMATRIXSET=c&";
 90     // var server = "TILEMATRIX="+String(level)+"&"+"TILEROW="+String(y_num)+"&"+"TILECOL="+String(x_num)+"&FORMAT=tiles";
 91
 92        var dir =  "http://t0.tianditu.com/DataServer?T=vec_w&";
 93       var server = "l="+String(level)+"&"+"x="+String(x_num)+"&"+"y="+String(y_num);
 94
 95
 96
 97      var imageDir = dir+server;
 98
 99
100      var imgDiv = document.getElementById("map");
101      imgDiv.style.backgroundImage =  "url("+imageDir+")";
102
103
104
105 }
106
107
108 function getPoints4()
109 {
110
111     var topTileFromX  = -20037508.3427892;
112     var topTileFromY  =  20037508.3427892;
113
114     var tdtScale={18:0.597164283559817,17:1.19432856685505,16:2.38865713397468,15:4.77731426794937,14:9.55462853563415,13:19.1092570712683,12:38.2185141425366,11:76.4370282850732,10:152.8740565704,9:305.7481128,8:611.49622628138,7:1222.99245256249,6:2445.98490512499,5:4891.96981024998,4:9783.93962049996,3:19567.8792409999,2:39135.7584820001,1:78271.5169639999};
115
116     var strList = document.getElementById("content").value;
117
118
119     var oStringList = strList.split(‘,‘);
120     var level  = oStringList[0];
121     var lon    =  oStringList[1];
122     var lat    =  oStringList[2];
123
124     lon = lon2Mercator(parseFloat(lon));
125     lat = lat2Mercator(parseFloat(lat));
126
127        var coef =  tdtScale[level]*256;
128
129     var x_num =  Math.round((lon - topTileFromX) / coef);
130     var y_num =  Math.round((topTileFromY - lat) / coef);
131
132
133        var dir =  "http://a.tile.openstreetmap.org/";
134       var server = String(level)+"/"+String(x_num)+"/"+String(y_num)+".png";
135
136
137      var imageDir = dir+server;
138
139
140      var imgDiv = document.getElementById("map");
141      imgDiv.style.backgroundImage =  "url("+imageDir+")";
142
143
144
145 }
146
147 function getPoints5()
148 {
149
150     var topTileFromX  = -20037508.3427892;
151     var topTileFromY  =  20037508.3427892;
152
153     var tdtScale={18:0.597164283559817,17:1.19432856685505,16:2.38865713397468,15:4.77731426794937,14:9.55462853563415,13:19.1092570712683,12:38.2185141425366,11:76.4370282850732,10:152.8740565704,9:305.7481128,8:611.49622628138,7:1222.99245256249,6:2445.98490512499,5:4891.96981024998,4:9783.93962049996,3:19567.8792409999,2:39135.7584820001,1:78271.5169639999};
154
155     var strList = document.getElementById("content").value;
156
157
158     var oStringList = strList.split(‘,‘);
159     var level  = oStringList[0];
160     var lon    =  oStringList[1];
161     var lat    =  oStringList[2];
162
163     lon = lon2Mercator(parseFloat(lon));
164     lat = lat2Mercator(parseFloat(lat));
165
166        var coef =  tdtScale[level]*256;
167
168     var x_num =  Math.round((lon - topTileFromX) / coef);
169     var y_num =  Math.round((topTileFromY - lat) / coef);
170
171
172
173        var dir =  "http://mt2.google.cn/vt/[email protected]&hl=zh-CN&gl=cn&";
174       var server = "x="+String(x_num)+"&"+"y="+String(y_num)+"&"+"z="+String(level)+"&s=Galil";
175
176
177
178      var imageDir = dir+server;
179
180
181      var imgDiv = document.getElementById("map");
182      imgDiv.style.backgroundImage =  "url("+imageDir+")";
183
184
185
186 }

测试HTML:

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 2 <html xmlns="http://www.w3.org/1999/xhtml">
 3
 4     <head>
 5     <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
 6     <title>获取瓦片</title>
 7     <style>
 8 v\:*   {  Behavior:   url(#default#VML)}
 9 </style>
10     <link href="default.css" rel="stylesheet" type="text/css" media="screen" />
11     </head>
12      <script language="javascript" src="Tool.js"></script>
13     <body>
14
15       <input id="content" type="text" autocomplete="on" maxlength="100" size="35">
16 <input type="button" value="获取天地图经纬度" onClick="getPoints2();"/> <input type="button" value="获取天地图墨卡托" onClick="getPoints3();"/> <input type="button" value="获取OpenstreetMap" onClick="getPoints4();"/>
17  <input type="button" value="获取谷歌地图" onClick="getPoints5();"/>
18          <div id="map"> </div>
19
20  <script type="text/javascript">
21
22
23      document.getElementById("content").value = "10,113.6,34.8";
24
25    </script>
26
27   </body>  
时间: 2024-10-13 11:30:29

根据经纬度坐标获取对应的切片算法的相关文章

Android根据已知的经纬度坐标获取当前位置

例如:经度:10.123456   纬度:20.654321 根据以上坐标获取到实际位置(不借用百度地图或高德地图的API) 代码如下: //放入经纬度就可以了 public String getAddress(double latitude, double longitude) {         Geocoder geocoder = new Geocoder(this, Locale.getDefault());         try {             List<Address

利用百度地图API,获取经纬度坐标

利用百度地图API,获取经纬度坐标 代码很简单,但在网上没找到现成的获取地图经纬度的页面. 就是想,给当前页面传递一个经纬度,自动定位到此经纬度.然后可以重新选择,选择完返回经纬度. 效果如下: 源代码下载:http://files.cnblogs.com/zjfree/select_map.rar 利用百度地图API,获取经纬度坐标,布布扣,bubuko.com

微信获取到的经纬度坐标不精准的问题

(转自:风行天下 http://www.cnblogs.com/php-linux/p/4730744.html) 微信如何根据经纬度坐标查询具体地理位置 好多人会问为什么微信高级接口获取的坐标信息位置不准,主要原因不是微信获取的不准,而是微信获取的是gps坐标,如果你直接用百度或google的api去解析的话肯定会出现误差的. 首先你需要吧gps位置转换成google或者百度的坐标,然后在通过转换后的坐标去获取准确的地理位置. 方法一:gps转换成google或者百度坐标,转换gps的接口 h

百度地图多边形画区域、获取节点经纬度坐标、判断某一点是否在此区域内

创建可绘画map: 1 <!DOCTYPE html> 2 3 <html> 4 <head> 5 <meta charset="UTF-8"> 6 <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no"> 7 <meta name=&

由经纬度坐标得到腾讯地图的瓦片/切片行列号

参考:https://blog.csdn.net/mygisforum/article/details/22997879 https://blog.csdn.net/u013929284/article/details/53614281 https://blog.csdn.net/shaxiaozilove/article/details/54908569 项目需要根据数据的瓦片行列号建立文件目录,而已知的位置信息是经纬度,下面是解决方法: 一.经纬度坐标 => 投影坐标:腾讯地图使用的是Web

发送经纬度坐标给指定手机

public class LocationService extends Service { @Override public void onCreate() { super.onCreate(); //获取手机的经纬度坐标 //1,获取位置管理者对象 LocationManager lm = (LocationManager) getSystemService(LOCATION_SERVICE); //2,以最优的方式获取经纬度坐标() Criteria criteria = new Crit

提取行政区边界经纬度坐标(高德+百度)

前言 近来由于工作需要,需要提取某些城市的经纬度坐标,稍微搜索了一下,发现百度地图和高德地图都提供了相关的函数和例子.那么剩余的工作也就比较简单了,保存坐标,然后转换为WGS坐标,这样才能和现有的GPS数据以及地图匹配. 主要问题和解决方法 本地保存文件跨浏览器支持 由于安全的原因,JavaScript本地保存文件的方式通常都只有IE支持的ActiveXObject/Open方法,每次都要提示不安全和允许运行,非常麻烦.好在其他浏览器目前都支持<a>标签实现文件下载的方法.经测试最新的Goog

百度地图坐标获取器

直接把百度地图坐标获取器放到dom里面有时会 引起js失效:用iframe标签就会涉及到父窗口的操作 代码如下 父窗口 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <meta http-equiv=&

经纬度坐标与地图容器像素坐标相互转换

<!doctype html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="initial-scale=1.0, user-scalable=no, wi