Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
var lineLayer = L.geoJson().addTo(mapLayer.getMap());
lineLayer.options.style = function (feature) {
var p = feature.properties || {};
return {color:p.color||"gray", weight:p.weight||2, opacity:0.5};
}
var counter = 0;
var timeLimit = 10 * 30;
var Papa = require("papaparse");
Papa.parse("http://127.0.0.1:8989/spt?point=51.351201,12.398071&time_limit="+timeLimit+"&columns=prev_longitude,prev_latitude,longitude,latitude,time,road_environment", {
download: true,
worker: true, // the UI should stay reactive while downloading
step: function(results) {
var d = results.data;
// the root node has null for the previous values and time==0
if(counter > 0 && d[4] > 0) {
var properties = {};
if (d[5] === "tunnel")
properties = {weight: 3, color: "red"};
else if(d[5] === "bridge")
properties = {weight: 3, color: "orange"};
lineLayer.addData({type:"Feature",properties: properties,geometry:{type:"LineString",coordinates:[[d[0],d[1]],[d[2],d[3]]]}});
}
counter++;
},
complete: function() {
console.log("All done for /spt! " + counter);
}
});
var lineLayer = L.geoJson().addTo(mapLayer.getMap());
lineLayer.options.style = function (feature) {
var p = feature.properties || {};
return {color:p.color||"gray", weight:p.weight||2, opacity:0.5};
}
var counter = 0;
var timeLimit = 10 * 30;
var Papa = require("papaparse");
Papa.parse("http://127.0.0.1:8989/spt?point=52.321911,10.393066&time_limit="+timeLimit+"&columns=prev_longitude,prev_latitude,longitude,latitude,time", {
download: true,
worker: true, // the UI should stay reactive while downloading
step: function(results) {
var d = results.data;
// the root node has null for the previous values and time==0
if(counter > 0 && d[4] > 0) {
var r = d[4] / 1000.0 / timeLimit;
// TODO can we avoid parsing the Color here?
var colorStr = "rgb("+255 * (1 - r)+","+ 128 * r+","+ 255 * r+")";
lineLayer.addData({type:"Feature",properties:{color:colorStr},geometry:{type:"LineString",coordinates:[[d[0],d[1]],[d[2],d[3]]]}});
}
counter++;
},
complete: function() {
console.log("All done for /spt! " + counter);
}
});
@karussell

This comment has been minimized.

Copy link
Owner Author

commented Jun 23, 2019

  1. Get GraphHopper and look into web/src/main/resources/assets/
  2. Put one of the snippets in map-template.js under mapLayer.initMap...
  3. adapt the point argument to fit the area of your GH installation
  4. run cd web && npm install papaparse
  5. run npm run watch
  6. open the UI at: http://127.0.0.1:8989/maps/?point=&layer=Omniscale%20Dev (or use http://localhost... to avoid CORS problems)

Example output

snippet:

image

highlight tunnels: (this is probably better done via the new mvt layer)

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.