Skip to content

Commit

Permalink
completes geomarker rendering in senseanal
Browse files Browse the repository at this point in the history
  • Loading branch information
mhausenblas committed Feb 15, 2017
1 parent 24f7f3d commit 3adaf04
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 16 deletions.
4 changes: 3 additions & 1 deletion 1.8/sensoranalytics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ Now we're all set and can use the demo.

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

TBD
As a result, this is what you should see in the mapping agent Web interface:

![OSM overlay with Markers](img/osm-overlay-marker.png)

## Development

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 14 additions & 10 deletions 1.8/sensoranalytics/mapping-agent/content/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,21 @@
var vectorLayer = new OpenLayers.Layer.Vector("Overlay");

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

map.addLayer(vectorLayer);
map.addLayer(vectorLayer);
});

//Add a selector control to the vectorLayer with popup functions
var controls = {
Expand Down
8 changes: 5 additions & 3 deletions 1.8/sensoranalytics/mapping-agent/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ type MetaRecord struct {

// GeoMarker carries the data for an OSM overlay marker
type GeoMarker struct {
Lat float64 `json:"lat"`
Lng float64 `json:"lng"`
Label string `json:"label"`
Lat float64 `json:"lat"`
Lng float64 `json:"lng"`
Label string `json:"label"`
TimeStamp string `json:"timestamp"`
VehicleCount int `json:"numvehicles"`
}
11 changes: 9 additions & 2 deletions 1.8/sensoranalytics/mapping-agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,15 @@ func servecontent() {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Content-Type", "application/json")
// join with route and metrics data and create geomap overlay data
// TBD: create slice with all the data points
json.NewEncoder(w).Encode(lookup(t.Result.Records[0].ID))
gmlist := []GeoMarker{}
for _, record := range t.Result.Records {
gm := lookup(record.ID)
gm.TimeStamp = record.TimeStamp
gm.VehicleCount = record.VehicleCount
gmlist = append(gmlist, gm)
log.WithFields(log.Fields{"func": "servecontent"}).Info(fmt.Sprintf("%v", gm))
}
json.NewEncoder(w).Encode(gmlist)

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

0 comments on commit 3adaf04

Please sign in to comment.