maptalks / maptalks.js

A light and plugable JavaScript library for integrated 2D/3D maps.
https://maptalks.org
BSD 3-Clause "New" or "Revised" License
4.31k stars 504 forks source link

建议Layers增加自定义替换模板url中的关键字 #1409

Closed just-ads closed 1 year ago

just-ads commented 3 years ago

maptalks's version and what browser you use?

Issue description

Please provide a reproduction URL (on any jsfiddle like site)

just-ads commented 3 years ago

比如 layers的options中

options: {
            'visible': false,
            'urlTemplate': 'https://t{s}.tianditu.gov.cn/cia_w/wmts?service=WMTS&version=1.0.0&request=GetTile&tilematrix={z}&layer=cia&style=default&tilerow={y}&tilecol={x}&tilematrixset=w&format=tiles&tk={token}',
            'subdomains': ['1', '2', '3', '4'],
            'customTags': {
                'token': getTianMapToken,
            },
        },
function getTianMapToken(){
    const tokens = ['11', '22',
        '33', '44', '55', '66'];
    const index = randomNum(0,5);
    return tokens[index];
}

或者直接

'customTags': {
                'token': ['11', '22','33', '44', '55', '66'],
            },

但是支持函数拓展要强一些