openlayers转坐标系

         <div class="article-copyright">
                                      <svg class="icon" title="CSDN认证原创" aria-hidden="true" style="width:53px; height: 18px; vertical-align: -4px;">
                            <use xlink:href="#CSDN_Cert"></use>
                    </svg>
                                      
                    版权声明:码字不易,转载请注明出处:                    https://blog.csdn.net/qq_24309981/article/details/81149602                </div>

<div class="htmledit_views" id="content_views">
                <hr><h3><a name="t0"></a><strong>背景</strong></h3>

<p>&nbsp; &nbsp; &nbsp; &nbsp; OpenLayers默认只支持EPSG:4326和EPSG:3857,那想让它支持CGCS2000坐标系该怎么办?这个时候就需要自定义坐标系了,借助proj4.js(proj4js是一个转换点坐标从一个坐标系到另一个坐标系的JavaScript库,包括数据转换)即可实现。</p>

<h2><a name="t1"></a><strong>准备工作,使OpenLayers支持坐标系(这里以EPSG:4512为例)</strong></h2>

<p>&nbsp; &nbsp; &nbsp; &nbsp; <strong>1:</strong>下载proj4.js文件&nbsp;&nbsp;<a href="https://www.bootcdn.cn/proj4js/" rel="nofollow" target="_blank">https://www.bootcdn.cn/proj4js/</a></p>

<p>&nbsp; &nbsp; &nbsp; &nbsp; <strong>2:</strong>查找坐标系定义&nbsp;&nbsp;<a href="http://epsg.io/" rel="nofollow" target="_blank">http://epsg.io/</a></p>

<p>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<img alt="" class="has" height="467" src="https://img-blog.csdn.net/20180721220943607?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzI0MzA5OTgx/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70" width="707"></p>

<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<img alt="" class="has" height="445" src="https://img-blog.csdn.net/20180721221106731?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzI0MzA5OTgx/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70" width="693"></p>

<p>&nbsp; &nbsp; &nbsp; &nbsp; <strong>3 :</strong>页面引入proj4.js&nbsp;</p>

<p>&nbsp;&lt;script type="text/javascript" src="./plugins/proj4/proj4-2.4.4.js"&gt;&lt;/script&gt;</p>

<p>&nbsp; &nbsp; &nbsp; &nbsp;<strong> 4 :</strong>定义EPSG:4512坐标系&nbsp;</p>

<p>&nbsp; &nbsp;proj4.defs("EPSG:4512","+proj=tmerc +lat_0=0 +lon_0=135 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs");</p>

<h2><a name="t2"></a><strong>坐标转换测试</strong></h2>

<p>&nbsp; &nbsp; &nbsp; &nbsp;默认坐标转换只能在EPSG:4326和EPSG:3857之间转换,如果没有自定义坐标系,下面语句是会报错的;自定义坐标系EPSG:4512之后,可以发现报错消失了,这也就说明,自定义坐标系成功了。</p>

<pre class="has" name="code" onclick="hljs.copyCode(event)"><code class="language-javascript hljs">geom4512 = geom3857.clone().transform(<span class="hljs-string">'EPSG:3857'</span>, <span class="hljs-string">'EPSG:4512'</span>);</code><div class="hljs-button {2}" data-title="复制"></div></pre>

<h2><a name="t3"></a><strong>参考文献</strong></h2>

<p><a href="https://blog.csdn.net/xk_zhang/article/details/53543606" rel="nofollow" target="_blank">https://blog.csdn.net/xk_zhang/article/details/53543606</a></p>            </div>

猜你喜欢

转载自blog.csdn.net/csdn_xuebing/article/details/89226534