Skip to content

Commit

Permalink
Merge branch 'dev-places' of github.com:whosonfirst/whosonfirst-www-a…
Browse files Browse the repository at this point in the history
…pi into dev-config

Conflicts:
	.gitignore
	www/.htaccess
	www/include/config.php
  • Loading branch information
botsonfirst committed Aug 31, 2017
2 parents b356f4f + 82c3813 commit eb91882
Show file tree
Hide file tree
Showing 17 changed files with 315 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*~
.vagrant
www/include/config_dev.php
www/include/config_local*.php
www/include/secrets*.php
www/test*.php
Expand Down
6 changes: 6 additions & 0 deletions www/.htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,15 @@ RewriteRule ^contact/?$ contact.php [L,QSA]

RewriteRule ^id/?$ id.php [L] # mostly so we can get cfg.abs_root_url
RewriteRule ^id/([0-9]+)/?$ id.php?id=$1&%{QUERY_STRING} [L]
RewriteRule ^id/([0-9]+)/nearby/?$ id.php?id=$1&nearby=1&%{QUERY_STRING} [L]

RewriteRule ^id/([0-9]+)/info(.json)?$ info.php?id=$1&%{QUERY_STRING} [L]

RewriteRule ^nearby/?$ nearby.php?%{QUERY_STRING} [L]
RewriteRule ^nearby/([0-9]+)/?$ nearby.php?id=$1&%{QUERY_STRING} [L]

RewriteRule ^placetypes/([a-z]+)/?$ placetype.php?placetype=$1&%{QUERY_STRING} [L]

RewriteRule ^tags/([a-z]+)/?$ tag.php?tag=$1&%{QUERY_STRING} [L]

# See all this stuff that's been commented out? It's a lot of hoop-jumping
Expand Down
8 changes: 7 additions & 1 deletion www/id.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
error_404();
}

if (get_isset("nearby")){
$url = whosonfirst_places_nearby_url_for_place($place);
header("location: {$url}");
exit();
}

$parent_id = $place["wof:parent_id"];

if ($parent_id != -1){
Expand All @@ -24,7 +30,7 @@
}

$GLOBALS['smarty']->assign_by_ref("place", $place);
$GLOBALS['smarty']->display("page_id.txt", $place);
$GLOBALS['smarty']->display("page_id.txt");

exit();
?>
4 changes: 4 additions & 0 deletions www/include/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
# Things you may want to change in a hurry

$GLOBALS['cfg']['site_name'] = 'Who\'s On First API';
<<<<<<< HEAD
$GLOBALS['cfg']['environment'] = 'prod';
=======
$GLOBALS['cfg']['environment'] = 'dev';
>>>>>>> 82c38130bb71707250efc609fa436ffadb482eb5

$GLOBALS['cfg']['site_disabled'] = 0;
$GLOBALS['cfg']['site_disabled_retry_after'] = 0; # seconds; if set will return HTTP Retry-After header
Expand Down
4 changes: 3 additions & 1 deletion www/include/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,15 @@ function filter_strict_quot($str){
$local_secrets, $server_secrets, $host_secrets
);


foreach ($to_check as $path){

if (file_exists($path)){
$config_files[] = $path;
}
}


foreach ($config_files as $path){

# echo "load {$path} <br />";
Expand Down Expand Up @@ -627,4 +629,4 @@ function handle_error_notices($errno, $errstr){
}
}

