Automatically exported from code.google.com/p/planningalerts
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

preview.php 3.1 KiB

18 år sedan
15 år sedan
15 år sedan
15 år sedan
18 år sedan
15 år sedan
18 år sedan
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. require_once ("config.php");
  3. require_once ("phpcoord.php");
  4. $preview_page = new preview_page;
  5. class preview_page {
  6. //Properties
  7. var $warnings = "";
  8. var $center_long = 0;
  9. var $center_lat = 0;
  10. var $bottom_left_long = 0;
  11. var $bottom_left_lat = 0;
  12. var $top_right_long = 0;
  13. var $top_right_lat = 0;
  14. //Constructor
  15. function preview_page() {
  16. $this->setup();
  17. $this->bind();
  18. }
  19. //setup
  20. function setup (){
  21. //Grab the postcode and area size from the get string
  22. if (!isset($_GET['postcode'])){
  23. $this->warnings .= "No postcode specified ";
  24. }
  25. if (!isset($_GET['area_size'])){
  26. $this->warnings .= "No area size specified ";
  27. }
  28. if ($this->warnings == ""){
  29. $url = "http://ernestmarples.com/?p=sw98jx&f=csv";
  30. $result = file_get_contents($url);
  31. $result = split(",", $result);
  32. if(count($result) != 2){
  33. trigger_error("No lat/long could be found");
  34. }
  35. $lat = $result[0];
  36. $lng = $result[1];
  37. //Get OS ref from postcode
  38. $xy = postcode_to_location($_GET['postcode']);
  39. //Get the centroid long / lat (google maps doesnt handle grid refs)
  40. //$os_ref = new OSRef($xy[0], $xy[1]);
  41. //$long_lat = $os_ref->toLatLng();
  42. $this->center_long = $lng; //$long_lat->lng;
  43. $this->center_lat = $lat; //$long_lat->lat;
  44. //get long lat for the bounding box (OS grid refs are in meters in case you were wondering)
  45. //bottom left
  46. $area_size_meters = alert_size_to_meters($_GET['area_size']);
  47. $os_ref = new OSRef($xy[0] - $area_size_meters, $xy[1] - $area_size_meters);
  48. $long_lat = $os_ref->toLatLng();
  49. $this->bottom_left_long = $long_lat->lng;
  50. $this->bottom_left_lat = $long_lat->lat;
  51. //top right
  52. $area_size_meters = alert_size_to_meters($_GET['area_size']);
  53. $os_ref = new OSRef($xy[0] + $area_size_meters, $xy[1] + $area_size_meters);
  54. $long_lat = $os_ref->toLatLng();
  55. $this->top_right_long = $long_lat->lng;
  56. $this->top_right_lat = $long_lat->lat;
  57. }
  58. }
  59. //Bind
  60. function bind () {
  61. //page vars
  62. $form_action = $_SERVER['PHP_SELF'];
  63. //smarty
  64. $smarty = new Smarty;
  65. $smarty->force_compile = true;
  66. $smarty->compile_dir = SMARTY_COMPILE_DIRECTORY;
  67. $smarty->assign("warnings", $this->warnings);
  68. $smarty->assign("center_long", $this->center_long);
  69. $smarty->assign("center_lat", $this->center_lat);
  70. $smarty->assign("bottom_left_long", $this->bottom_left_long);
  71. $smarty->assign("bottom_left_lat", $this->bottom_left_lat);
  72. $smarty->assign("top_right_long", $this->top_right_long);
  73. $smarty->assign("top_right_lat", $this->top_right_lat);
  74. $smarty->assign("warnings", $this->warnings);
  75. $smarty->assign("google_maps_key", GOOGLE_MAPS_KEY);
  76. //Render
  77. $smarty->display('preview.tpl');
  78. }
  79. }
  80. ?>