-
Notifications
You must be signed in to change notification settings - Fork 10
/
sitna.js
273 lines (232 loc) · 10.9 KB
/
sitna.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
/**
* @overview API SITNA: API JavaScript para la visualización de datos georreferenciados en aplicaciones web.
* @version 4.4.0
* @copyright 2019 Gobierno de Navarra
* @license BSD-2-Clause
* @author Fernando Lacunza <[email protected]>
*/
import TC from './TC';
import Util from './TC/Util';
import Consts from './TC/Consts';
import i18n from './TC/i18n';
import SitnaMap from './SITNA/Map';
import Feature from './SITNA/feature/Feature';
import Point from './SITNA/feature/Point';
import MultiPoint from './SITNA/feature/MultiPoint';
import Marker from './SITNA/feature/Marker';
import MultiMarker from './SITNA/feature/MultiMarker';
import Polyline from './SITNA/feature/Polyline';
import MultiPolyline from './SITNA/feature/MultiPolyline';
import Polygon from './SITNA/feature/Polygon';
import MultiPolygon from './SITNA/feature/MultiPolygon';
import Circle from './SITNA/feature/Circle';
import Layer from './SITNA/layer/Layer';
import Raster from './SITNA/layer/Raster';
import Vector from './SITNA/layer/Vector';
import './TC/tool/ExcelExport';
import './TC/tool/Proxification';
import Map from './TC/Map';
import Cfg from './TC/Cfg';
import wrap from './TC/wrap';
import { JL } from 'jsnlog';
// Importamos para precargar estilos y evitar FOUC
import Button from './SITNA/ui/Button';
import './SITNA/ui/Toggle';
import './SITNA/ui/Tab';
TC.isDebug = true;
const layer = {
Layer,
Raster,
Vector
};
const feature = {
Feature,
Point,
MultiPoint,
Marker,
MultiMarker,
Polyline,
MultiPolyline,
Polygon,
MultiPolygon,
Circle
};
const ui= {
Button: Button
}
const tool = TC.tool || {};
TC.feature = feature;
TC.layer = layer;
TC.tool = tool;
TC.Util = Util;
TC.Consts = Consts;
TC.i18n = i18n;
TC.Cfg = Cfg;
TC.Map = Map;
TC.wrap = wrap;
globalThis.TC = globalThis.TC || TC;
//window.JL = JL;
TC.version = '4.4.0';
TC.loadCSS(TC.apiLocation + 'css/sitna.css');
// Precargamos el CRS por defecto
TC.loadProjDef({ crs: 'EPSG:25830', name: 'ETRS89 / UTM zone 30N', def: '+proj=utm +zone=30 +ellps=GRS80 +units=m +no_defs' });
// Precargamos los CRS de IDENA que tienen orden de ejes neu
TC.loadProjDef({ crs: 'EPSG:4258', name: 'ETRS89', def: '+proj=longlat +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +no_defs +axis=neu' });
TC.loadProjDef({ crs: 'EPSG:3040', name: 'ETRS89 / UTM zone 28N (N-E)', def: '+proj=utm +zone=28 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs +axis=neu' });
TC.loadProjDef({ crs: 'EPSG:3041', name: 'ETRS89 / UTM zone 29N (N-E)', def: '+proj=utm +zone=29 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs +axis=neu' });
TC.loadProjDef({ crs: 'EPSG:3042', name: 'ETRS89 / UTM zone 30N (N-E)', def: '+proj=utm +zone=30 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs +axis=neu' });
TC.loadProjDef({ crs: 'EPSG:3043', name: 'ETRS89 / UTM zone 31N (N-E)', def: '+proj=utm +zone=31 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs +axis=neu' });
TC.loadProjDef({ crs: 'EPSG:4230', name: 'ED50', def: '+proj=longlat +ellps=intl +towgs84=-87,-98,-121,0,0,0,0 +no_defs +axis=neu' });
//resto de CRS nacionales
TC.loadProjDef({ crs: 'EPSG:25828', name: 'ETRS89 / UTM zone 28N', def: '+proj=utm +zone=28 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs' });
TC.loadProjDef({ crs: 'EPSG:25829', name: 'ETRS89 / UTM zone 29N', def: '+proj=utm +zone=29 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs' });
TC.loadProjDef({ crs: 'EPSG:25831', name: 'ETRS89 / UTM zone 31N', def: '+proj=utm +zone=31 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs' });
// Método que se usa en varios proyectos
// TODO: eliminar de todos los sitios
if (!Object.prototype.hasOwnProperty.call(Array.prototype, 'findByProperty')) {
Object.defineProperty(Array.prototype, "findByProperty", {
enumerable: false,
writable: true,
value: function (propertyName, value) {
for (var i = 0; i < this.length; i++) {
if (this[i][propertyName] == value)
return this[i];
}
}
});
}
document.addEventListener('DOMContentLoaded', function () {
// Completamos los datos de versión
var mapLibrary = 'Unknown library';
if (window.ol) {
mapLibrary = 'OpenLayers ' + ol.VERSION;
}
TC.version = TC.version + ' (' + mapLibrary + '; @ ' + TC.apiLocation + ')';
TC.browser = Util.getBrowser();
fetch(TC.apiLocation + 'config/browser-versions.json')
.then(r => {
if (r.ok) {
return r.json();
}
return Promise.resolve([]);
})
.then(browserVersions => {
TC._isSupported = true;
TC.Cfg.acceptedBrowserVersions = browserVersions;
const match = browserVersions.find(item => item.name.toLowerCase() === TC.browser.name.toLowerCase());
// GLS: 14/02/2019 Añadimos gestión para que no muestre tostada ni envíe correos en caso de que el navegador sea uno expirado
if (match && match.expired) {
TC.Cfg.loggingErrorsEnabled = false;
} else {
if (match && !Number.isNaN(match.version)) {
if (TC.browser.version < match.version) {
TC._isSupported = false;
}
}
if (TC.Cfg.oldBrowserAlert && !TC._isSupported) {
TC.Cfg.loggingErrorsEnabled = false;
// Timeout para evitar pedir el mapa antes de que se instancie
setTimeout(() => {
const mapObj = TC.Map.get(document.querySelector('.' + Consts.classes.MAP));
TC.i18n.loadResources(!TC.i18n[mapObj.options.locale], TC.apiLocation + 'TC/resources/', mapObj.options.locale).then(function () {
TC.error(Util.getLocaleString(mapObj.options.locale, 'outdatedBrowser'), Consts.msgErrorMode.TOAST);
});
}, 500);
}
}
});
if (/ip(ad|hone|od)/i.test(navigator.userAgent)) {
// En iOS, el primer click es un mouseover, por eso usamos touchstart como sustituto.
Consts.event.CLICK = "touchstart";
}
// Gestión de errores
if (TC.Cfg.loggingErrorsEnabled) {
JL.setOptions({
defaultAjaxUrl: Consts.url.ERROR_LOGGER.includes('//localhost') ? '' : Consts.url.ERROR_LOGGER
});
const onError = (function () {
var errorCount = 0;
var mapObj;
return function (e) {
mapObj = mapObj || TC.Map.get(document.querySelector('.' + Consts.classes.MAP));
if (!mapObj) {
return false;
}
var errorMsg, url = "", lineNumber = -1, column = -1, errorObj, apiError;
if (e.type === "unhandledrejection") {
errorMsg = e.reason ?
e.reason instanceof XMLDocument ? e.reason.firstElementChild.outerHTML : e.reason.message
: "";
if (e.reason && e.reason.stack) {
apiError = e.reason.stack.indexOf(TC.apiLocation) >= 0;
} else {
apiError = true;
}
errorObj = e.reason;
} else {
errorMsg = e.message;
url = e.filename;
lineNumber = e.lineno;
column = e.colno;
errorObj = e.error;
apiError = url.indexOf(TC.apiLocation) >= 0;
}
// Si notifyApplicationErrors === false solo capturamos los errores de la API
if ((TC.Cfg.notifyApplicationErrors || apiError) && errorCount < TC.Cfg.maxErrorCount && TC.Cfg.loggingErrorsEnabled) {
// Send object with all data to server side log, using severity fatal,
// from logger "onerrorLogger"
const previousMapState = mapObj.getPreviousMapState();
// 13/03/2020 añadimos el estado de los controles a la URL que se enviará por correo
const endProcess = function (appUrl) {
var msg = apiError ? Consts.text.API_ERROR : Consts.text.APP_ERROR;
JL("onerrorLogger").fatalException({
"msg": msg,
"errorMsg": errorMsg,
"url": url,
"lineNumber": lineNumber,
"column": column,
"appUrl": appUrl,
"apiVersion": TC.version,
"prevState": previousMapState,
"userAgent": navigator.userAgent
}, errorObj);
errorCount++;
};
let appUrl = location.href;
const controlStates = mapObj.exportControlStates() || [];
if (controlStates.length > 0) {
var currentUrl = location.href;
const hashPosition = currentUrl.indexOf('#');
if (hashPosition > 0) {
currentUrl = currentUrl.substring(0, hashPosition);
}
mapObj.getMapState({ extraStates: { ctl: controlStates } }).then(state => {
appUrl = currentUrl.concat("#", state);
endProcess(appUrl);
});
}
else {
endProcess(appUrl);
}
if (!TC.isDebug) {
var DEFAULT_CONTACT_EMAIL = "[email protected]";
TC.i18n.loadResources(!TC.i18n[mapObj.options.locale], TC.apiLocation + 'TC/resources/', mapObj.options.locale)
.then(function () {
TC.error(Util.getLocaleString(mapObj.options.locale, "genericError") + (mapObj.options.contactEmail || DEFAULT_CONTACT_EMAIL), { type: Consts.msgType.ERROR });
});
}
}
// Tell browser to run its own error handler as well
return false;
};
})();
window.addEventListener('error', onError, false);
window.addEventListener('unhandledrejection', onError, false);
}
});
/**
* Espacio de nombres donde se encuentran las clases de la API SITNA.
* @namespace SITNA
*/
Cfg.layout = TC.apiLocation + 'layout/responsive';
export { Cfg, SitnaMap as Map, Consts, feature, layer, tool, ui };