LoginSignup
1
0

More than 5 years have passed since last update.

leafletを鍛える。その7

Posted at

概要

leafletを鍛えてみた。
地図タイルを、自作してみた。

写真

サンプルコード

var map = L.map('map').setView([37.9, 140.1], 13);
var mvr = L.tileLayer("", {
    attribution: 'mvr',
    maxZoom: 18,
});
mvr.getTileUrl = function(coord) {
    var zoom = coord.z;
    var s = Math.pow(2, coord.z);
    var llp = L.point((coord.x * 256 + 128) / s, (coord.y * 256 + 128) / s);
    var ll = fromPointToLatLng(llp, s);
    var lng = ll.lng;    
    var lat = ll.lat;
    return "http://yumeblog.dip.jp/yb2g0.php?zoom=" + zoom + "&long=" + lng + "&lat=" + lat;
};
mvr.addTo(map);
function fromPointToLatLng(point, max_zoom) {
    var size = (1 << max_zoom) * 256,
        lat = (2 * Math.atan(Math.exp((point.y - size / 2) / -(size / (2 * Math.PI)))) - (Math.PI / 2)) * (180 / Math.PI),
        lng = (point.x - size / 2) * (360 / size);
    return L.latLng(lat, lng);
}

成果物

以上。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0