繁体   English   中英

OpenLayers LonLat转型

[英]OpenLayers LonLat transformation

我正在尝试将OSM OpenLayers示例与从query.wikidata.org获得的结果结合起来,但是似乎我在做错误的转换。 长和纬的正确变换是什么?

<html><body>
  <div id="mapdiv"></div>
  <script src="http://www.openlayers.org/api/OpenLayers.js"></script>
  <script>
    map = new OpenLayers.Map("mapdiv");
    map.addLayer(new OpenLayers.Layer.OSM());

    var lonLat = new OpenLayers.LonLat( 40.228055555556, 27.242222222222 )
          .transform(
            new OpenLayers.Projection("EPSG:900913"), // transform from WGS 1984
            map.getProjectionObject() // to Spherical Mercator Projection
          );

    var zoom=16;

    var markers = new OpenLayers.Layer.Markers( "Markers" );
    map.addLayer(markers);

    markers.addMarker(new OpenLayers.Marker(lonLat));

    map.setCenter (lonLat, zoom);
  </script>
</body></html>

转换是错误的:您的lonLat变量位于EPSG:4326中,因此您应该从EPSG:4326转换为EPSG:900913

var lonLat = new OpenLayers.LonLat( 27.242222222222, 40.228055555556 )
      .transform(
        new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
        map.getProjectionObject() // to Spherical Mercator Projection
      );

使用Leaflet时 ,无需进行任何转换。

var map = L.map('map').setView(40.228055555556, 27.242222222222],
  13);

L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
  attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);

L.marker([40.228055555556, 27.242222222222]).addTo(map)
  .bindPopup('A pretty CSS3 popup.<br> Easily customizable.')
  .openPopup();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM