forked from IITC-CE/ingress-intel-total-conversion
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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@@ |