Merge repos with workflow
This commit is contained in:
1 parent
e229ad9fa5
commit
45fb7ddd77
2697 files changed
+45896
-4191
No files matched your search
@@ -0,0 +1,173 @@
|
||||
/**
|
||||
* Create a new [Mapbox GL JS plugin](https://www.mapbox.com/blog/build-mapbox-gl-js-plugins/) that
|
||||
* modifies the layers of the map style to use the `text-field` that matches the browser language.
|
||||
* As of Mapbox GL Language v1.0.0, this plugin no longer supports token values (e.g. `{name}`). v1.0+ expects the `text-field`
|
||||
* property of a style to use an [expression](https://docs.mapbox.com/mapbox-gl-js/style-spec/expressions/) of the form `['get', 'name_en']` or `['get', 'name']`; these expressions can be nested. Note that `get` expressions used as inputs to other expressions may not be handled by this plugin. For example:
|
||||
* ```
|
||||
* ["match",
|
||||
* ["get", "name"],
|
||||
* "California",
|
||||
* "Golden State",
|
||||
* ["coalesce",
|
||||
* ["get", "name_en"],
|
||||
* ["get", "name"]
|
||||
* ]
|
||||
* ]
|
||||
* ```
|
||||
* Only styles based on [Mapbox v8 styles](https://docs.mapbox.com/help/troubleshooting/streets-v8-migration-guide/) are supported.
|
||||
*
|
||||
* @constructor
|
||||
* @param {object} options - Options to configure the plugin.
|
||||
* @param {string[]} [options.supportedLanguages] - List of supported languages
|
||||
* @param {Function} [options.languageTransform] - Custom style transformation to apply
|
||||
* @param {RegExp} [options.languageField=/^name_/] - RegExp to match if a text-field is a language field
|
||||
* @param {Function} [options.getLanguageField] - Given a language choose the field in the vector tiles
|
||||
* @param {string} [options.languageSource] - Name of the source that contains the different languages.
|
||||
* @param {string} [options.defaultLanguage] - Name of the default language to initialize style after loading.
|
||||
* @param {string[]} [options.excludedLayerIds] - Name of the layers that should be excluded from translation.
|
||||
*/
|
||||
function MapboxLanguage(options) {
|
||||
options = Object.assign({}, options);
|
||||
if (!(this instanceof MapboxLanguage)) {
|
||||
throw new Error('MapboxLanguage needs to be called with the new keyword');
|
||||
}
|
||||
|
||||
this.setLanguage = this.setLanguage.bind(this);
|
||||
this._initialStyleUpdate = this._initialStyleUpdate.bind(this);
|
||||
|
||||
this._defaultLanguage = options.defaultLanguage;
|
||||
this._isLanguageField = options.languageField || /^name_/;
|
||||
this._getLanguageField = options.getLanguageField || function nameField(language) {
|
||||
return language === 'mul' ? 'name' : `name_${language}`;
|
||||
};
|
||||
this._languageSource = options.languageSource || null;
|
||||
this._languageTransform = options.languageTransform;
|
||||
this._excludedLayerIds = options.excludedLayerIds || [];
|
||||
this.supportedLanguages = options.supportedLanguages || ['ar', 'de', 'en', 'es', 'fr', 'it', 'ja', 'ko', 'mul', 'pt', 'ru', 'vi', 'zh-Hans', 'zh-Hant'];
|
||||
}
|
||||
|
||||
const isTokenField = /^\{name/;
|
||||
function isFlatExpressionField(isLangField, property) {
|
||||
const isGetExpression = Array.isArray(property) && property[0] === 'get';
|
||||
if (isGetExpression && isTokenField.test(property[1])) {
|
||||
console.warn('This plugin no longer supports the use of token syntax (e.g. {name}). Please use a get expression. See https://docs.mapbox.com/mapbox-gl-js/style-spec/expressions/ for more details.');
|
||||
}
|
||||
|
||||
return isGetExpression && isLangField.test(property[1]);
|
||||
}
|
||||
|
||||
function adaptNestedExpressionField(isLangField, property, languageFieldName) {
|
||||
if (Array.isArray(property)) {
|
||||
for (let i = 1; i < property.length; i++) {
|
||||
if (Array.isArray(property[i])) {
|
||||
if (isFlatExpressionField(isLangField, property[i])) {
|
||||
property[i][1] = languageFieldName;
|
||||
}
|
||||
adaptNestedExpressionField(isLangField, property[i], languageFieldName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function adaptPropertyLanguage(isLangField, property, languageFieldName) {
|
||||
if (isFlatExpressionField(isLangField, property)) {
|
||||
property[1] = languageFieldName;
|
||||
}
|
||||
|
||||
adaptNestedExpressionField(isLangField, property, languageFieldName);
|
||||
|
||||
// handle special case of bare ['get', 'name'] expression by wrapping it in a coalesce statement
|
||||
if (property[0] === 'get' && property[1] === 'name') {
|
||||
const defaultProp = property.slice();
|
||||
const adaptedProp = ['get', languageFieldName];
|
||||
property = ['coalesce', adaptedProp, defaultProp];
|
||||
}
|
||||
|
||||
return property;
|
||||
}
|
||||
|
||||
function changeLayerTextProperty(isLangField, layer, languageFieldName, excludedLayerIds) {
|
||||
if (layer.layout && layer.layout['text-field'] && excludedLayerIds.indexOf(layer.id) === -1) {
|
||||
return Object.assign({}, layer, {
|
||||
layout: Object.assign({}, layer.layout, {
|
||||
'text-field': adaptPropertyLanguage(isLangField, layer.layout['text-field'], languageFieldName)
|
||||
})
|
||||
});
|
||||
}
|
||||
return layer;
|
||||
}
|
||||
|
||||
function findStreetsSource(style) {
|
||||
const sources = Object.keys(style.sources).filter((sourceName) => {
|
||||
const url = style.sources[sourceName].url;
|
||||
// the source URL can reference the source version or the style version
|
||||
// this check and the error forces users to migrate to styles using source version 8
|
||||
return url && url.indexOf('mapbox.mapbox-streets-v8') > -1 || /mapbox-streets-v[1-9][1-9]/.test(url);
|
||||
});
|
||||
if (!sources.length) throw new Error('If using MapboxLanguage with a Mapbox style, the style must be based on vector tile version 8, e.g. "streets-v11"');
|
||||
return sources[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Explicitly change the language for a style.
|
||||
* @param {object} style - Mapbox GL style to modify
|
||||
* @param {string} language - The language iso code
|
||||
* @returns {object} the modified style
|
||||
*/
|
||||
MapboxLanguage.prototype.setLanguage = function (style, language) {
|
||||
if (this.supportedLanguages.indexOf(language) < 0) throw new Error(`Language ${ language } is not supported`);
|
||||
const streetsSource = this._languageSource || findStreetsSource(style);
|
||||
if (!streetsSource) return style;
|
||||
|
||||
const field = this._getLanguageField(language);
|
||||
const isLangField = this._isLanguageField;
|
||||
const excludedLayerIds = this._excludedLayerIds;
|
||||
const changedLayers = style.layers.map((layer) => {
|
||||
if (layer.source === streetsSource) return changeLayerTextProperty(isLangField, layer, field, excludedLayerIds);
|
||||
return layer;
|
||||
});
|
||||
|
||||
const languageStyle = Object.assign({}, style, {
|
||||
layers: changedLayers
|
||||
});
|
||||
|
||||
return this._languageTransform ? this._languageTransform(languageStyle, language) : languageStyle;
|
||||
};
|
||||
|
||||
MapboxLanguage.prototype._initialStyleUpdate = function () {
|
||||
const style = this._map.getStyle();
|
||||
const language = this._defaultLanguage || browserLanguage(this.supportedLanguages);
|
||||
|
||||
this._map.setStyle(this.setLanguage(style, language));
|
||||
};
|
||||
|
||||
function browserLanguage(supportedLanguages) {
|
||||
const language = navigator.languages ? navigator.languages[0] : (navigator.language || navigator.userLanguage);
|
||||
const parts = language && language.split('-');
|
||||
let languageCode = language;
|
||||
if (parts.length > 1) {
|
||||
languageCode = parts[0];
|
||||
}
|
||||
if (supportedLanguages.indexOf(languageCode) > -1) {
|
||||
return languageCode;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
MapboxLanguage.prototype.onAdd = function (map) {
|
||||
this._map = map;
|
||||
this._map.on('style.load', this._initialStyleUpdate);
|
||||
this._container = document.createElement('div');
|
||||
return this._container;
|
||||
};
|
||||
|
||||
MapboxLanguage.prototype.onRemove = function () {
|
||||
this._map.off('style.load', this._initialStyleUpdate);
|
||||
this._map = undefined;
|
||||
};
|
||||
|
||||
if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
|
||||
module.exports = MapboxLanguage;
|
||||
} else {
|
||||
window.MapboxLanguage = MapboxLanguage;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
/**
|
||||
* Skipped minification because the original files appears to be already minified.
|
||||
* Original file: /npm/mapbox-gl@2.9.1/dist/mapbox-gl.css
|
||||
*
|
||||
* Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
|
||||
*/
|
||||
.mapboxgl-map{font:12px/20px Helvetica Neue,Arial,Helvetica,sans-serif;overflow:hidden;position:relative;-webkit-tap-highlight-color:rgb(0 0 0/0)}.mapboxgl-canvas{position:absolute;left:0;top:0}.mapboxgl-map:-webkit-full-screen{width:100%;height:100%}.mapboxgl-canary{background-color:salmon}.mapboxgl-canvas-container.mapboxgl-interactive,.mapboxgl-ctrl-group button.mapboxgl-ctrl-compass{cursor:grab;-webkit-user-select:none;user-select:none}.mapboxgl-canvas-container.mapboxgl-interactive.mapboxgl-track-pointer{cursor:pointer}.mapboxgl-canvas-container.mapboxgl-interactive:active,.mapboxgl-ctrl-group button.mapboxgl-ctrl-compass:active{cursor:grabbing}.mapboxgl-canvas-container.mapboxgl-touch-zoom-rotate,.mapboxgl-canvas-container.mapboxgl-touch-zoom-rotate .mapboxgl-canvas{touch-action:pan-x pan-y}.mapboxgl-canvas-container.mapboxgl-touch-drag-pan,.mapboxgl-canvas-container.mapboxgl-touch-drag-pan .mapboxgl-canvas{touch-action:pinch-zoom}.mapboxgl-canvas-container.mapboxgl-touch-zoom-rotate.mapboxgl-touch-drag-pan,.mapboxgl-canvas-container.mapboxgl-touch-zoom-rotate.mapboxgl-touch-drag-pan .mapboxgl-canvas{touch-action:none}.mapboxgl-ctrl-bottom-left,.mapboxgl-ctrl-bottom-right,.mapboxgl-ctrl-top-left,.mapboxgl-ctrl-top-right{position:absolute;pointer-events:none;z-index:2}.mapboxgl-ctrl-top-left{top:0;left:0}.mapboxgl-ctrl-top-right{top:0;right:0}.mapboxgl-ctrl-bottom-left{bottom:0;left:0}.mapboxgl-ctrl-bottom-right{right:0;bottom:0}.mapboxgl-ctrl{clear:both;pointer-events:auto;transform:translate(0)}.mapboxgl-ctrl-top-left .mapboxgl-ctrl{margin:10px 0 0 10px;float:left}.mapboxgl-ctrl-top-right .mapboxgl-ctrl{margin:10px 10px 0 0;float:right}.mapboxgl-ctrl-bottom-left .mapboxgl-ctrl{margin:0 0 10px 10px;float:left}.mapboxgl-ctrl-bottom-right .mapboxgl-ctrl{margin:0 10px 10px 0;float:right}.mapboxgl-ctrl-group{border-radius:4px;background:#fff}.mapboxgl-ctrl-group:not(:empty){box-shadow:0 0 0 2px rgb(0 0 0/10%)}@media (-ms-high-contrast:active){.mapboxgl-ctrl-group:not(:empty){box-shadow:0 0 0 2px ButtonText}}.mapboxgl-ctrl-group button{width:29px;height:29px;display:block;padding:0;outline:none;border:0;box-sizing:border-box;background-color:transparent;cursor:pointer;overflow:hidden}.mapboxgl-ctrl-group button+button{border-top:1px solid #ddd}.mapboxgl-ctrl button .mapboxgl-ctrl-icon{display:block;width:100%;height:100%;background-repeat:no-repeat;background-position:50%}@media (-ms-high-contrast:active){.mapboxgl-ctrl-icon{background-color:transparent}.mapboxgl-ctrl-group button+button{border-top:1px solid ButtonText}}.mapboxgl-ctrl-attrib-button:focus,.mapboxgl-ctrl-group button:focus{box-shadow:0 0 2px 2px rgb(0 150 255/100%)}.mapboxgl-ctrl button:disabled{cursor:not-allowed}.mapboxgl-ctrl button:disabled .mapboxgl-ctrl-icon{opacity:.25}.mapboxgl-ctrl-group button:first-child{border-radius:4px 4px 0 0}.mapboxgl-ctrl-group button:last-child{border-radius:0 0 4px 4px}.mapboxgl-ctrl-group button:only-child{border-radius:inherit}.mapboxgl-ctrl button:not(:disabled):hover{background-color:rgb(0 0 0/5%)}.mapboxgl-ctrl-group button:focus:focus-visible{box-shadow:0 0 2px 2px rgb(0 150 255/100%)}.mapboxgl-ctrl-group button:focus:not(:focus-visible){box-shadow:none}.mapboxgl-ctrl button.mapboxgl-ctrl-zoom-out .mapboxgl-ctrl-icon{background-image:url("data:image/svg+xml;charset=utf-8,%3Csvg width='29' height='29' viewBox='0 0 29 29' xmlns='http://www.w3.org/2000/svg' fill='%23333'%3E %3Cpath d='M10 13c-.75 0-1.5.75-1.5 1.5S9.25 16 10 16h9c.75 0 1.5-.75 1.5-1.5S19.75 13 19 13h-9z'/%3E %3C/svg%3E")}.mapboxgl-ctrl button.mapboxgl-ctrl-zoom-in .mapboxgl-ctrl-icon{background-image:url("data:image/svg+xml;charset=utf-8,%3Csvg width='29' height='29' viewBox='0 0 29 29' xmlns='http://www.w3.org/2000/svg' fill='%23333'%3E %3Cpath d='M14.5 8.5c-.75 0-1.5.75-1.5 1.5v3h-3c-.75 0-1.5.75-1.5 1.5S9.25 16 10 16h3v3c0 .75.75 1.5 1.5 1.5S16 19.75 16 19v-3h3c.75 0 1.5-.75 1.5-1.5S19.75 13 19 13h-3v-3c0-.75-.75-1.5-1.5-1.5z'/%3E %3C/svg%3E")}@media (-ms-high-contrast:active){.mapboxgl-ctrl button.mapboxgl-ctrl-zoom-out .mapboxgl-ctrl-icon{background-image:url("data:image/svg+xml;charset=utf-8,%3Csvg width='29' height='29' viewBox='0 0 29 29' xmlns='http://www.w3.org/2000/svg' fill='%23fff'%3E %3Cpath d='M10 13c-.75 0-1.5.75-1.5 1.5S9.25 16 10 16h9c.75 0 1.5-.75 1.5-1.5S19.75 13 19 13h-9z'/%3E %3C/svg%3E")}.mapboxgl-ctrl button.mapboxgl-ctrl-zoom-in .mapboxgl-ctrl-icon{background-image:url("data:image/svg+xml;charset=utf-8,%3Csvg width='29' height='29' viewBox='0 0 29 29' xmlns='http://www.w3.org/2000/svg' fill='%23fff'%3E %3Cpath d='M14.5 8.5c-.75 0-1.5.75-1.5 1.5v3h-3c-.75 0-1.5.75-1.5 1.5S9.25 16 10 16h3v3c0 .75.75 1.5 1.5 1.5S16 19.75 16 19v-3h3c.75 0 1.5-.75 1.5-1.5S19.75 13 19 13h-3v-3c0-.75-.75-1.5-1.5-1.5z'/%3E %3C/svg%3E")}}@media (-ms-high-contrast:black-on-white){.mapboxgl-ctrl button.mapboxgl-ctrl-zoom-out .mapboxgl-ctrl-icon{background-image:url("data:image/svg+xml;charset=utf-8,%3Csvg width='29' height='29' viewBox='0Line truncated
|
||||
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Minified by jsDelivr using Terser v5.13.1.
|
||||
* Original file: /npm/mapbox-gl@2.9.1/dist/mapbox-gl.js
|
||||
*
|
||||
* Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
|
||||
*/
|
||||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).mapboxgl=t()}(this,(function(){"use strict";var e,t,i;function r(r,n){if(e)if(t){var o="self.onerror = function() { console.error('An error occurred while parsing the WebWorker bundle. This is most likely due to improper transpilation by Babel; please see https://docs.mapbox.com/mapbox-gl-js/guides/install/#transpiling'); }; var sharedChunk = {}; ("+e+")(sharedChunk); ("+t+")(sharedChunk); self.onerror = null;",s={};e(s),i=n(s),"undefined"!=typeof window&&window&&window.URL&&window.URL.createObjectURL&&(i.workerUrl=window.URL.createObjectURL(new Blob([o],{type:"text/javascript"})))}else t=n;else e=n}return r(0,(function(e){var t="undefined"!=typeof self?self:{},i=r;function r(e,t,i,r){this.cx=3*e,this.bx=3*(i-e)-this.cx,this.ax=1-this.cx-this.bx,this.cy=3*t,this.by=3*(r-t)-this.cy,this.ay=1-this.cy-this.by,this.p1x=e,this.p1y=r,this.p2x=i,this.p2y=r}r.prototype.sampleCurveX=function(e){return((this.ax*e+this.bx)*e+this.cx)*e},r.prototype.sampleCurveY=function(e){return((this.ay*e+this.by)*e+this.cy)*e},r.prototype.sampleCurveDerivativeX=function(e){return(3*this.ax*e+2*this.bx)*e+this.cx},r.prototype.solveCurveX=function(e,t){var i,r,n,o,s;for(void 0===t&&(t=1e-6),n=e,s=0;s<8;s++){if(o=this.sampleCurveX(n)-e,Math.abs(o)<t)return n;var a=this.sampleCurveDerivativeX(n);if(Math.abs(a)<1e-6)break;n-=o/a}if((n=e)<(i=0))return i;if(n>(r=1))return r;for(;i<r;){if(o=this.sampleCurveX(n),Math.abs(o-e)<t)return n;e>o?i=n:r=n,n=.5*(r-i)+i}return n},r.prototype.solve=function(e,t){return this.sampleCurveY(this.solveCurveX(e,t))};var n=o;function o(e,t){this.x=e,this.y=t}o.prototype={clone:function(){return new o(this.x,this.y)},add:function(e){return this.clone()._add(e)},sub:function(e){return this.clone()._sub(e)},multByPoint:function(e){return this.clone()._multByPoint(e)},divByPoint:function(e){return this.clone()._divByPoint(e)},mult:function(e){return this.clone()._mult(e)},div:function(e){return this.clone()._div(e)},rotate:function(e){return this.clone()._rotate(e)},rotateAround:function(e,t){return this.clone()._rotateAround(e,t)},matMult:function(e){return this.clone()._matMult(e)},unit:function(){return this.clone()._unit()},perp:function(){return this.clone()._perp()},round:function(){return this.clone()._round()},mag:function(){return Math.sqrt(this.x*this.x+this.y*this.y)},equals:function(e){return this.x===e.x&&this.y===e.y},dist:function(e){return Math.sqrt(this.distSqr(e))},distSqr:function(e){var t=e.x-this.x,i=e.y-this.y;return t*t+i*i},angle:function(){return Math.atan2(this.y,this.x)},angleTo:function(e){return Math.atan2(this.y-e.y,this.x-e.x)},angleWith:function(e){return this.angleWithSep(e.x,e.y)},angleWithSep:function(e,t){return Math.atan2(this.x*t-this.y*e,this.x*e+this.y*t)},_matMult:function(e){var t=e[2]*this.x+e[3]*this.y;return this.x=e[0]*this.x+e[1]*this.y,this.y=t,this},_add:function(e){return this.x+=e.x,this.y+=e.y,this},_sub:function(e){return this.x-=e.x,this.y-=e.y,this},_mult:function(e){return this.x*=e,this.y*=e,this},_div:function(e){return this.x/=e,this.y/=e,this},_multByPoint:function(e){return this.x*=e.x,this.y*=e.y,this},_divByPoint:function(e){return this.x/=e.x,this.y/=e.y,this},_unit:function(){return this._div(this.mag()),this},_perp:function(){var e=this.y;return this.y=this.x,this.x=-e,this},_rotate:function(e){var t=Math.cos(e),i=Math.sin(e),r=i*this.x+t*this.y;return this.x=t*this.x-i*this.y,this.y=r,this},_rotateAround:function(e,t){var i=Math.cos(e),r=Math.sin(e),n=t.y+r*(this.x-t.x)+i*(this.y-t.y);return this.x=t.x+i*(this.x-t.x)-r*(this.y-t.y),this.y=n,this},_round:function(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}},o.convert=function(e){return e instanceof o?e:Array.isArray(e)?new o(e[0],e[1]):e};const s=Math.PI/180,a=180/Math.PI;function l(e){return e*s}function c(e){return e*a}const u=[[0,0],[1,0],[1,1],[0,1]];function h(e){if(e<=0)return 0;if(e>=1)return 1;const t=e*e,i=t*e;return 4*(e<.5?i:3*(e-t)+i-.75)}function p(e,t,r,n){const o=new i(e,t,r,n);return function(e){return o.solve(e)}}const d=p(.25,.1,.25,1);function f(e,t,i){return Math.min(i,Math.max(t,e))}function m(e,t,i){return(i=f((i-e)/(t-e),0,1))*i*(3-2*i)}function _(e,t,i){const r=i-t,n=((e-t)%r+r)%r+t;return n===t?i:n}function g(e,t,i){if(!e.length)return i(null,[]);let r=e.length;const n=new Array(e.length);let o=null;e.forEach(((e,s)=>{t(e,((e,t)=>{e&&(o=e),n[s]=t,0==--r&&i(o,n)}))}))}function y(e){const t=[];for(const i in e)t.push(e[i]);return t}function x(e,...t){for(const i of t)for(const t in i)e[t]=i[t];return e}let v=1;function b(){return v++}function w(){return function e(t){return t?(t^Math.random()*(16>>t/4)).toString(16):([1e7]+-[1e3]+-4e3+-8e3+-1e11).replace(/[018]/g,e)}()}function T(e){return e<=1?1:Math.pow(2,Math.ceil(Math.log(e)/Math.LN2))}function E(e){return!!e&Line truncated
|
||||
//# sourceMappingURL=/sm/dedec2205749fc77be93541a9a595f9d093cd4721efa47f1dd5fc6ecaa67a5e6.map
|
||||
Reference in new issue
Block a user