-
Notifications
You must be signed in to change notification settings - Fork 923
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add OpenMapTiles vector map #4042
base: master
Are you sure you want to change the base?
Changes from all commits
d899ecc
90fb7ea
94ea06b
e41b232
f162cdb
8887671
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
//= require maplibre-gl | ||
//= require @maplibre/maplibre-gl-leaflet | ||
//= require @maptiler/maplibre-gl-omt-language | ||
//= require i18n | ||
//= require qs/dist/qs | ||
|
||
L.extend(L.LatLngBounds.prototype, { | ||
|
@@ -11,6 +15,40 @@ L.extend(L.LatLngBounds.prototype, { | |
} | ||
}); | ||
|
||
if (OSM.MAPTILER_KEY) { | ||
L.OpenMapTiles = L.MaplibreGL.extend({ | ||
options: { | ||
maxZoom: 23, | ||
style: "https://api.maptiler.com/maps/openstreetmap/style.json?key=" + OSM.MAPTILER_KEY | ||
}, | ||
onAdd: function (map) { | ||
var supportedLanguages = "am,ar,az,be,bg,br,bs,ca,co,cs,cy,da,de,el,en,eo,es,et,eu,fi,fr,fy,ga,gd,he,hi,hr,hu,hy,id,is,it,ja,ja_kana,ja_rm,ja-Latn,ja-Hira,ka,kk,kn,ko,ko-Latn,ku,la,lb,lt,lv,mk,mt,ml,nl,no,oc,pl,pt,rm,ro,ru,sk,sl,sq,sr,sr-Latn,sv,ta,te,th,tr,uk,zh".split(","); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This list doesn’t include the languages added to OpenMapTiles openmaptiles/openmaptiles#1477, including |
||
L.MaplibreGL.prototype.onAdd.call(this, map); | ||
var m = this.getMaplibreMap(); | ||
m.on("load", function () { | ||
var locale; | ||
if (supportedLanguages.includes(I18n.locale)) { | ||
locale = I18n.locale; | ||
} else { | ||
var mainLocale = I18n.locale.slice(0, 2); | ||
var localeIndex = supportedLanguages.findIndex(function (locale) { return locale.slice(0, 2) === mainLocale; }); | ||
if (localeIndex > -1) { | ||
locale = supportedLanguages[localeIndex]; | ||
} | ||
} | ||
|
||
if (locale) { | ||
m.setLanguage(locale); | ||
} | ||
}); | ||
L.MaplibreGL.prototype._update.call(this, map); | ||
}, | ||
onRemove: function (map) { | ||
L.MaplibreGL.prototype.onRemove.call(this, map); | ||
} | ||
}); | ||
} | ||
|
||
L.OSM.Map = L.Map.extend({ | ||
initialize: function (id, options) { | ||
L.Map.prototype.initialize.call(this, id, options); | ||
|
@@ -65,6 +103,11 @@ L.OSM.Map = L.Map.extend({ | |
}).prop("outerHTML"); | ||
var hotosm = I18n.t("javascripts.map.hotosm_credit", { hotosm_link: hotosm_link, osm_france_link: osm_france_link }); | ||
|
||
var openmaptiles_link = I18n.t("javascripts.map.openmaptiles", { | ||
openmaptiles_url: "https://openmaptiles.org/", | ||
maptiler_url: "https://www.maptiler.com/" | ||
}); | ||
|
||
this.baseLayers = []; | ||
|
||
this.baseLayers.push(new L.OSM.Mapnik({ | ||
|
@@ -74,6 +117,15 @@ L.OSM.Map = L.Map.extend({ | |
name: I18n.t("javascripts.map.base.standard") | ||
})); | ||
|
||
if (L.OpenMapTiles) { | ||
this.baseLayers.push(new L.OpenMapTiles({ | ||
attribution: copyright + ". " + openmaptiles_link + ". " + terms, | ||
code: "V", | ||
keyid: "openmaptiles_osm", | ||
name: I18n.t("javascripts.map.base.openmaptiles_osm") | ||
})); | ||
} | ||
|
||
this.baseLayers.push(new L.OSM.CyclOSM({ | ||
attribution: copyright + ". " + cyclosm + ". " + terms, | ||
code: "Y", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Arabic and Hebrew would be broken unless this code also installs the right-to-left text plugin. (Note that it only supports these two languages, not other languages in the same scripts or other right-to-left scripts.)