diff options
| author | Luc Donnet | 2017-10-16 23:52:06 +0200 |
|---|---|---|
| committer | Luc Donnet | 2017-10-16 23:52:06 +0200 |
| commit | f480ad0739e5c0ec2c0c8bb890344b9c4777ba35 (patch) | |
| tree | a19bc6b43449b8b978a53c33476fb3eb571d4dda /app/javascript/packs/routes/show.js | |
| parent | b611a84ed724036c4929bd4c3eaa7e23ea314f45 (diff) | |
| parent | 51a1ea5b141032121913f807a162d305828bec54 (diff) | |
| download | chouette-core-f480ad0739e5c0ec2c0c8bb890344b9c4777ba35.tar.bz2 | |
Merge branch 'master' into staging
Diffstat (limited to 'app/javascript/packs/routes/show.js')
| -rw-r--r-- | app/javascript/packs/routes/show.js | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/app/javascript/packs/routes/show.js b/app/javascript/packs/routes/show.js new file mode 100644 index 000000000..7f14a6f11 --- /dev/null +++ b/app/javascript/packs/routes/show.js @@ -0,0 +1,102 @@ +import clone from '../../helpers/clone' +let route = clone(window, "route", true) +route = JSON.parse(decodeURIComponent(route)) + +const geoColPts = [] +const geoColLns = [] +const geoColEdges = [ + new ol.Feature({ + geometry: new ol.geom.Point(ol.proj.fromLonLat([parseFloat(route[0].longitude), parseFloat(route[0].latitude)])) + }), + new ol.Feature({ + geometry: new ol.geom.Point(ol.proj.fromLonLat([parseFloat(route[route.length - 1].longitude), parseFloat(route[route.length - 1].latitude)])) + }) +] +route.forEach(function (stop, i) { + if (i < route.length - 1) { + geoColLns.push(new ol.Feature({ + geometry: new ol.geom.LineString([ + ol.proj.fromLonLat([parseFloat(route[i].longitude), parseFloat(route[i].latitude)]), + ol.proj.fromLonLat([parseFloat(route[i + 1].longitude), parseFloat(route[i + 1].latitude)]) + ]) + })) + } + geoColPts.push(new ol.Feature({ + geometry: new ol.geom.Point(ol.proj.fromLonLat([parseFloat(stop.longitude), parseFloat(stop.latitude)])) + }) + ) +}) +var edgeStyles = new ol.style.Style({ + image: new ol.style.Circle(({ + radius: 5, + stroke: new ol.style.Stroke({ + color: '#007fbb', + width: 2 + }), + fill: new ol.style.Fill({ + color: '#007fbb', + width: 2 + }) + })) +}) +var defaultStyles = new ol.style.Style({ + image: new ol.style.Circle(({ + radius: 4, + stroke: new ol.style.Stroke({ + color: '#007fbb', + width: 2 + }), + fill: new ol.style.Fill({ + color: '#ffffff', + width: 2 + }) + })) +}) +var lineStyle = new ol.style.Style({ + stroke: new ol.style.Stroke({ + color: '#007fbb', + width: 3 + }) +}) + +var vectorPtsLayer = new ol.layer.Vector({ + source: new ol.source.Vector({ + features: geoColPts + }), + style: defaultStyles, + zIndex: 2 +}) +var vectorEdgesLayer = new ol.layer.Vector({ + source: new ol.source.Vector({ + features: geoColEdges + }), + style: edgeStyles, + zIndex: 3 +}) +var vectorLnsLayer = new ol.layer.Vector({ + source: new ol.source.Vector({ + features: geoColLns + }), + style: [lineStyle], + zIndex: 1 +}) + +var map = new ol.Map({ + target: 'route_map', + layers: [ + new ol.layer.Tile({ + source: new ol.source.OSM() + }), + vectorPtsLayer, + vectorEdgesLayer, + vectorLnsLayer + ], + controls: [new ol.control.ScaleLine(), new ol.control.Zoom(), new ol.control.ZoomSlider()], + interactions: ol.interaction.defaults({ + zoom: true + }), + view: new ol.View({ + center: ol.proj.fromLonLat([parseFloat(route[0].longitude), parseFloat(route[0].latitude)]), + zoom: 13 + }) +}); |
