-
Notifications
You must be signed in to change notification settings - Fork 936
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
3449579
878480d
a56675f
1da1c68
5558ff4
5b23a99
79ac1ff
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,8 @@ | ||
//= require maplibre-gl | ||
//= require @maplibre/maplibre-gl-leaflet | ||
//= require @maptiler/maplibre-gl-omt-language | ||
//= require i18n | ||
|
||
L.extend(L.LatLngBounds.prototype, { | ||
getSize: function () { | ||
return (this._northEast.lat - this._southWest.lat) * | ||
|
@@ -9,6 +14,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); | ||
|
@@ -44,6 +83,32 @@ L.OSM.Map = L.Map.extend({ | |
this.baseLayers.push(layer); | ||
} | ||
|
||
if (L.OpenMapTiles) { | ||
var copyright_link = $("<a>", { | ||
href: "/copyright", | ||
text: I18n.t("javascripts.map.openstreetmap_contributors") | ||
}).prop("outerHTML"); | ||
|
||
var copyright = I18n.t("javascripts.map.copyright_text", { copyright_link: copyright_link }); | ||
|
||
var openmaptiles_link = I18n.t("javascripts.map.openmaptiles", { | ||
openmaptiles_url: "https://openmaptiles.org/", | ||
maptiler_url: "https://www.maptiler.com/" | ||
}); | ||
|
||
var terms = $("<a>", { | ||
href: "https://wiki.osmfoundation.org/wiki/Terms_of_Use", | ||
text: I18n.t("javascripts.map.website_and_api_terms") | ||
}).prop("outerHTML"); | ||
|
||
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.noteLayer = new L.FeatureGroup(); | ||
this.noteLayer.options = { code: "N" }; | ||
|
||
|
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.)