-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcodegen.html
More file actions
170 lines (159 loc) · 6.73 KB
/
codegen.html
File metadata and controls
170 lines (159 loc) · 6.73 KB
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
<script type="text/javascript" src=/proxy/https/github.com/MapBBCode/mapbbcode.github.io/blob/master/_includes/"/lib/proprietary/Bing.js"></script>%3C/div>
<script type="text/javascript" src=/proxy/https/github.com/MapBBCode/mapbbcode.github.io/blob/master/_includes/"/lib/proprietary/Google.js"></script>%3C/div>
<script type="text/javascript" src=/proxy/https/github.com/MapBBCode/mapbbcode.github.io/blob/master/_includes/"/lib/proprietary/Yandex.js"></script>%3C/div>
<script type="text/javascript" src=/proxy/https/github.com/MapBBCode/mapbbcode.github.io/blob/master/_includes/"/lib/proprietary/2GIS.js"></script>%3C/div>
<script type="text/javascript" src=/proxy/https/github.com/MapBBCode/mapbbcode.github.io/blob/master/_includes/"/lib/proprietary/Nokia.js"></script>%3C/div>
<script type="text/javascript" src=/proxy/https/github.com/MapBBCode/mapbbcode.github.io/blob/master/_includes/"/lib/proprietary/Esri.js"></script>%3C/div>
<script type="text/javascript">
var mapbb, config, form = document.forms['f'];
L.DomEvent.on(window, 'load', function() {
mapbb = new MapBBCode().options;
config = new MapBBCodeConfig({ layers: ['OpenStreetMap'] });
config.bindLayerAdder({
select: 'layers',
button: 'layeradd',
keyBlock: 'bingkey',
keyTitle: 'bingtitle',
keyValue: 'keyvalue',
keyBlockDisplay: 'inline'
});
config.on('show change', update);
config.show('map');
// todo: add update() listener to all input fields
var fields = document.getElementsByTagName('input');
for( var i = 0; i < fields.length; i++ ) {
L.DomEvent.on(fields[i], fields[i].type == 'text' ? 'change' : 'click', update);
}
L.DomEvent.on(form.elements['lang'], 'change', update);
});
function value(name) {
var el = form.elements[name];
if( el.length && el.length > 1 ) {
// radio buttons
for( var i = 0; i < el.length; i++ )
if( el[i].checked || el[i].selected )
return el[i].value;
}
return el.type == 'checkbox' ? el.checked : el.value; // todo: value
}
function quotes(str) {
return '"' + str.replace(/\\/g, '\\\\').replace(/"/g, '\\"') + '"';
}
function mapbbConfig() {
var res = {}, o = config.options, i,
std = 'defaultZoom,fullFromStart,fullViewHeight,viewWidth,viewHeight,editorHeight,windowWidth,windowHeight'.split(',');
if( !(o.layers.length == 1 && o.layers[0] == 'OpenStreetMap') )
res.layers = quotes(o.layers.join(','));
if( o.defaultPosition[0] != mapbb.defaultPosition[0] || o.defaultPosition[1] != mapbb.defaultPosition[1] )
res.defaultPosition = '[' + o.defaultPosition.join(', ') + ']';
for( i = 0; i < std.length; i++ ) {
var opt = std[i];
if( o[opt] != mapbb[opt] )
res[opt] = o[opt];
}
if( value('switcher') != mapbb.preferStandardLayerSwitcher )
res.preferStandardLayerSwitcher = value('switcher') ? 'true' : 'false';
if( value('outer') != mapbb.outerLinkTemplate )
res.outerLinkTemplate = quotes(value('outer'));
if( value('tags') != mapbb.allowedHTML )
res.allowedHTML = quotes(value('tags'));
if( value('upload') != mapbb.uploadButton )
res.uploadButton = value('upload') ? 'true' : 'false';
var shareurl = value('shareurl');
if( shareurl.length && shareurl.substring(shareurl.length - 1) != '/' )
shareurl += '/';
if( value('upload') && shareurl != mapbb.externalEndpoint )
res.externalEndpoint = quotes(shareurl);
return res;
}
function printOptions(res, indent) {
var indentStr = '', str = [];
if( indent )
while( indent-- > 0 )
indentStr += '\t';
for( var i in res )
if( res.hasOwnProperty(i) )
str.push(indentStr + '\t' + i + ': ' + (typeof res[i] === 'object' ? printOptions(res[i], (indent||0) + 1) : res[i]));
return str.length ? '{\n' + str.join(',\n') + '\n' + indentStr + '}' : '{}';
}
function findProprietary(layers) {
var res = {}, i, l;
for( i = 0; i < layers.length; i++ ) {
l = layers[i];
if( l == 'Bing' )
res.Bing = true;
else if( l.indexOf('Google') >= 0 )
res.Google = true;
else if( l.indexOf('Yandex') >= 0 )
res.Yandex = true;
else if( l.indexOf('2GIS') >= 0 )
res['2GIS'] = true;
else if( l.indexOf('Nokia') >= 0 )
res.Nokia = true;
else if( l.indexOf('Esri') >= 0 || l.indexOf('National G') >= 0 )
res.Esri = true;
}
var ar = [];
for( i in res )
ar.push(i);
return ar;
}
function update() {
form.elements['path'].disabled = document.getElementById('pathcdn1').checked;
form.elements['wpath'].disabled = value('wpathm');
form.elements['shareurl'].disabled = !value('upload');
var pathFixed = value('cdn') == '1' ? '//cdn.jsdelivr.net/mapbbcode/1.2.0/' : value('path');
if( pathFixed.length > 0 && pathFixed.substring(pathFixed.length - 1) !== '/' )
pathFixed += '/';
var bbcode = document.getElementById('example').checked ? '[map=14]57.7753,26.0316(Eesti); 57.7751,26.0204(Latvija);\n57.769,26.024 57.7719,26.0206 57.7742,26.0263 57.7815,26.0271[/map]' : false;
var str = '', i, mapbbcfg = mapbbConfig(), proprietary = findProprietary(config.options.layers);
mapbbcfg.windowPath = quotes(value('wpathm') == '1' ? pathFixed : value('wpath'));
if( value('loader') == '0' ) {
str += '<link rel="stylesheet" type="text/css" href=/proxy/https/github.com/MapBBCode/mapbbcode.github.io/blob/master/_includes/"' + pathFixed + 'leaflet.css" />\n';
if( value('draw') )
str += '<link rel="stylesheet" type="text/css" href=/proxy/https/github.com/MapBBCode/mapbbcode.github.io/blob/master/_includes/"' + pathFixed + 'leaflet.draw.css" />\n';
str += '<script type="text/javascript" src=/proxy/https/github.com/MapBBCode/mapbbcode.github.io/blob/master/_includes/"' + pathFixed + 'leaflet.js"><' + '/script>\n';
if( value('draw') )
str += '<script type="text/javascript" src=/proxy/https/github.com/MapBBCode/mapbbcode.github.io/blob/master/_includes/"' + pathFixed + 'leaflet.draw.js"><' + '/script>\n';
str += '<script type="text/javascript" src=/proxy/https/github.com/MapBBCode/mapbbcode.github.io/blob/master/_includes/"' + pathFixed + 'mapbbcode.js"><' + '/script>\n';
if( 'layers' in mapbbcfg )
str += '<script type="text/javascript" src=/proxy/https/github.com/MapBBCode/mapbbcode.github.io/blob/master/_includes/"' + pathFixed + 'LayerList.js"><' + '/script>\n';
for( i = 0; i < proprietary.length; i++ )
str += '<script type="text/javascript" src=/proxy/https/github.com/MapBBCode/mapbbcode.github.io/blob/master/_includes/"' + pathFixed + 'proprietary/' + proprietary[i] + '.js"><' + '/script>\n';
if( value('length') )
str += '<script type="text/javascript" src=/proxy/https/github.com/MapBBCode/mapbbcode.github.io/blob/master/_includes/"' + pathFixed + 'Handler.Length.js"><' + '/script>\n';
if( value('lang') )
str += '<script type="text/javascript" src=/proxy/https/github.com/MapBBCode/mapbbcode.github.io/blob/master/_includes/"' + pathFixed + 'lang/' + value('lang') + '.js"><' + '/script>\n';
if( bbcode )
str += '<div id="map"></div>\n';
str += '<script type="text/javascript">\nvar mapBB = new MapBBCode(' + printOptions(mapbbcfg) + ');\n';
if( bbcode )
str += 'mapBB.show("map", "' + bbcode.replace('\n', '" +\n\t"') + '");\n';
str += '<'+'/script>';
} else {
var lopt = { mapBBCodeOptions: mapbbcfg };
if( pathFixed !== 'mapbbcode/' )
lopt.path = quotes(pathFixed);
if( mapbbcfg.windowPath === quotes(pathFixed) )
delete mapbbcfg.windowPath;
if( value('lang') )
lopt.language = value('lang');
if( value('draw') )
lopt.draw = true;
if( value('length') )
lopt.addons = '["Handler.Length"]';
if( proprietary.length ) {
var p = [];
for( i = 0; i < proprietary.length; i++ )
p.push('"' + proprietary[i] + '"');
lopt.proprietary = '[' + p.join(', ') + ']';
}
str += '<script type="text/javascript" src=/proxy/https/github.com/MapBBCode/mapbbcode.github.io/blob/master/_includes/"' + pathFixed + 'MapBBCodeLoader.min.js"><' + '/script>\n';
str += '<script type="text/javascript">mapBBCodeLoaderOptions.set(' + printOptions(lopt) + ');</' + '/script>';
if( bbcode )
str += '\n<div class="mapbbcode">' + bbcode + '</div>';
}
str = str.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
document.getElementById('code').innerHTML = str;
}
</script>
You can’t perform that action at this time.