0

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

<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>
4

2 回答 2

2

转换错误:您的 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
      );
于 2016-02-29T12:29:26.150 回答
0

使用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();
于 2016-03-07T14:51:20.703 回答