Skip to content

Commit 3adaf04

Browse files
committed
completes geomarker rendering in senseanal
1 parent 24f7f3d commit 3adaf04

File tree

5 files changed

+31
-16
lines changed

5 files changed

+31
-16
lines changed

1.8/sensoranalytics/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ Now we're all set and can use the demo.
131131

132132
The following sections describe how to use the demo after having installed it.
133133

134-
TBD
134+
As a result, this is what you should see in the mapping agent Web interface:
135+
136+
![OSM overlay with Markers](img/osm-overlay-marker.png)
135137

136138
## Development
137139

1 MB
Loading

1.8/sensoranalytics/mapping-agent/content/index.html

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,21 @@
2121
var vectorLayer = new OpenLayers.Layer.Vector("Overlay");
2222

2323
$.getJSON(BASE_URL + '/data', function(d) {
24-
console.log(d.label, d.lng, d.lat)
25-
// Define markers as "features" of the vector layer:
26-
var feature = new OpenLayers.Feature.Vector(
27-
new OpenLayers.Geometry.Point(d.lng, d.lat).transform(epsg4326, projectTo),
28-
{description:d.label} ,
29-
{externalGraphic: 'marker.png', graphicHeight: 25, graphicWidth: 21, graphicXOffset:-12, graphicYOffset:-25 }
30-
);
31-
vectorLayer.addFeatures(feature);
32-
});
24+
for (var i = 0; i < d.length; i++) {
25+
var gm = d[i]
26+
console.log(gm.label, gm.lng, gm.lat)
27+
if (gm.lng > 0 && gm.lat > 0) {
28+
var feature = new OpenLayers.Feature.Vector(
29+
new OpenLayers.Geometry.Point(gm.lng, gm.lat).transform(epsg4326, projectTo),
30+
{description: 'At <b>' + gm.timestamp + '</b><br/>there were <b>' + gm.numvehicles + '</b> vehicles<br/>in <b>' + gm.label + '</b>' } ,
31+
{externalGraphic: 'marker.png', graphicHeight: 25, graphicWidth: 21, graphicXOffset:-12, graphicYOffset:-25 }
32+
);
33+
vectorLayer.addFeatures(feature);
34+
}
35+
}
3336

34-
map.addLayer(vectorLayer);
37+
map.addLayer(vectorLayer);
38+
});
3539

3640
//Add a selector control to the vectorLayer with popup functions
3741
var controls = {

1.8/sensoranalytics/mapping-agent/data.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ type MetaRecord struct {
6767

6868
// GeoMarker carries the data for an OSM overlay marker
6969
type GeoMarker struct {
70-
Lat float64 `json:"lat"`
71-
Lng float64 `json:"lng"`
72-
Label string `json:"label"`
70+
Lat float64 `json:"lat"`
71+
Lng float64 `json:"lng"`
72+
Label string `json:"label"`
73+
TimeStamp string `json:"timestamp"`
74+
VehicleCount int `json:"numvehicles"`
7375
}

1.8/sensoranalytics/mapping-agent/main.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,15 @@ func servecontent() {
6262
w.Header().Set("Access-Control-Allow-Origin", "*")
6363
w.Header().Set("Content-Type", "application/json")
6464
// join with route and metrics data and create geomap overlay data
65-
// TBD: create slice with all the data points
66-
json.NewEncoder(w).Encode(lookup(t.Result.Records[0].ID))
65+
gmlist := []GeoMarker{}
66+
for _, record := range t.Result.Records {
67+
gm := lookup(record.ID)
68+
gm.TimeStamp = record.TimeStamp
69+
gm.VehicleCount = record.VehicleCount
70+
gmlist = append(gmlist, gm)
71+
log.WithFields(log.Fields{"func": "servecontent"}).Info(fmt.Sprintf("%v", gm))
72+
}
73+
json.NewEncoder(w).Encode(gmlist)
6774

6875
})
6976
log.WithFields(log.Fields{"func": "servecontent"}).Info("Starting app server")

0 commit comments

Comments
 (0)