Skip to content

Commit

Permalink
update to fetch geojson from /data rather than PIP request
Browse files Browse the repository at this point in the history
  • Loading branch information
thisisaaronland committed Mar 23, 2021
1 parent d4474e4 commit e0fdfcf
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 38 deletions.
3 changes: 0 additions & 3 deletions flags/append.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ func AppendWWWFlags(fs *flag.FlagSet) error {

fs.String(SERVER_URI, "http://localhost:8080", "A valid aaronland/go-http-server URI.")

desc_geojson := fmt.Sprintf("Allow users to request GeoJSON FeatureCollection formatted responses. This is automatically enabled if the -%s flag is set.", ENABLE_WWW)
fs.Bool(ENABLE_GEOJSON, false, desc_geojson)

fs.Bool(ENABLE_WWW, false, "Enable the interactive /debug endpoint to query points and display results.")

fs.String(PATH_PREFIX, "", "Prepend this prefix to all assets (but not HTTP handlers). This is mostly for API Gateway integrations.")
Expand Down
2 changes: 0 additions & 2 deletions flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ const PATH_PIP string = "path-pip"
const PATH_DATA string = "path-data"

const ENABLE_WWW string = "enable-www"
const ENABLE_GEOJSON string = "enable-geojson"

const ENABLE_TANGRAM string = "enable-tangram"

const NEXTZEN_APIKEY string = "nextzen-apikey"
Expand Down
5 changes: 0 additions & 5 deletions flags/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ func ValidateWWWFlags(fs *flag.FlagSet) error {
return nil
}

log.Printf("-%s flag is true causing the following flags to also be true: -%s\n", ENABLE_WWW, ENABLE_GEOJSON)

fs.Set(ENABLE_GEOJSON, "true")
// fs.Set(ENABLE_PROPERTIES, "true")

init_lat, err := lookup.Float64Var(fs, INITIAL_LATITUDE)

if err != nil {
Expand Down
5 changes: 1 addition & 4 deletions server/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ func (server_app *HTTPServerApplication) RunWithFlagSet(ctx context.Context, fs
}

enable_www, _ := lookup.BoolVar(fs, www_flags.ENABLE_WWW)
enable_geojson, _ := lookup.BoolVar(fs, www_flags.ENABLE_GEOJSON)
enable_tangram, _ := lookup.BoolVar(fs, www_flags.ENABLE_TANGRAM)

nextzen_apikey, _ := lookup.StringVar(fs, www_flags.NEXTZEN_APIKEY)
Expand Down Expand Up @@ -180,9 +179,7 @@ func (server_app *HTTPServerApplication) RunWithFlagSet(ctx context.Context, fs

// point-in-polygon handlers

api_pip_opts := &api.PointInPolygonHandlerOptions{
EnableGeoJSON: enable_geojson,
}
api_pip_opts := &api.PointInPolygonHandlerOptions{}

api_pip_handler, err := api.PointInPolygonHandler(spatial_app, api_pip_opts)

Expand Down
2 changes: 1 addition & 1 deletion static/javascript/whosonfirst.spatial.api.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ whosonfirst.spatial.api = (function(){
req.open("POST", abs_url, true);

req.setRequestHeader("Content-type", "application/json");
req.setRequestHeader("Accept", "application/geo+json");
// req.setRequestHeader("Accept", "application/geo+json");

var enc_args = JSON.stringify(args);
req.send(enc_args);
Expand Down
52 changes: 31 additions & 21 deletions static/javascript/whosonfirst.spatial.pip.init.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,35 +160,45 @@ window.addEventListener("load", function load(event){

var key = id + "_date";
args[key] = value;
}
};

var show_feature = function(id){

var data_root = document.body.getAttribute("data-root");
var url = data_root + id;

var on_success = function(data){

var l = L.geoJSON(data, {
style: function(feature){
return whosonfirst.spatial.pip.named_style("match");
},
});

layers.addLayer(l);
l.bringToFront();
};

var on_fail= function(err){
console.log("SAD", id, err);
}

whosonfirst.net.fetch(url, on_success, on_fail);
};

var on_success = function(rsp){

layers.clearLayers();

// FIX ME...

var l = L.geoJSON(rsp, {
style: function(feature){
return whosonfirst.spatial.pip.named_style("match");
},
});

layers.addLayer(l);
l.bringToFront();

//

var places = rsp["features"];
var places = rsp["places"];
var count = places.length;

var table_props = whosonfirst.spatial.pip.default_properties();

var count_properties = properties.length;

for (var i=0; i < count_properties; i++){
table_props[properties[i]] = "";
for (var i=0; i < count; i++){
var pl = places[i];
show_feature(pl["wof:id"]);
}

var table_props = whosonfirst.spatial.pip.default_properties();
var table = whosonfirst.spatial.pip.render_properties_table(places, table_props);

var matches = document.getElementById("pip-matches");
Expand Down
6 changes: 4 additions & 2 deletions static/javascript/whosonfirst.spatial.pip.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ whosonfirst.spatial.pip = (function(){

for (var i=0; i < count; i++){

var f = features[i];
var props = f["properties"];
// var f = features[i];
// var props = f["properties"];

var props = features[i];

// draw table header

if (i % 10 == 0){
Expand Down

0 comments on commit e0fdfcf

Please sign in to comment.