Compare commits

..

4 Commits

4 changed files with 133 additions and 18 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "lifo-dijkstraserv"]
path = lifo-dijkstraserv
url = https://notsyncing.net:8080/markus/lifo-dijkstraserv.git

View File

@ -42,8 +42,7 @@ L.StreetLabels = L.LabelTextCollision
_text: function (ctx, layer) { _text: function (ctx, layer) {
if (layer && layer.feature && layer.feature.properties && layer.feature.properties[this.options.propertyName] !== 'undefined') { if (layer && layer.feature && layer.feature.properties && layer.feature.properties[this.options.propertyName] !== undefined) {
if (this.options.showLabelIf) { if (this.options.showLabelIf) {
if (this.options.showLabelIf.call(this, layer.feature) === false) { if (this.options.showLabelIf.call(this, layer.feature) === false) {
return; return;
@ -95,7 +94,7 @@ L.StreetLabels = L.LabelTextCollision
L.point(p.x + offsetX, p.y + offsetY), L.point( L.point(p.x + offsetX, p.y + offsetY), L.point(
textWidth, textHeight)); textWidth, textHeight));
if (this.options.collisionFlg) { if (this._getCollisionFlag(layer)) {
for (var index in this._textList) { for (var index in this._textList) {
var pointBounds = this._textList[index]; var pointBounds = this._textList[index];
if (pointBounds.intersects(bounds)) { if (pointBounds.intersects(bounds)) {
@ -106,7 +105,6 @@ L.StreetLabels = L.LabelTextCollision
this._textList.push(bounds); this._textList.push(bounds);
ctx.fillStyle = this.options.fontStyle.fillStyle; ctx.fillStyle = this.options.fontStyle.fillStyle;
ctx.strokeStyle = this.options.fontStyle.strokeStyle; ctx.strokeStyle = this.options.fontStyle.strokeStyle;
@ -144,6 +142,10 @@ L.StreetLabels = L.LabelTextCollision
} }
}, },
_getCollisionFlag: function (layer) {
return this.options.collisionFlg;
},
/*** /***
* Returns the bearing in degrees clockwise from north (0 degrees) * Returns the bearing in degrees clockwise from north (0 degrees)
from the first L.LatLng to the second, at the first LatLng from the first L.LatLng to the second, at the first LatLng

View File

@ -5,6 +5,7 @@ var polyconf_show_street_names = 5; // Zoom level for when to start showing stre
var polyconf_show_cities = 5; /* City outlines will be filled on this level and further away */ var polyconf_show_cities = 5; /* City outlines will be filled on this level and further away */
var polyconf_show_districts = 4; /* Shown from polyconf_show_cities until this*/ var polyconf_show_districts = 4; /* Shown from polyconf_show_cities until this*/
var dijkstraserv_base = "https://notsyncing.net/dijkstra/";
var wikiurl_base = "https://wiki.linux-forks.de/mediawiki/index.php/" var wikiurl_base = "https://wiki.linux-forks.de/mediawiki/index.php/"
var streetLabelsRenderer = new L.StreetLabels({ var streetLabelsRenderer = new L.StreetLabels({
@ -36,6 +37,13 @@ var streetLabelsRenderer = new L.StreetLabels({
}, },
}); });
streetLabelsRenderer._getCollisionFlag = function (layer) {
if (!(layer instanceof L.Polygon)) // Always check collision for streets
return true;
zoom = mymap.getZoom();
return (zoom < 5);
}
streetLabelsRenderer._getDynamicFontSize = function (layer) { streetLabelsRenderer._getDynamicFontSize = function (layer) {
zoom = mymap.getZoom(); zoom = mymap.getZoom();
@ -86,6 +94,13 @@ var style_outlines = {
var style_streets = { var style_streets = {
}; };
var style_route = {
radius: 8,
fillColor: "#00ff00",
color: "red",
opacity: 1.0,
fillOpacity: 0.5
};
// Projection fix from: https://gis.stackexchange.com/questions/200865/leaflet-crs-simple-custom-scale // Projection fix from: https://gis.stackexchange.com/questions/200865/leaflet-crs-simple-custom-scale
var factorx = 1 / 256 * 4; var factorx = 1 / 256 * 4;
@ -256,6 +271,10 @@ function load_geojson(name, url, geotype, iconcolor, active=1, style={}) {
iconname = "umbrella-beach"; iconname = "umbrella-beach";
iconcolor = "orange"; iconcolor = "orange";
break; break;
case "waterway":
iconname = "water";
iconcolor = "blue";
break;
} }
if (iconname != "star") if (iconname != "star")
break; break;
@ -347,12 +366,8 @@ function prompt_location() {
} }
var search_element; var search_element;
function toggle_search() { var route_element;
if (el = document.getElementById('searchbar')) { function build_sidebar() {
el.parentNode.removeChild(el);
return;
}
if (!search_element) { if (!search_element) {
search_element = document.createElement("div"); search_element = document.createElement("div");
search_element.style.overflow = "scroll"; search_element.style.overflow = "scroll";
@ -361,14 +376,43 @@ function toggle_search() {
search_element.innerHTML = '<input style="width:100%;" id="search_query" name="lifo_map_search" type="search" placeholder="Start typing to search..." oninput="search(event)"><div id="search_results"></div>'; search_element.innerHTML = '<input style="width:100%;" id="search_query" name="lifo_map_search" type="search" placeholder="Start typing to search..." oninput="search(event)"><div id="search_results"></div>';
} }
if (!route_element) {
route_element = document.createElement("div");
route_element.style.overflow = "scroll";
route_element.style.padding = "6px";
route_element.style.height = "100%";
route_element.innerHTML = '<a href="#" onclick="toggle_search(\'search\',1);return false;">&lt;-- Return to search<br></a><input style="width:100%;" id="route_start" name="lifo_route_loc" type="search" placeholder="Start at x,y"><br><input style="width:100%;" id="route_destination" name="lifo_route_loc" type="search" placeholder="Go to x,y"><br><input id="route_submit" type="button" style="width:100%;" value="Go!" onclick="route(event)"><div id="route_results"></div>';
}
}
var current_sidebar = "search";
function toggle_search(type = current_sidebar, force_act = 0) {
if (el = document.getElementById('sidebar')) {
el.parentNode.removeChild(el);
if (force_act == 0 && type == current_sidebar)
return;
}
td = document.getElementById('windowtr').insertCell(0); td = document.getElementById('windowtr').insertCell(0);
td.style.width = "400px"; td.style.width = "400px";
td.style.borderRight = "1px solid black"; td.style.borderRight = "1px solid black";
td.style.verticalAlign = "top"; td.style.verticalAlign = "top";
td.id = "searchbar"; td.id = "sidebar";
td.appendChild(search_element);
switch (type) {
case "search":
td.appendChild(search_element);
document.getElementById('search_query').select(); document.getElementById('search_query').select();
break;
case "route":
td.appendChild(route_element);
break;
default:
alert("JS error: sidebar");
break;
}
current_sidebar = type;
} }
function htmlEntities(str) { function htmlEntities(str) {
@ -452,6 +496,67 @@ function search(e) {
return false; return false;
} }
var route_layer;
function route(e) // BOOKMARK
{
if (route_layer) {
mymap.removeLayer(route_layer);
}
start = document.getElementById('route_start').value;
destination = document.getElementById('route_destination').value;
if ((start == "") || (destination == "")) {
document.getElementById('route_results').innerHTML = "";
return;
}
document.getElementById('route_submit').disabled = true;
document.getElementById('route_results').innerHTML = "Loading...";
var xhttp_ps = new XMLHttpRequest();
xhttp_ps.onreadystatechange = function() {
if (this.readyState == 4) {
if (this.status == 200) {
var json = JSON.parse(xhttp_ps.responseText);
geojson = L.geoJSON(json, {
style: style_route
});
route_layer = geojson.addTo(mymap);
str = "<ol>";
last_through = "";
geojson.eachLayer( function(layer) {
if (last_through != layer.feature.properties.through) {
str += '<li><a href="#" onclick="latLng2 = L.latLng(' + layer.feature.geometry.coordinates[0][1] + ',' + layer.feature.geometry.coordinates[0][0] + '); jump_to(latLng2); return false;">' + htmlEntities(layer.feature.properties.description) + "</a></li>";
last_through = layer.feature.properties.through;
}
});
str += "</ol>";
document.getElementById('route_results').innerHTML = str;
} else {
document.getElementById('route_results').innerHTML = "No results.";
}
document.getElementById('route_submit').disabled = false;
}
};
coordstr = start + ';' + destination;
xhttp_ps.open("GET", dijkstraserv_base + coordstr, true);
xhttp_ps.send();
}
function set_route_start(latlng) {
toggle_search("route", 1);
document.getElementById('route_start').value = latlng.lat + ',' + latlng.lng;
route();
}
function set_route_destination(latlng) {
toggle_search("route", 1);
document.getElementById('route_destination').value = latlng.lat + ',' + latlng.lng;
route();
}
L.MyControl = L.Control.extend({ L.MyControl = L.Control.extend({
options: { options: {
position: 'topleft', position: 'topleft',
@ -503,13 +608,15 @@ var baseballIcon = L.AwesomeMarkers.icon({
function onMapClick(e) { function onMapClick(e) {
var addinfo = ""; var addinfo = "";
pos = resolve_latlng(e.latlng);
route_links = '<br><a href="#" onclick="latLng2 = L.latLng(' + pos.lng + ',' + pos.lat + '); set_route_start(latLng2); return false;">[route from here]</a>';
route_links += ' <a href="#" onclick="latLng2 = L.latLng(' + pos.lng + ',' + pos.lat + '); set_route_destination(latLng2); return false;">[route to here]</a>';
if (current_location != "") if (current_location != "")
addinfo = " (part of <a target=\"_blank\" href='" + wikiurl_base + current_location + "'>" + current_location + "</a>)"; addinfo = " (part of <a target=\"_blank\" href='" + wikiurl_base + current_location + "'>" + current_location + "</a>)";
if (current_feature) { if (current_feature) {
popup.setLatLng(e.latlng).setContent("This is " + current_feature.properties.name + addinfo).openOn(mymap); popup.setLatLng(e.latlng).setContent("This is " + current_feature.properties.name + addinfo + route_links).openOn(mymap);
} else { } else {
pos = resolve_latlng(e.latlng); popup.setLatLng(e.latlng).setContent("You clicked the map at " + pos.lng + "," + pos.lat + addinfo + route_links).openOn(mymap);
popup.setLatLng(e.latlng).setContent("You clicked the map at " + pos.lng + "," + pos.lat + addinfo).openOn(mymap);
} }
current_feature = null; current_feature = null;
current_location = ""; current_location = "";
@ -600,5 +707,7 @@ function onHashChange(e, hash=null) {
} }
} }
build_sidebar();
window.addEventListener("hashchange", onHashChange, false); window.addEventListener("hashchange", onHashChange, false);
onHashChange(null); onHashChange(null);

1
lifo-dijkstraserv Submodule

@ -0,0 +1 @@
Subproject commit d7d59322c57c9154faa537d8d00e4ec2071f09fa