Skip to content

Commit

Permalink
Merge pull request #79 from johnd0e/plugin-basemap-gaode
Browse files Browse the repository at this point in the history
basemap-gaode: new plugin
  • Loading branch information
modos189 authored Mar 13, 2019
2 parents 08a37ea + bb3755f commit c65895d
Showing 1 changed file with 92 additions and 0 deletions.
92 changes: 92 additions & 0 deletions plugins/basemap-gaode.user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// ==UserScript==
// @id iitc-plugin-basemap-gaode
// @name IITC plugin: Gaode (高德地图) / AutoNavi map
// @category Map Tiles
// @version 0.1.0.@@DATETIMEVERSION@@
// @description [@@BUILDNAME@@-@@BUILDDATE@@] Map layers from AutoNavi / Gaode (高德地图)
@@METAINFO@@
// ==/UserScript==

@@PLUGINSTART@@

// PLUGIN START ////////////////////////////////////////////////////////

function setup () {
// sample tile: https://webrd01.is.autonavi.com/appmaptile?style=8&x=13720&y=6693&z=14&lang=zh_cn

var baseUrl = [
'https://wprd0{s}.is.autonavi.com/appmaptile?style={style}&x={x}&y={y}&z={z}',
'https://webrd0{s}.is.autonavi.com/appmaptile?style={style}&x={x}&y={y}&z={z}&size=1&scale=1',
'https://webst0{s}.is.autonavi.com/appmaptile?style={style}&x={x}&y={y}&z={z}', // same as wprd0
];

var GaodeLayer = L.TileLayer.extend({
options: {
subdomains: '1234',
minZoom: 3,
maxZoom: 20,
maxNativeZoom: 18,
//detectRetina: true,
type: 'roads',
attribution: '© AutoNavi',
needFixChinaOffset: true // depends on fix-china-map-offset plugin
},
initialize: function (options) {
function expand (field) {
return options[field]
? '&' + field + '=' + options[field]
: '';
}
var extra = expand('lang');
extra += expand('scl');
var url = baseUrl[options.site || 0] + extra;
L.TileLayer.prototype.initialize.call(this, url, options);
}
});

var trafficUrl = 'https://tm.amap.com/trafficengine/mapabc/traffictile?v=1.0&;t=1&z={z}&y={y}&x={x}&t={time}';
var AmapTraffic = GaodeLayer.extend({
getTileUrl: function (coords) {
this.options.time = new Date().getTime();
return L.TileLayer.prototype.getTileUrl.call(this, coords);
},
initialize: function (options) {
L.TileLayer.prototype.initialize.call(this, trafficUrl, options);
},
minZoom: 6,
maxNativeZoom: 17
});

function add (name, layer) {
layerChooser.addBaseLayer(layer, name);
return layer;
}

var Roads = // en, zh_en
add('Gaode Roads [zh]', new GaodeLayer({ style: 7, maxNativeZoom: 20, lang: 'zh_cn' }));

//add('Gaode Roads', new GaodeLayer({ style: 7, maxNativeZoom: 20 }));
//add('Gaode Roads 7', new GaodeLayer({ style: 7, site: 1 }));
//add('Gaode Roads 8', new GaodeLayer({ style: 8, site: 1 }));
//add('Gaode Roads 8 [zh]',new GaodeLayer({ style: 8, site: 1, lang: 'zh_cn' }));

add('Gaode Roads + Traffic', L.layerGroup([
Roads,
new AmapTraffic({ opacity: 0.75 })
]));

var Satellite =
add('Gaode Satellite', new GaodeLayer({ style: 6, type: 'satellite' }));

add('Gaode Hybrid', L.layerGroup([
Satellite,
new GaodeLayer({ style: 8, type: 'roadnet', opacity: 0.75 })

//new GaodeLayer({ style: 8, type: 'roadnet', opacity: 0.75, lang: 'zh_cn', scl: 2 }), // (512*512 tile, w/o labels)
//new GaodeLayer({ style: 8, type: 'labels', opacity: 0.75, lang: 'zh_cn', ltype: 4 }) // (feature mask) here: 2: roads, 4: labels)
]));
}

// PLUGIN END //////////////////////////////////////////////////////////

@@PLUGINEND@@

0 comments on commit c65895d

Please sign in to comment.