javascript - Leaflet custom urlcustom tiles - Stack Overflow

I am working on a custom map with leaflet. So far everything worked fine, but unfortunately the program

I am working on a custom map with leaflet. So far everything worked fine, but unfortunately the program I am using to split my image into tiles dont start the count with 0 but instead with 1, so my tiles start with "1_1.jpg" and so my whole map is shifted by one tile on y- and x-axis. To rename the tiles is not an option, cuz there to many, so I was looking for a possibility to change the {x} and {y} value in

L.tileLayer('images/map/{z}/C{x}_R{y}.jpg',

to something like x=x+1 and y=y+1, that would be my logic. I've read that it would be possible with getTileUrl but I didn't understand how. I am still quite new to Javascript and this problem starts to drive me mad!

If anyone can help I would be very thankful.

Tile names are like "Cx_Ry.jpg" (for example first image "C1_R1.jpg") And here is the code.

var w = 16384, h = 16384; //Größe innerhalb Box

var map = L.map('image-map', {
        minZoom: 0,
        maxZoom: 5,
        crs: L.CRS.Simple,
        attributionControl: false,
}).setView([0, 0], 0);

var southWest = map.unproject([0, h], map.getMaxZoom());
var northEast = map.unproject([w, 0], map.getMaxZoom());
var bounds = new L.LatLngBounds(southWest, northEast);

map.setMaxBounds(bounds);

L.tileLayer('images/map/{z}/C{x}_R{y}.jpg', {
    minZoom: 0,
    maxZoom: 5,
    tms: false,
    continuousWorld: 'false',
    noWrap: false,
    defaultRadius:1,
}).addTo(map);

I am working on a custom map with leaflet. So far everything worked fine, but unfortunately the program I am using to split my image into tiles dont start the count with 0 but instead with 1, so my tiles start with "1_1.jpg" and so my whole map is shifted by one tile on y- and x-axis. To rename the tiles is not an option, cuz there to many, so I was looking for a possibility to change the {x} and {y} value in

L.tileLayer('images/map/{z}/C{x}_R{y}.jpg',

to something like x=x+1 and y=y+1, that would be my logic. I've read that it would be possible with getTileUrl but I didn't understand how. I am still quite new to Javascript and this problem starts to drive me mad!

If anyone can help I would be very thankful.

Tile names are like "Cx_Ry.jpg" (for example first image "C1_R1.jpg") And here is the code.

var w = 16384, h = 16384; //Größe innerhalb Box

var map = L.map('image-map', {
        minZoom: 0,
        maxZoom: 5,
        crs: L.CRS.Simple,
        attributionControl: false,
}).setView([0, 0], 0);

var southWest = map.unproject([0, h], map.getMaxZoom());
var northEast = map.unproject([w, 0], map.getMaxZoom());
var bounds = new L.LatLngBounds(southWest, northEast);

map.setMaxBounds(bounds);

L.tileLayer('images/map/{z}/C{x}_R{y}.jpg', {
    minZoom: 0,
    maxZoom: 5,
    tms: false,
    continuousWorld: 'false',
    noWrap: false,
    defaultRadius:1,
}).addTo(map);
Share Improve this question edited May 7, 2017 at 2:56 Peter Hall 59.1k15 gold badges165 silver badges227 bronze badges asked May 6, 2017 at 23:26 John OutsiderJohn Outsider 331 silver badge3 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

You can extend Leaflet's TileLayer class to provide your own getTileUrl method: http://leafletjs./examples/extending/extending-2-layers.html.

In this case, it would probably look something like this:

L.TileLayer.MyCustomLayer = L.TileLayer.extend({
    getTileUrl: function(coords) {
        // increment our x/y coords by 1 so they match our tile naming scheme
        coords.x = coords.x + 1;
        coords.y = coords.y + 1;

        // pass the new coords on through the original getTileUrl
        // see http://leafletjs./examples/extending/extending-1-classes.html 
        // for calling parent methods
        return L.TileLayer.prototype.getTileUrl.call(this, coords);
    }
});

// static factory as remended by http://leafletjs./reference-1.0.3.html#class
L.tileLayer.myCustomLayer = function(templateUrl, options) {
    return new L.TileLayer.MyCustomLayer(templateUrl, options);
}

// create the layer and add it to the map
L.tileLayer.myCustomLayer('images/map/{z}/C{x}_R{y}.jpg', {
    minZoom: 0,
    maxZoom: 5,
    tms: false,
    continuousWorld: 'false',
    noWrap: false,
    defaultRadius:1,
}).addTo(map);

Code is untested, but should get you moving in the right direction.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745396164a4625887.html

相关推荐

  • javascript - Leaflet custom urlcustom tiles - Stack Overflow

    I am working on a custom map with leaflet. So far everything worked fine, but unfortunately the program

    12小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信