Skip to content

Commit

Permalink
basemap-gaode: new plugin
Browse files Browse the repository at this point in the history
Sample China map to illustrate IITC-CE#68.

Currently we can get road map with slightly different look.
It is not straightforward, as there are not much info in official API [docs](https://lbs.amap.com/api/javascript-api/example/).

I've played with some parameters, and you can see result after uncommenting corresponding lines.
Some of the variants allow language change.

P.S.
Different map themes could be seen here: https://lbs.amap.com/api/javascript-api/example/personalized-map/set-theme-style.
Unfortunately I've failed to figure out if it's possible to implement it in the plugin.
  • Loading branch information
johndoe committed Jan 28, 2019
1 parent 953519d commit 417d931
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: Map layers from AutoNavi / Gaode (高德地图)
// @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 417d931

Please sign in to comment.