[freeside-commits] branch FREESIDE_3_BRANCH updated. 20319dfaa1c0f3ca4dc4c9685e3582154dcce517

Christopher Burger burgerc at freeside.biz
Fri Nov 16 10:02:58 PST 2018


The branch, FREESIDE_3_BRANCH has been updated
       via  20319dfaa1c0f3ca4dc4c9685e3582154dcce517 (commit)
       via  7bfcb1a73569815632cd7606c3d485234c21232e (commit)
      from  d34861c4d32675dac5f0405f078adddb35d4c863 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 20319dfaa1c0f3ca4dc4c9685e3582154dcce517
Author: Christopher Burger <burgerc at freeside.biz>
Date:   Fri Nov 16 11:14:32 2018 -0500

    RT# 81730 - added code to fix possible cross origin request error

diff --git a/httemplate/misc/openmap.html b/httemplate/misc/openmap.html
index 7cbe3db1d..88f64c1ff 100644
--- a/httemplate/misc/openmap.html
+++ b/httemplate/misc/openmap.html
@@ -18,7 +18,7 @@
 
   <script>
 
-    var url = 'http://nominatim.openstreetmap.org/search?format=json&limit=1&q=<%$loc%>';
+    var url = 'xmlhttp-openstreetmap.html?loc=<%$loc%>';
     $.getJSON(url,function(data){
       var latlong = [data[0].lat, data[0].lon];
       var mymap = L.map('mapid').setView(latlong, 15);
diff --git a/httemplate/misc/xmlhttp-openstreetmap.html b/httemplate/misc/xmlhttp-openstreetmap.html
new file mode 100644
index 000000000..bf6625c93
--- /dev/null
+++ b/httemplate/misc/xmlhttp-openstreetmap.html
@@ -0,0 +1,15 @@
+<% $return %>\
+<%init>
+
+my $DEBUG = 0;
+
+my $conf = new FS::Conf;
+
+my $return = {};
+
+my $url = "http://nominatim.openstreetmap.org/search?format=json&limit=1&q=" . $cgi->param('loc');
+
+use LWP::Simple;
+my $return = get $url;
+
+</%init>
\ No newline at end of file

commit 7bfcb1a73569815632cd7606c3d485234c21232e
Author: Christopher Burger <burgerc at freeside.biz>
Date:   Fri Nov 16 09:09:13 2018 -0500

    RT# 81730 - fixed XMLHttpRequest async issue, and fixed changed .gov api link.

diff --git a/httemplate/misc/openmap.html b/httemplate/misc/openmap.html
index 73f107142..7cbe3db1d 100644
--- a/httemplate/misc/openmap.html
+++ b/httemplate/misc/openmap.html
@@ -11,50 +11,45 @@
      <input type=hidden id="censustract" value="">
    </td>
    <td>
-     <div id="mapid" style="width: 600px; height: 600px;"></div>
+     <div id="mapid" style="width: 600px; height: 600px;">Retrieving Map.</div>
    </td>
   </tr>
  </table>
 
   <script>
-    var mymap = L.map('mapid').setView(getLatLong('<%$loc%>'), 15);
-    var popup = L.popup();
-    var mainLayer = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
-    	 maxZoom: 19,
-	 attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
-    }).addTo(mymap);
-    var markersLayer = new L.LayerGroup();
-    mymap.addLayer(markersLayer);
 
-    function onMapClick(e) {
-      markersLayer.clearLayers();
-      var marker = L.marker([e.latlng.lat, e.latlng.lng]);
-      marker.bindPopup("You selected (" + e.latlng.lat + " , " + e.latlng.lng + ")").openPopup();
-      markersLayer.addLayer(marker);
-      getCensusTract(e.latlng.lat, e.latlng.lng);
-    }
+    var url = 'http://nominatim.openstreetmap.org/search?format=json&limit=1&q=<%$loc%>';
+    $.getJSON(url,function(data){
+      var latlong = [data[0].lat, data[0].lon];
+      var mymap = L.map('mapid').setView(latlong, 15);
+      var popup = L.popup();
+      var mainLayer = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
+        maxZoom: 19,
+        attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
+      }).addTo(mymap);
+      var markersLayer = new L.LayerGroup();
+      mymap.addLayer(markersLayer);
 
