1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
const clone = require('../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
})
});
|