forked from mulfvik/origo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
origo.js
140 lines (132 loc) · 4.38 KB
/
origo.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
import { Feature as olFeature, Collection as olCollection, Overlay as olOverlay } from 'ol';
import * as olGeom from 'ol/geom';
import { fromCircle, fromExtent } from 'ol/geom/Polygon';
import * as olInteraction from 'ol/interaction';
import { createBox } from 'ol/interaction/Draw';
import * as olLayer from 'ol/layer';
import * as olSource from 'ol/source';
import * as olStyle from 'ol/style';
import * as olFormat from 'ol/format';
import polyfill from './src/utils/polyfill';
import * as ui from './src/ui';
import Viewer from './src/viewer';
import loadResources from './src/loadresources';
import titleCase from './src/utils/titlecase';
import * as origoControls from './src/controls';
import * as origoExtensions from './src/extensions';
import supports from './src/utils/supports';
import renderError from './src/utils/rendererror';
import Style from './src/style';
import featurelayer from './src/featurelayer';
import getFeatureInfo from './src/getfeatureinfo';
import getFeature from './src/getfeature';
import * as Utils from './src/utils';
import dropdown from './src/dropdown';
import { renderSvgIcon } from './src/utils/legendmaker';
import SelectedItem from './src/models/SelectedItem';
import 'core-js/stable';
import 'regenerator-runtime/runtime';
const Origo = function Origo(configPath, options = {}) {
let viewer;
const origoConfig = {
controls: [],
crossDomain: true,
target: '#app-wrapper',
svgSpritePath: 'css/svg/',
svgSprites: ['fa-icons.svg', 'material-icons.svg', 'miscellaneous.svg', 'origo-icons.svg', 'custom.svg'],
breakPoints: {
xs: [240, 320],
s: [320, 320],
m: [500, 500],
l: [768, 500]
},
breakPointsPrefix: 'o-media',
defaultControls: [
{ name: 'scaleline' },
{ name: 'zoom' },
{ name: 'rotate' },
{ name: 'attribution' },
{ name: 'fullscreen' }
]
};
const isSupported = supports();
const el = options.target || origoConfig.target;
if (!isSupported) {
renderError('browser', el);
return null;
}
polyfill();
const initControls = (controlDefs) => {
const controls = [];
controlDefs.forEach((def) => {
if ('name' in def) {
const controlName = titleCase(def.name);
const controlOptions = def.options || {};
if (controlName in origoControls) {
const control = origoControls[controlName](controlOptions);
control.options = Object.assign(control.options || {}, controlOptions);
controls.push(control);
}
}
});
return controls;
};
const initExtensions = (extensionDefs) => {
const extensions = [];
extensionDefs.forEach((def) => {
if ('name' in def) {
const extensionName = titleCase(def.name);
const extensionOptions = def.options || {};
if (extensionName in origoExtensions) {
const extension = origoExtensions[extensionName](extensionOptions);
extensions.push(extension);
}
}
});
return extensions;
};
const api = () => viewer;
const getConfig = () => origoConfig;
return ui.Component({
api,
getConfig,
onInit() {
const defaultConfig = Object.assign({}, origoConfig, options);
loadResources(configPath, defaultConfig)
.then((data) => {
const viewerOptions = data.options;
viewerOptions.controls = initControls(viewerOptions.controls);
viewerOptions.extensions = initExtensions(viewerOptions.extensions || []);
const target = viewerOptions.target;
viewer = Viewer(target, viewerOptions);
this.dispatch('load', viewer);
})
.catch(error => console.error(error));
}
});
};
olInteraction.Draw.createBox = createBox;
olGeom.Polygon.fromCircle = fromCircle;
olGeom.Polygon.fromExtent = fromExtent;
Origo.controls = origoControls;
Origo.extensions = origoExtensions;
Origo.ui = ui;
Origo.Style = Style;
Origo.featurelayer = featurelayer;
Origo.getFeatureInfo = getFeatureInfo;
Origo.getFeature = getFeature;
Origo.ol = [];
Origo.ol.geom = olGeom;
Origo.ol.interaction = olInteraction;
Origo.ol.layer = olLayer;
Origo.ol.source = olSource;
Origo.ol.style = olStyle;
Origo.ol.Feature = olFeature;
Origo.ol.Collection = olCollection;
Origo.ol.Overlay = olOverlay;
Origo.ol.format = olFormat;
Origo.Utils = Utils;
Origo.dropdown = dropdown;
Origo.renderSvgIcon = renderSvgIcon;
Origo.SelectedItem = SelectedItem;
export default Origo;