This repository has been archived by the owner on Dec 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathspeeds.tpl
67 lines (67 loc) · 2.42 KB
/
speeds.tpl
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
<!doctype html>
<html lang="en">
<head>
<style>
.map {
height: 100%;
width: 100%;
}
</style>
<script src="http://openlayers.org/en/v3.9.0/build/ol.js" type="text/javascript"></script>
<title>speeds.py</title>
</head>
<body>
<div id="map" class="map"></div>
<script type="text/javascript">
function speed2color(speed){
h = 2*3.14*speed/45
return Array(127.5+127.5*Math.sin(h),127.5+127.5*Math.sin(h+120),127.5+127.5*Math.sin(h+240),1);
}
var stops = {{!stops}};
var speeds = {{!speeds}};
var stopSource = new ol.source.Vector({
features: (new ol.format.GeoJSON()).readFeatures(stops, { featureProjection: 'EPSG:3857' })
});
var speedSource = new ol.source.Vector({
features: (new ol.format.GeoJSON()).readFeatures(speeds, { featureProjection: 'EPSG:3857' })
});
var stopStyleFunctionCreator = function() {
return function(feature, resolution) {
var style = new ol.style.Style({
text: new ol.style.Text({ text: feature.getId(), scale: 1.5, fill: new ol.style.Fill({ color: 'rgba(0, 0, 0, 1)' }), stroke: new ol.style.Stroke({ color: 'rgba(255, 255, 255, 1)' }), offsetY: 20, offsetX: 20 }),
image: new ol.style.Circle({ radius: 5, fill: new ol.style.Fill({ color: 'rgba(255, 0, 0, 1)' }) })
})
return [style];
}
}
var speedStyleFunctionCreator = function() {
return function(feature, resolution) {
var style = new ol.style.Style({
text: new ol.style.Text({ text: feature.getId(), scale: 1.5, fill: new ol.style.Fill({ color: 'rgba(0, 0, 0, 1)' }), stroke: new ol.style.Stroke({ color: 'rgba(255, 255, 255, 1)' }), offsetY: -20, offsetX: -20 }),
stroke: new ol.style.Stroke({ width: feature.getId(), color: speed2color(feature.getId()) }),
})
return [style];
}
}
var stopLayer = new ol.layer.Vector({
source: stopSource,
style: stopStyleFunctionCreator()
});
var speedLayer = new ol.layer.Vector({
source: speedSource,
style: speedStyleFunctionCreator()
});
var tileLayer = new ol.layer.Tile({
source: new ol.source.OSM()
});
var map = new ol.Map({
target: 'map',
layers: [tileLayer, stopLayer, speedLayer],
view: new ol.View({
center: ol.proj.transform([-98.58, 39.83], 'EPSG:4326', 'EPSG:3857'),
zoom: 4
})
});
</script>
</body>
</html>