2017-12-25 15:12:44 +00:00
|
|
|
define(['map/clientlayer', 'map/labellayer', 'map/button', 'leaflet', 'map/activearea'],
|
2017-04-30 12:59:39 +00:00
|
|
|
function (ClientLayer, LabelLayer, Button, L) {
|
2017-01-29 23:51:08 +00:00
|
|
|
'use strict';
|
2016-05-27 21:59:01 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
var options = {
|
|
|
|
worldCopyJump: true,
|
2017-03-14 18:25:11 +00:00
|
|
|
zoomControl: true,
|
|
|
|
minZoom: 0
|
2016-05-22 12:51:30 +00:00
|
|
|
};
|
2015-04-04 17:08:28 +00:00
|
|
|
|
2017-11-03 21:07:22 +00:00
|
|
|
return function (linkScale, sidebar, buttons) {
|
2016-05-22 11:23:43 +00:00
|
|
|
var self = this;
|
|
|
|
var savedView;
|
2015-03-24 23:54:00 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
var map;
|
2016-05-22 11:23:43 +00:00
|
|
|
var layerControl;
|
|
|
|
var baseLayers = {};
|
2015-04-04 17:08:28 +00:00
|
|
|
|
2015-04-19 14:54:35 +00:00
|
|
|
function saveView() {
|
2016-05-22 12:51:30 +00:00
|
|
|
savedView = {
|
|
|
|
center: map.getCenter(),
|
|
|
|
zoom: map.getZoom()
|
|
|
|
};
|
2015-04-19 14:54:35 +00:00
|
|
|
}
|
|
|
|
|
2016-05-22 14:36:14 +00:00
|
|
|
function contextMenuOpenLayerMenu() {
|
2017-01-29 23:51:08 +00:00
|
|
|
document.querySelector('.leaflet-control-layers').classList.add('leaflet-control-layers-expanded');
|
2016-02-25 14:47:07 +00:00
|
|
|
}
|
|
|
|
|
2017-12-25 15:12:44 +00:00
|
|
|
function setActiveArea() {
|
|
|
|
setTimeout(function () {
|
|
|
|
map.setActiveArea({
|
|
|
|
position: 'absolute',
|
|
|
|
left: sidebar.getWidth() + 'px',
|
|
|
|
right: 0,
|
|
|
|
top: 0,
|
|
|
|
bottom: 0
|
|
|
|
});
|
|
|
|
}, 300);
|
|
|
|
}
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
var el = document.createElement('div');
|
|
|
|
el.classList.add('map');
|
2015-03-24 23:54:00 +00:00
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
map = L.map(el, options);
|
2017-12-25 15:12:44 +00:00
|
|
|
map.setActiveArea({
|
|
|
|
position: 'absolute',
|
|
|
|
left: sidebar.getWidth() + 'px',
|
|
|
|
right: 0,
|
|
|
|
top: 0,
|
|
|
|
bottom: 0
|
|
|
|
});
|
|
|
|
|
2016-09-17 17:59:18 +00:00
|
|
|
var now = new Date();
|
|
|
|
config.mapLayers.forEach(function (item, i) {
|
2017-01-07 02:09:14 +00:00
|
|
|
if ((typeof item.config.start === 'number' && item.config.start <= now.getHours()) || (typeof item.config.end === 'number' && item.config.end > now.getHours())) {
|
2016-09-17 17:59:18 +00:00
|
|
|
item.config.order = item.config.start * -1;
|
|
|
|
} else {
|
|
|
|
item.config.order = i;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
config.mapLayers = config.mapLayers.sort(function (a, b) {
|
|
|
|
return a.config.order - b.config.order;
|
|
|
|
});
|
2015-03-24 23:54:00 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
var layers = config.mapLayers.map(function (d) {
|
2015-07-07 14:36:19 +00:00
|
|
|
return {
|
2017-01-29 23:51:08 +00:00
|
|
|
'name': d.name,
|
2017-10-29 19:52:17 +00:00
|
|
|
'layer': L.tileLayer(d.url.replace('{retina}', L.Browser.retina ? '@2x' : ''), d.config)
|
2016-05-22 11:23:43 +00:00
|
|
|
};
|
|
|
|
});
|
2015-07-07 14:36:19 +00:00
|
|
|
|
2016-12-28 03:21:55 +00:00
|
|
|
map.addLayer(layers[0].layer);
|
2015-07-07 14:36:19 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
layers.forEach(function (d) {
|
2016-05-22 11:23:43 +00:00
|
|
|
baseLayers[d.name] = d.layer;
|
|
|
|
});
|
2015-03-24 23:54:00 +00:00
|
|
|
|
2017-11-03 21:07:22 +00:00
|
|
|
var button = new Button(map, buttons);
|
2017-04-30 12:59:39 +00:00
|
|
|
|
|
|
|
map.on('locationfound', button.locationFound);
|
|
|
|
map.on('locationerror', button.locationError);
|
2017-01-29 23:51:08 +00:00
|
|
|
map.on('dragend', saveView);
|
|
|
|
map.on('contextmenu', contextMenuOpenLayerMenu);
|
2015-04-04 17:08:28 +00:00
|
|
|
|
[TASK] Add GeoJSON support
JSON needs to be added as array in config.js oder config.default.js
It needs a json and a option part (for style)
e.g.
geo: [
{
json: [
{
'type': 'Feature',
'geometry': {
'type': 'Polygon',
'coordinates': [
[
[
12.04925537109375,
49.036517514836994
],
[
12.033462524414062,
49.021660359632115
],
[
12.058181762695312,
48.99553703238219
],
[
12.11311340332031,
49.001843917978526
],
[
12.122726440429686,
49.03381654386847
],
[
12.04925537109375,
49.036517514836994
]
]
]
}
}
],
option: {
style: {
color: '#e23535',
weight: 5,
opacity: 0.4,
fillColor: '#6de922',
fillOpacity: 0.1
}
}
}
]
2018-07-27 18:02:19 +00:00
|
|
|
if (config.geo) {
|
|
|
|
[].forEach.call(config.geo, function (geo) {
|
|
|
|
L.geoJSON(geo.json, geo.option).addTo(map);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-04-30 12:59:39 +00:00
|
|
|
button.init();
|
2015-04-04 17:08:28 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
layerControl = L.control.layers(baseLayers, [], { position: 'bottomright' });
|
2016-05-22 11:23:43 +00:00
|
|
|
layerControl.addTo(map);
|
2015-04-15 20:25:22 +00:00
|
|
|
|
2017-02-26 15:09:23 +00:00
|
|
|
map.zoomControl.setPosition('topright');
|
|
|
|
|
2017-03-14 18:25:11 +00:00
|
|
|
var clientLayer = new ClientLayer({ minZoom: config.clientZoom });
|
2016-05-22 11:23:43 +00:00
|
|
|
clientLayer.addTo(map);
|
|
|
|
clientLayer.setZIndex(5);
|
2015-04-16 23:02:56 +00:00
|
|
|
|
2017-03-14 18:25:11 +00:00
|
|
|
var labelLayer = new LabelLayer({ minZoom: config.labelZoom });
|
|
|
|
labelLayer.addTo(map);
|
|
|
|
labelLayer.setZIndex(6);
|
|
|
|
|
2017-12-25 15:12:44 +00:00
|
|
|
sidebar.button.addEventListener('visibility', setActiveArea);
|
|
|
|
|
2017-03-14 18:25:11 +00:00
|
|
|
map.on('zoom', function () {
|
|
|
|
clientLayer.redraw();
|
|
|
|
labelLayer.redraw();
|
|
|
|
});
|
2015-04-17 21:54:19 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
map.on('baselayerchange', function (e) {
|
2016-05-22 11:23:43 +00:00
|
|
|
map.options.maxZoom = e.layer.options.maxZoom;
|
|
|
|
clientLayer.options.maxZoom = map.options.maxZoom;
|
2017-03-14 18:25:11 +00:00
|
|
|
labelLayer.options.maxZoom = map.options.maxZoom;
|
2016-05-25 20:52:29 +00:00
|
|
|
if (map.getZoom() > map.options.maxZoom) {
|
|
|
|
map.setZoom(map.options.maxZoom);
|
|
|
|
}
|
2016-07-23 12:52:19 +00:00
|
|
|
|
2017-01-31 03:45:27 +00:00
|
|
|
var style = document.querySelector('.css-mode:not([media="not"])');
|
|
|
|
if (style && e.layer.options.mode !== '' && !style.classList.contains(e.layer.options.mode)) {
|
|
|
|
style.media = 'not';
|
2017-03-14 18:25:11 +00:00
|
|
|
labelLayer.updateLayer();
|
2016-07-23 12:52:19 +00:00
|
|
|
}
|
|
|
|
if (e.layer.options.mode) {
|
2017-02-03 01:07:31 +00:00
|
|
|
var newStyle = document.querySelector('.css-mode.' + e.layer.options.mode);
|
|
|
|
newStyle.media = '';
|
|
|
|
newStyle.appendChild(document.createTextNode(''));
|
2017-03-14 18:25:11 +00:00
|
|
|
labelLayer.updateLayer();
|
2016-07-23 12:52:19 +00:00
|
|
|
}
|
2016-05-22 11:23:43 +00:00
|
|
|
});
|
2016-05-22 10:30:31 +00:00
|
|
|
|
2017-10-21 00:06:42 +00:00
|
|
|
map.on('load', function () {
|
2017-11-02 21:38:22 +00:00
|
|
|
var inputs = document.querySelectorAll('.leaflet-control-layers-selector');
|
|
|
|
[].forEach.call(inputs, function (input) {
|
2017-10-21 00:06:42 +00:00
|
|
|
input.setAttribute('role', 'radiogroup');
|
|
|
|
input.setAttribute('aria-label', input.nextSibling.innerHTML.trim());
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
var nodeDict = {};
|
|
|
|
var linkDict = {};
|
|
|
|
var highlight;
|
2015-04-06 09:58:02 +00:00
|
|
|
|
2015-04-17 20:10:47 +00:00
|
|
|
function resetMarkerStyles(nodes, links) {
|
2016-05-22 12:51:30 +00:00
|
|
|
Object.keys(nodes).forEach(function (d) {
|
2016-05-22 11:23:43 +00:00
|
|
|
nodes[d].resetStyle();
|
|
|
|
});
|
2015-04-06 09:58:02 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
Object.keys(links).forEach(function (d) {
|
2016-05-22 11:23:43 +00:00
|
|
|
links[d].resetStyle();
|
|
|
|
});
|
2015-04-17 20:10:47 +00:00
|
|
|
}
|
2015-04-06 09:58:02 +00:00
|
|
|
|
2017-03-05 11:29:21 +00:00
|
|
|
function setView(bounds, zoom) {
|
2017-12-25 15:12:44 +00:00
|
|
|
map.fitBounds(bounds, { maxZoom: (zoom ? zoom : config.nodeZoom) });
|
2015-04-17 20:10:47 +00:00
|
|
|
}
|
2015-04-06 09:58:02 +00:00
|
|
|
|
2015-04-17 20:10:47 +00:00
|
|
|
function goto(m) {
|
2016-05-22 11:23:43 +00:00
|
|
|
var bounds;
|
2015-04-06 09:58:02 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
if ('getBounds' in m) {
|
2016-05-22 11:23:43 +00:00
|
|
|
bounds = m.getBounds();
|
2016-05-22 12:51:30 +00:00
|
|
|
} else {
|
2016-05-22 11:23:43 +00:00
|
|
|
bounds = L.latLngBounds([m.getLatLng()]);
|
2016-05-22 12:51:30 +00:00
|
|
|
}
|
2015-04-06 09:58:02 +00:00
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
setView(bounds);
|
2015-04-06 09:58:02 +00:00
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
return m;
|
2015-04-17 20:10:47 +00:00
|
|
|
}
|
2015-04-06 09:58:02 +00:00
|
|
|
|
2015-04-17 20:10:47 +00:00
|
|
|
function updateView(nopanzoom) {
|
2016-05-22 11:23:43 +00:00
|
|
|
resetMarkerStyles(nodeDict, linkDict);
|
|
|
|
var m;
|
2015-04-06 09:58:02 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
if (highlight !== undefined) {
|
2017-10-29 14:11:24 +00:00
|
|
|
if (highlight.type === 'node' && nodeDict[highlight.o.node_id]) {
|
|
|
|
m = nodeDict[highlight.o.node_id];
|
2017-11-05 17:23:40 +00:00
|
|
|
m.setStyle(config.map.highlightNode);
|
2017-02-12 23:31:31 +00:00
|
|
|
} else if (highlight.type === 'link' && linkDict[highlight.o.id]) {
|
2016-05-22 11:23:43 +00:00
|
|
|
m = linkDict[highlight.o.id];
|
2017-11-05 17:23:40 +00:00
|
|
|
m.setStyle(config.map.highlightLink);
|
2015-04-17 20:10:47 +00:00
|
|
|
}
|
2016-05-22 12:51:30 +00:00
|
|
|
}
|
2015-04-17 20:10:47 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
if (!nopanzoom) {
|
|
|
|
if (m) {
|
2016-05-22 11:23:43 +00:00
|
|
|
goto(m);
|
2016-05-22 12:51:30 +00:00
|
|
|
} else if (savedView) {
|
2016-05-22 11:23:43 +00:00
|
|
|
map.setView(savedView.center, savedView.zoom);
|
2016-05-22 12:51:30 +00:00
|
|
|
} else {
|
2016-12-28 03:21:55 +00:00
|
|
|
setView(config.fixedCenter);
|
2016-05-22 12:51:30 +00:00
|
|
|
}
|
|
|
|
}
|
2015-04-17 20:10:47 +00:00
|
|
|
}
|
2015-04-06 09:58:02 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
self.setData = function setData(data) {
|
2016-05-22 11:23:43 +00:00
|
|
|
nodeDict = {};
|
|
|
|
linkDict = {};
|
2015-04-06 13:54:26 +00:00
|
|
|
|
2017-04-30 12:59:39 +00:00
|
|
|
clientLayer.setData(data);
|
2017-11-03 21:07:22 +00:00
|
|
|
labelLayer.setData(data, map, nodeDict, linkDict, linkScale);
|
2015-03-29 14:14:10 +00:00
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
updateView(true);
|
|
|
|
};
|
2015-04-16 23:02:56 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
self.resetView = function resetView() {
|
2017-04-30 12:59:39 +00:00
|
|
|
button.disableTracking();
|
2016-05-22 11:23:43 +00:00
|
|
|
highlight = undefined;
|
|
|
|
updateView();
|
|
|
|
};
|
2015-03-29 14:14:10 +00:00
|
|
|
|
2017-03-05 11:29:21 +00:00
|
|
|
self.gotoNode = function gotoNode(d) {
|
2017-04-30 12:59:39 +00:00
|
|
|
button.disableTracking();
|
2017-01-29 23:51:08 +00:00
|
|
|
highlight = { type: 'node', o: d };
|
2017-03-05 11:29:21 +00:00
|
|
|
updateView();
|
2016-05-22 11:23:43 +00:00
|
|
|
};
|
2015-03-25 00:16:15 +00:00
|
|
|
|
2017-03-05 11:29:21 +00:00
|
|
|
self.gotoLink = function gotoLink(d) {
|
2017-04-30 12:59:39 +00:00
|
|
|
button.disableTracking();
|
2017-11-14 16:37:20 +00:00
|
|
|
highlight = { type: 'link', o: d[0] };
|
2017-03-05 11:29:21 +00:00
|
|
|
updateView();
|
2016-05-22 11:23:43 +00:00
|
|
|
};
|
2015-03-24 23:54:00 +00:00
|
|
|
|
2017-03-05 11:29:21 +00:00
|
|
|
self.gotoLocation = function gotoLocation(d) {
|
2017-04-30 12:59:39 +00:00
|
|
|
button.disableTracking();
|
2017-03-05 11:29:21 +00:00
|
|
|
map.setView([d.lat, d.lng], d.zoom);
|
2016-05-22 11:23:43 +00:00
|
|
|
};
|
2016-02-25 14:47:07 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
self.destroy = function destroy() {
|
2017-04-30 12:59:39 +00:00
|
|
|
button.clearButtons();
|
2017-12-25 15:12:44 +00:00
|
|
|
sidebar.button.removeEventListener('visibility', setActiveArea);
|
2016-05-22 11:23:43 +00:00
|
|
|
map.remove();
|
2015-07-11 22:11:18 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
if (el.parentNode) {
|
2016-05-22 11:23:43 +00:00
|
|
|
el.parentNode.removeChild(el);
|
2016-05-22 12:51:30 +00:00
|
|
|
}
|
2016-05-22 11:23:43 +00:00
|
|
|
};
|
2015-07-11 22:11:18 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
self.render = function render(d) {
|
2016-05-22 11:23:43 +00:00
|
|
|
d.appendChild(el);
|
|
|
|
map.invalidateSize();
|
|
|
|
};
|
2015-03-24 23:54:00 +00:00
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
return self;
|
|
|
|
};
|
2016-05-22 12:51:30 +00:00
|
|
|
});
|