# end of flamework-api stuff for API site keys
# end of flamework-api stuff for API site keys
8 changes: 8 additions & 0 deletions www/include/lib_whosonfirst_places.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,14 @@ function whosonfirst_places_url_for_place($place){

########################################################################

function whosonfirst_places_nearby_url_for_place($place){

$enc_id = urlencode($place["wof:id"]);
return $GLOBALS["cfg"]["abs_root_url"] . "nearby/{$enc_id}/";
}

########################################################################

function whosonfirst_places_data_url_for_place($place){

loadlib("whosonfirst_uri");
Expand Down
16 changes: 5 additions & 11 deletions www/javascript/flamework.api.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ flamework.api = function(){

'_handlers': {
'endpoint': null_handler,
'accesstoken': null_handler,
'authentication': null_handler,
},

'set_handler': function(target, handler){
Expand Down Expand Up @@ -90,18 +90,12 @@ flamework.api = function(){

form_data.append('method', method);

if (! form_data.has('access_token')){
var set_auth = self.get_handler('authentication');

var get_accesstoken = self.get_handler('accesstoken');

if (! get_accesstoken){
dothis_onerror(self.destruct("there is no accesstoken handler"));
return false;
}

form_data.append('access_token', get_accesstoken());
if (set_auth){
form_data = set_auth(form_data);
}
var onload = function(rsp){

var target = rsp.target;
Expand Down
47 changes: 47 additions & 0 deletions www/javascript/mapzen.places.api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
var mapzen = mapzen || {};
mapzen.places = mapzen.places || {};

mapzen.places.api = (function(){

var _api = undefined;

var self = {

'init': function(){

_api = new flamework.api();
_api.set_handler('endpoint', mapzen.places.api.endpoint);
_api.set_handler('authentication', mapzen.places.api.authentication);
},

'execute_method': function(method, data, on_success, on_error){
_api.call(method, data, on_success, on_error);
},

'call': function(method, data, on_success, on_error){
_api.call(method, data, on_success, on_error);
},

'endpoint': function(){
return document.body.getAttribute("data-mapzen-api-endpoint");
},

'authentication': function(form_data){

var key = document.body.getAttribute("data-mapzen-api-key");

if (! form_data.has("api_key")){
form_data.append("api_key", key);
}

return form_data;
}
}

return self;

})();

window.addEventListener('load', function(e){
mapzen.places.api.init();
});
61 changes: 58 additions & 3 deletions www/javascript/mapzen.places.map.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,22 @@ mapzen.places.map = (function(){

return maps[map_id];
},

'draw_nearby_map': function(map_id, cb){

var map_el = document.getElementById(map_id);
var map = self.get_map(map_id);

if (map_el.getAttribute("data-wof-id")){
return self.draw_place_map(map_id, cb);
}

console.log(location.href);

map.setView([37.7749, -122.4194], 12);

cb(map);
},

'draw_place_map': function(map_id, cb){

Expand Down Expand Up @@ -108,13 +124,52 @@ mapzen.places.map = (function(){

'add_geojson_to_map': function(map, geojson, more){

console.log("GEOJSON", geojson);

if (! more){
more = {};
}


var point_style = {
"color": "#000",
"weight": 2,
"opacity": 1,
"radius": 6,
"fillColor": "#0BBDFF",
"fillOpacity": 1
};

var point_handler = function(feature, latlon){

var props = feature['properties'];
var label = props['wof:name'];

var m = L.circleMarker(latlon, point_style);
m.bindTooltip(label);

return m;
};

var feature_handler = function(feature, layer) {

var props = feature['properties'];
var wofid = props["wof:id"];

layer.on('click', function (e){

var enc_id = encodeURIComponent(wofid);

var abs_root_url = document.body.getAttribute("data-abs-root-url");
var url = abs_root_url + "id/" + enc_id + "/";

location.href = url;
});

};

var args = {
// "style": style,
// "pointToLayer": handler
"pointToLayer": point_handler,
"onEachFeature": feature_handler,
}

// console.log("[map][geojson] ADD", geojson, args);
Expand Down
85 changes: 85 additions & 0 deletions www/javascript/mapzen.places.nearby.init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
window.addEventListener("load", function load(event){

var cb = function(map){

L.Mapzen.hash({
map: map
});

var nearby_layer;

var nearby = function(){

var center = map.getCenter();

var lat = center.lat;
var lon = center.lng;

var method = "whosonfirst.places.getNearby";

var args = {
"latitude": lat,
"longitude": lon,
"per_page": 200,
"extras": "geom:",
};

var on_success = function(rsp){

var features = [];

var places = rsp["places"];
var count_places = places.length;

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

var place = places[i];

var name = place["wof:name"];

var lat = place["geom:latitude"];
var lon = place["geom:longitude"];

var coords = [ lon, lat ];

var geom = {
"type": "Point",
"coordinates": coords,
};

var props = place;

var feature = {
"type": "Feature",
"geometry": geom,
"properties": props,
};

features.push(feature);
}

var feature_collection = {
"type": "FeatureCollection",
"features": features,
};

nearby_layer = mapzen.places.map.add_geojson_to_map(map, feature_collection);
};

mapzen.places.api.execute_method(method, args, function(rsp){
on_success(rsp);
});

if (nearby_layer){
nearby_layer.remove(map);
}
};

map.on("dragend", nearby);
map.on("zoomend", nearby);

nearby();
};

mapzen.places.map.draw_nearby_map("map", cb);
});
13 changes: 10 additions & 3 deletions www/javascript/mapzen.whosonfirst.api.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ mapzen.whosonfirst.api = (function(){

_api = new flamework.api();
_api.set_handler('endpoint', mapzen.whosonfirst.api.endpoint);
_api.set_handler('accesstoken', mapzen.whosonfirst.api.accesstoken);
_api.set_handler('authentication', mapzen.whosonfirst.api.authentication);
},

'call': function(method, data, on_success, on_error){
Expand All @@ -22,8 +22,15 @@ mapzen.whosonfirst.api = (function(){
return document.body.getAttribute("data-api-endpoint");
},

'accesstoken': function(){
return document.body.getAttribute("data-api-access-token");
'authentication': function(form_data){

var access_token = document.body.getAttribute("data-api-access-token");

if (! form_data.has("access_token")){
form_data.append("access_token", access_token);
}

return form_data;
}
}

Expand Down
26 changes: 26 additions & 0 deletions www/nearby.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

include("include/init.php");
loadlib("whosonfirst_places");

if ($id = get_int64("id")){

$place = whosonfirst_places_get_by_id($id);

if (! $place){
error_404();
}

$parent_id = $place["wof:parent_id"];

if ($parent_id != -1){
$parent = whosonfirst_places_get_by_id($parent_id);
$place["wof:parent"] = $parent;
}

$GLOBALS['smarty']->assign_by_ref("place", $place);
}

$GLOBALS['smarty']->display("page_nearby.txt", $place);
exit();
?>
Loading

0 comments on commit eb91882

Please sign in to comment.