-    mymap.on('click', onMapClick);
+      function onMapClick(e) {
+       markersLayer.clearLayers();
+       var marker = L.marker([e.latlng.lat, e.latlng.lng]);
+       marker.bindPopup("You selected (" + e.latlng.lat + " , " + e.latlng.lng + ")").openPopup();
+       markersLayer.addLayer(marker);
+       document.getElementById("mycensustract").innerHTML = "Retrieving census tract...";
+       getCensusTract(e.latlng.lat, e.latlng.lng);
+      }
 
-    function Get(yourUrl){
-      var Httpreq = new XMLHttpRequest(); // a new request
-      Httpreq.open("GET",yourUrl,false);
-      Httpreq.send();
-      return Httpreq.responseText;          
-    }
+      mymap.on('click', onMapClick);
 
-    function getLatLong(loc) {
-    	 var url = 'http://nominatim.openstreetmap.org/search?format=json&limit=1&q=' + loc;
-    	 var json_obj = JSON.parse(Get(url));
-    	 return [json_obj[0].lat, json_obj[0].lon];
-    }
+      function getCensusTract(lat, lon) {
+       var url = 'xmlhttp-censustract.html?lat=' + lat + '&lon=' + lon + '&census_year=<%$census_year%>';
+       $.getJSON(url,function(data){
+         var tract = (data.Block.FIPS.substr(0, 11) / 100).toFixed(2);
+         document.getElementById("mycensustract").innerHTML = tract;
+       });
+      }
 
-    function getCensusTract(lat, lon) {
-    	 var url = 'xmlhttp-censustract.html?lat=' + lat + '&lon=' + lon + '&census_year=<%$census_year%>';
-    	 var json_obj = JSON.parse(Get(url));
-    	 var tract = (json_obj.Block.FIPS.substr(0, 11) / 100).toFixed(2);
-    	 document.getElementById("mycensustract").innerHTML = tract;
-    }
+    });
 
     function changeMainDiv(lat,lng) {
           window.opener.document.getElementById("newcensustract").innerHTML = document.getElementById("mycensustract").innerHTML;
diff --git a/httemplate/misc/xmlhttp-censustract.html b/httemplate/misc/xmlhttp-censustract.html
index 8a7686047..985fb90e5 100644
--- a/httemplate/misc/xmlhttp-censustract.html
+++ b/httemplate/misc/xmlhttp-censustract.html
@@ -6,7 +6,9 @@ my $DEBUG = 0;
 my $conf = new FS::Conf;
 
 my $return = {};
-my $url = "http://data.fcc.gov/api/block/find?format=json&censusYear=" . $cgi->param('census_year') . "&latitude=" . $cgi->param('lat') . "&longitude=" . $cgi->param('lon');
+
+## new api link, see doc https://geo.fcc.gov/api/census/
+my $url = "https://geo.fcc.gov/api/census/block/find?format=json&censusYear=" . $cgi->param('census_year') . "&latitude=" . $cgi->param('lat') . "&longitude=" . $cgi->param('lon');
 
 use LWP::Simple;
 my $return = get $url;

-----------------------------------------------------------------------

Summary of changes:
 httemplate/misc/openmap.html               | 63 ++++++++++++++----------------
 httemplate/misc/xmlhttp-censustract.html   |  4 +-
 httemplate/misc/xmlhttp-openstreetmap.html | 15 +++++++
 3 files changed, 47 insertions(+), 35 deletions(-)
 create mode 100644 httemplate/misc/xmlhttp-openstreetmap.html




More information about the freeside-commits mailing list