Skip to content

Commit

Permalink
completes first end-to-end processing of senseanal
Browse files Browse the repository at this point in the history
  • Loading branch information
mhausenblas committed Feb 14, 2017
1 parent 61f8ddc commit 24f7f3d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 24 deletions.
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 @@ -3,7 +3,10 @@
<body>
<div id="mapdiv"></div>
<script src="http://www.openlayers.org/api/OpenLayers.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<script>
var BASE_URL = "http://" + window.location.host;
$(document).ready(function() {
map = new OpenLayers.Map("mapdiv");
map.addLayer(new OpenLayers.Layer.OSM());

Expand All @@ -17,18 +20,19 @@

var vectorLayer = new OpenLayers.Layer.Vector("Overlay");

// Define markers as "features" of the vector layer:
var feature = new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.Point(10.18616224669654, 56.16929516572502).transform(epsg4326, projectTo),
{description:'This is the value of<br>the description attribute'} ,
{externalGraphic: 'marker.png', graphicHeight: 25, graphicWidth: 21, graphicXOffset:-12, graphicYOffset:-25 }
);
vectorLayer.addFeatures(feature);

$.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);
});

map.addLayer(vectorLayer);


//Add a selector control to the vectorLayer with popup functions
var controls = {
selector: new OpenLayers.Control.SelectFeature(vectorLayer, { onSelect: createPopup, onUnselect: destroyPopup })
Expand All @@ -54,7 +58,7 @@

map.addControl(controls['selector']);
controls['selector'].activate();

});
</script>

</body></html>
17 changes: 3 additions & 14 deletions 1.8/sensoranalytics/mapping-agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
log "github.com/Sirupsen/logrus"
"net/http"
"os"
"strconv"
"sync"
)

Expand Down Expand Up @@ -62,19 +61,9 @@ func servecontent() {
log.WithFields(log.Fields{"func": "servecontent"}).Info(fmt.Sprintf("Serving data: %v records", len(t.Result.Records)))
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Content-Type", "application/json")

lookup := t.Result.Records[0].ID
gm := GeoMarker{}
for _, record := range rmd.Result.Records {
if record.ID == lookup {
gm.Lat, _ = strconv.ParseFloat(record.Lat, 64)
gm.Lng, _ = strconv.ParseFloat(record.Lng, 64)
gm.Label = record.Name
break
}
}
// join with route and metrics data and create geomap overlay data:
json.NewEncoder(w).Encode(gm)
// 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))

})
log.WithFields(log.Fields{"func": "servecontent"}).Info("Starting app server")
Expand Down
17 changes: 17 additions & 0 deletions 1.8/sensoranalytics/mapping-agent/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
log "github.com/Sirupsen/logrus"
"github.com/minio/minio-go"
"os"
"strconv"
)

func about() {
Expand Down Expand Up @@ -67,3 +68,19 @@ func syncstaticdata() MetaTrafficData {
}
return mtd
}

// Lookup joins a record ID from a traffic datapoint with
// the static route and metrics data set and creates a geo-coded
// marker for consumption in the OSM overlay from it
func lookup(id int) GeoMarker {
gm := GeoMarker{}
for _, record := range rmd.Result.Records {
if record.ID == id {
gm.Lat, _ = strconv.ParseFloat(record.Lat, 64)
gm.Lng, _ = strconv.ParseFloat(record.Lng, 64)
gm.Label = record.Name
break
}
}
return gm
}

0 comments on commit 24f7f3d

Please sign in to comment.