var EPSG4326 = new OpenLayers.Projection("EPSG:4326"); // lon/lat
var EPSG3857 = new OpenLayers.Projection("EPSG:3857"); // google
+ // tool functions
+ function createElement(tagName, attributes={}) {
+ var element = $(document.createElement(tagName));
+ for (var attribute in attributes) {
+ element.attr(attribute, attributes[attribute]);
+ }
+ return element;
+ }
+
+ function appendElement(parentElement, tagName, attributes={}) {
+ var element = createElement(tagName, attributes);
+ parentElement.append(element);
+ return element;
+ }
+
+
// extract geojson from map element and clear map element's content
jq_map = $(jq_map);
OpenLayers.ImgPath = jq_map.attr('data-img-path'); // e.g. "/mediawiki/extensions/wrmap/openlayers/img/"
autoActivate: true,
toggle: true,
onSelect: function(feature) {
- var popup_text = '';
+ var popup_div = createElement('div');
if (feature.attributes.type == 'sledrun') {
- popup_text += "<h2>" + feature.attributes.name + '</h2>\n' +
- '<ul>\n' +
- '<li><a href="' + feature.attributes.wiki + '">Details zur Rodelbahn</a></li>\n' +
- '<li>Rodelbahnzustand<br/>';
+ popup_div.append(createElement('h2').text(feature.attributes.name));
+ var ul = appendElement(popup_div, 'ul');
+ ul.append(createElement('li').append(createElement('a', {'href': feature.attributes.wiki}).text('Details zur Rodelbahn')));
+ var li = appendElement(ul, 'li').text('Rodelbahnzustand').append(createElement('br'));
if (feature.attributes.condition !== undefined) {
- var condition_text = {1: 'Sehr gut', 2: 'Gut', 3: 'Mittelmäßig', 4: 'Schlecht', 5: 'Geht nicht'};
+ var condition_text = {1: 'Sehr gut', 2: 'Gut', 3: 'Mittelmäßig', 4: 'Schlecht', 5: 'Geht nicht'};
var year_month_day = feature.attributes.date_report.split('-');
- popup_text += '<a href="' + feature.attributes.wiki + '#Eintr.C3.A4ge">' + condition_text[feature.attributes.condition] + '</a> ' +
- '<small>' + year_month_day[2] + '.' + year_month_day[1] + '.</small> ' +
- '<em><a href="' + feature.attributes.wiki + '#Eintragen">Neu</a></em>';
+ li.append(createElement('a', {'href': feature.attributes.wiki + '#Eintr.C3.A4ge'}).text(condition_text[feature.attributes.condition]), ' ');
+ li.append(createElement('small').text(year_month_day[2] + '.' + year_month_day[1] + '.'), ' ');
+ li.append(createElement('em').append(createElement('a', {'href': feature.attributes.wiki + '#Eintragen'}).text('Neu')));
} else {
- popup_text += '<em><a href="' + feature.attributes.wiki + '#Eintragen">Bitte eintragen</a></em>';
+ li.append(createElement('em').append(createElement('a', {'href': feature.attributes.wiki + '#Eintragen'}).text('Bitte eintragen')));
}
- popup_text += '</li>\n</ul>\n';
} else if (feature.attributes.wiki !== undefined) {
- if (feature.attributes.name != undefined) popup_text += '<h2>' + feature.attributes.name + '</h2>\n';
- popup_text += '<p><a href="' + feature.attributes.wiki + '">Details</a></p>\n';
+ if (feature.attributes.name != undefined) popup_div.append(createElement('h2').text(feature.attributes.name));
+ popup_div.append(createElement('p').append(createElement('a', {'href': feature.attributes.wiki}).text('Details')));
} else return;
// Open popup
var popup = new OpenLayers.Popup.FramedCloud('sledruninfopopup_' + feature.attributes.wiki,
feature.geometry.getBounds().getCenterLonLat(),
null,
- popup_text,
+ popup_div.html(),
null, true, function(event) {
// onPopupClose
selectFeatureControl.unselectAll();