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();