Skip to content
This repository has been archived by the owner on May 20, 2024. It is now read-only.

Commit

Permalink
Add tileserver public url to map options
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiří Hykel committed Jan 23, 2020
1 parent ac000f0 commit a8824e0
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 20 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ import LmcMaps from '@lmc-eu/lmc-maps';
style: 'lmc-default',
marker: true,
lang: 'cs',
authToken: 'YOUR_TOKEN'
authToken: 'YOUR_TOKEN',
publicUrl: 'https://tileserver.lmc.cz'
});
})();
```
Expand All @@ -63,6 +64,7 @@ import LmcMaps from '@lmc-eu/lmc-maps';
| style | Style id (default: lmc-default) ([see supported styles](https://maps.lmc.cz/#styles)) | string
| lang | Language of labels in map ([see supported languages](#supported-languages)) (default: native) | string
| authToken | Your Authorization token (required) | string
| publicUrl | Url to your tileserver (default: https://tileserver.lmc.cz) | string

#### Supported languages <a name="supported-languages"></a>

Expand Down
4 changes: 4 additions & 0 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ declare module '@lmc-eu/lmc-maps' {

authToken: string;

publicUrl: string;

init(): void;

getEvents(): void;
Expand Down Expand Up @@ -54,4 +56,6 @@ declare type MapsOptions = {

authToken: string;

publicUrl?: string;

};
8 changes: 4 additions & 4 deletions dist/lmc-maps.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau
var mapboxgl = _interopDefault(require('mapbox-gl'));

var STYLES = {
URL: "https://tileserver.lmc.cz" + "/styles/",
DEFAULT: 'lmc-default'
};

Expand Down Expand Up @@ -89,23 +88,24 @@ var LmcMaps = /** @class */ (function () {
this.container = options.container;
this.coords = options.coords || [14.4563172, 50.1028914];
this.zoom = options.zoom || 12;
this.style = (options.style || STYLES.DEFAULT);
this.style = options.style || STYLES.DEFAULT;
this.lang = options.lang;
this.hasMarker = options.hasMarker;
this.authToken = options.authToken;
this.publicUrl = options.publicUrl || "https://tileserver.lmc.cz";
this.init();
}
LmcMaps.prototype.init = function () {
var _this = this;
this.map = new mapboxgl.Map({
container: this.container,
style: "" + STYLES.URL + this.style + "/style.json",
style: this.publicUrl + "/styles/" + this.style + "/style.json",
center: this.coords,
zoom: this.zoom,
renderWorldCopies: false,
pitchWithRotate: false,
transformRequest: function (url, resourceType) {
if (_this.authToken && url.startsWith("https://tileserver.lmc.cz") && resourceType === 'Tile') {
if (_this.authToken && url.startsWith(_this.publicUrl) && resourceType === 'Tile') {
return {
url: url,
headers: {
Expand Down
8 changes: 4 additions & 4 deletions dist/lmc-maps.iife.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ var LmcMaps = (function (mapboxgl) {
mapboxgl = mapboxgl && mapboxgl.hasOwnProperty('default') ? mapboxgl['default'] : mapboxgl;

var STYLES = {
URL: "https://tileserver.lmc.cz" + "/styles/",
DEFAULT: 'lmc-default'
};

Expand Down Expand Up @@ -88,23 +87,24 @@ var LmcMaps = (function (mapboxgl) {
this.container = options.container;
this.coords = options.coords || [14.4563172, 50.1028914];
this.zoom = options.zoom || 12;
this.style = (options.style || STYLES.DEFAULT);
this.style = options.style || STYLES.DEFAULT;
this.lang = options.lang;
this.hasMarker = options.hasMarker;
this.authToken = options.authToken;
this.publicUrl = options.publicUrl || "https://tileserver.lmc.cz";
this.init();
}
LmcMaps.prototype.init = function () {
var _this = this;
this.map = new mapboxgl.Map({
container: this.container,
style: "" + STYLES.URL + this.style + "/style.json",
style: this.publicUrl + "/styles/" + this.style + "/style.json",
center: this.coords,
zoom: this.zoom,
renderWorldCopies: false,
pitchWithRotate: false,
transformRequest: function (url, resourceType) {
if (_this.authToken && url.startsWith("https://tileserver.lmc.cz") && resourceType === 'Tile') {
if (_this.authToken && url.startsWith(_this.publicUrl) && resourceType === 'Tile') {
return {
url: url,
headers: {
Expand Down
8 changes: 4 additions & 4 deletions dist/lmc-maps.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import mapboxgl from 'mapbox-gl';

var STYLES = {
URL: "https://tileserver.lmc.cz" + "/styles/",
DEFAULT: 'lmc-default'
};

Expand Down Expand Up @@ -85,23 +84,24 @@ var LmcMaps = /** @class */ (function () {
this.container = options.container;
this.coords = options.coords || [14.4563172, 50.1028914];
this.zoom = options.zoom || 12;
this.style = (options.style || STYLES.DEFAULT);
this.style = options.style || STYLES.DEFAULT;
this.lang = options.lang;
this.hasMarker = options.hasMarker;
this.authToken = options.authToken;
this.publicUrl = options.publicUrl || "https://tileserver.lmc.cz";
this.init();
}
LmcMaps.prototype.init = function () {
var _this = this;
this.map = new mapboxgl.Map({
container: this.container,
style: "" + STYLES.URL + this.style + "/style.json",
style: this.publicUrl + "/styles/" + this.style + "/style.json",
center: this.coords,
zoom: this.zoom,
renderWorldCopies: false,
pitchWithRotate: false,
transformRequest: function (url, resourceType) {
if (_this.authToken && url.startsWith("https://tileserver.lmc.cz") && resourceType === 'Tile') {
if (_this.authToken && url.startsWith(_this.publicUrl) && resourceType === 'Tile') {
return {
url: url,
headers: {
Expand Down
3 changes: 0 additions & 3 deletions src/lib/constants.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { Styles } from './types';

declare const TILESERVER_URL: string;

export const STYLES: Styles = {
URL: `${TILESERVER_URL}/styles/`,
DEFAULT: 'lmc-default'
};
4 changes: 4 additions & 0 deletions src/lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ declare module '@lmc-eu/lmc-maps' {

authToken: string;

publicUrl: string;

init(): void;

getEvents(): void;
Expand Down Expand Up @@ -54,4 +56,6 @@ declare type MapsOptions = {

authToken: string;

publicUrl?: string;

};
10 changes: 7 additions & 3 deletions src/lib/lmc-maps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,38 @@ class LmcMaps {

authToken: string;

publicUrl: string;

constructor(options: MapsOptions) {
this.container = options.container;

this.coords = options.coords || [14.4563172, 50.1028914];

this.zoom = options.zoom || 12;

this.style = (options.style || STYLES.DEFAULT);
this.style = options.style || STYLES.DEFAULT;

this.lang = options.lang;

this.hasMarker = options.hasMarker;

this.authToken = options.authToken;

this.publicUrl = options.publicUrl || TILESERVER_URL;

this.init();
}

init() {
this.map = new mapboxgl.Map({
container: this.container,
style: `${STYLES.URL}${this.style}/style.json`,
style: `${this.publicUrl}/styles/${this.style}/style.json`,
center: this.coords,
zoom: this.zoom,
renderWorldCopies: false,
pitchWithRotate: false,
transformRequest: (url, resourceType) => {
if (this.authToken && url.startsWith(TILESERVER_URL) && resourceType === 'Tile') {
if (this.authToken && url.startsWith(this.publicUrl) && resourceType === 'Tile') {
return {
url: url,
headers: {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ export type MapsOptions = {
lang?: Languages;
hasMarker?: boolean;
authToken: string;
publicUrl?: string;
};

export type Styles = {
URL: string;
DEFAULT: MapStyle;
};

Expand Down
2 changes: 2 additions & 0 deletions src/page/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import { Languages } from '../lib/types';
const hasMarker: boolean = urlParams.get('hasMarker') !== null;
const authToken: string = 'eyJhbGciOiJSUzI1NiIsImtpZCI6IkR4QzBhZEVub0VvemFUUnJHakZwTWFfUkdwWSIsInR5cCI6IkpXVCJ9.eyJzaWQiOiJ1c2VyIiwiYXpwIjoidXNlciIsImNydCI6IiIsImF1ZCI6InNpZ25vciIsImV4cCI6MTU3NjMyOTI3NywianRpIjoiMGU1NGY3NzYtYjQwMS00ZWI0LTkyMWItMmMxMWNkMDdmN2M5IiwiaWF0IjoxNTczNzM3Mjc3LCJpc3MiOiJzaWdub3IiLCJuYmYiOjE1NzM3MzcyNzcsInN1YiI6ImF1dGgtdG9rZW4ifQ.tiXx8UA9GoY2rqO9_OJT8If2QHbijrPpC-Bt-EEoXV7h7KfpP7mj6EVDVTENsfRmhcRFT6zakT9G-O9A7ntSKBx367C9BdCVY_WVB8VPU1lW3c3_N4LirlIjCY3zWP2v0tTXB01JpDrbAwyc6OhtNDAZADzodqoJs_2-CHSM01pjWQ08xFM8x6OgZOV5DQ7m7k4-b49bDftZJ15jomHenY-RNCEY-eX2np6jaS2gUphicixaF6rMpyV6hssyrsjt6TXy4-f4P2RgHz4AcdVrEf2uct8abS_1lfFHqIvuLU3YYkJQV0VAs7MUoetFQe1QIBP-m4HX8ffuLdELSZsqpA';

// const publicUrl = 'http://localhost:8080/fin';

new LmcMaps({
container: 'map',
coords,
Expand Down

0 comments on commit a8824e0

Please sign in to comment.