PageSourceSearch

https://www.merri-bek.vic.gov.au/site.resource.main/js/mapping/mapping-address-search-four-bins.js

js merri-bek.vic.gov.au collected 2026-09-24 21:25:45 UTC 14,616 bytes, 315 lines download raw bytes

1
2var autocompleteData = "";
3var selectedAddress = false;
4var setfirstAddress = false;
5var tryAutoAddress = false;
6var zeroResults = false;
7function mccAddressSearch(url, field) {
8
9    var addressField = $('#'+field);
10                addressField.autocomplete({
11            source:    function (request, response) {
12                    $.ajax({
13                        url: url + "/query/",
14                        dataType: "jsonp",
15                        data: {
16                            where: "EZI_Address LIKE '" + getSmartAddress(request.term.replace(/\'/g, '\'\'')) + "%'",//makes single quotes into double for sql  
17                            outFields: "EZI_Address,Waste_Rate_Code,Recycling_Rate_Code,FOGO_Rate_Code,Glass_Rate_Code,Day,Zone,GlassWeek",
18                            returnGeometry: true,
19                            f: "pjson"
20                        },
21                        success: function (data) {
22                            if (data.features) {
23                                // response($.map(data.features.slice(0, 9), function (item) {//only display first 10  
24                                //  return { label: item.attributes.EZI_ADD, value: item.attributes.EZI_ADD }
25                                //}));
26                                response($.map(data.features.slice(0, 6), function (item) {
27
28                                     
29
30
31                                    return {
32                                        label: item.attributes.EZI_Address,
33                                        x: item.geometry.x,
34                                        y: item.geometry.y,
35                                        Day: item.attributes.Day,
36                                        Zone: item.attributes.Zone,
37                                        Waste_Rate_Code: item.attributes.Waste_Rate_Code,
38                                        Recycling_Rate_Code: item.attributes.Recycling_Rate_Code,
39                                        FOGO_Rate_Code: item.attributes.Recycling_Rate_Code,
40                                        Glass_Rate_Code: item.attributes.Glass_Rate_Code,
41                                        GlassWeek: item.attributes.GlassWeek
42                                    }
43
44
45                                }));
46
47
48
49
50                            }
51                        }
52                    });
53                },
54                select: function (event, ui) {
55                    //event.preventDefault();
56
57                   
58                    setFormFields(ui.item);
59                    // this function allows callers to this address search to apply a different outcome.
60                    //if (autoSubmit) {
61            
62                    //}
63                    //selectedAddressReturnAll();
64
65         
66                },
67         
68                minLength: 2,
69                classes: {
70                    'ui-autocomplete': 'ui-autocomplete in-my-area__autocomplete',
71                },
72                open: () => {
73                    addressField.addClass('has-autocomplete');
74                },
75                close: () => {
76                    addressField.removeClass('has-autocomplete');
77                }
78            });
79}    
80
81
82 
83
84function getSmartAddress(address) {
85
86    var streetPatterns = [
87        // Full Street Extension
88        // See below for Street, Drive and Lane
89         [/\b\,/gi, '/'],
90       
91        [/^[\W]*?unit\s{1,}(([0-9]{0,})([\w]?))[\s{0,}]?([\/||-||,]{0,}?)[\s{0,}]?([0-9]{0,})\.?/gi, '$2$4/$5'],
92      
93        [/\b\s?\/\/?\s?/gi, '/'],
94        [/^[\W]*([0-9]{1,})([/|,]?)([\w]{0,})([\s]?)([\w]{1,})[\s]{1,}st[\s]{1,}([\sa-zA-Z0-9]{0,})$/gi, '$1$2$3$4$5 STREET $6'],
95         [/^[\W]*([0-9]{1,})([/|,]?)([\w]{0,})([\s]?)([\w]{1,})[\s]{1,}rd[\s]{1,}([\sa-zA-Z0-9]{0,})$/gi, '$1$2$3$4$5 Road $6'],
96         [/^[\W]*([0-9]{1,})([/|,]?)([\w]{0,})([\s]?)([\w]{1,})[\s]{1,}fr?wy[\s]{1,}([\sa-zA-Z0-9]{0,})$/gi, '$1$2$3$4$5 FREEWAY $6'],
97         [/^[\W]*([0-9]{1,})([/|,]?)([\w]{0,})([\s]?)([\w]{1,})[\s]{1,}bl(vd)[\s]{1,}([\sa-zA-Z0-9]{0,})$/gi, '$1$2$3$4$5 Boulevard $6'],
98         [/^[\W]*([0-9]{1,})([/|,]?)([\w]{0,})([\s]?)([\w]{1,})[\s]{1,}te?rr?[\s]{1,}([\sa-zA-Z0-9]{0,})$/gi, '$1$2$3$4$5 Terrace $6'],
99         [/^[\W]*([0-9]{1,})([/|,]?)([\w]{0,})([\s]?)([\w]{1,})[\s]{1,}tce[\s]{1,}([\sa-zA-Z0-9]{0,})$/gi, '$1$2$3$4$5 Terrace $6 '],
100         [/^[\W]*([0-9]{1,})([/|,]?)([\w]{0,})([\s]?)([\w]{1,})[\s]{1,}pk[\s]{1,}([\sa-zA-Z0-9]{0,})$/gi, '$1$2$3$4$5 Park $6'],
101         [/^[\W]*([0-9]{1,})([/|,]?)([\w]{0,})([\s]?)([\w]{1,})[\s]{1,}plz[\s]{1,}([\sa-zA-Z0-9]{0,})$/gi, '$1$2$3$4$5 Plaza $6'],
102         [/^[\W]*([0-9]{1,})([/|,]?)([\w]{0,})([\s]?)([\w]{1,})[\s]{1,}pl[\s]{1,}([\sa-zA-Z0-9]{0,})$/gi, '$1$2$3$4$5 Place $6'],
103         [/^[\W]*([0-9]{1,})([/|,]?)([\w]{0,})([\s]?)([\w]{1,})[\s]{1,}ln[\s]{1,}([\sa-zA-Z0-9]{0,})$/gi, '$1$2$3$4$5 Lane $6'],
104         [/^[\W]*([0-9]{1,})([/|,]?)([\w]{0,})([\s]?)([\w]{1,})[\s]{1,}cir[\s]{1,}([\sa-zA-Z0-9]{0,})$/gi, '$1$2$3$4$5 Circle $6'],
105         [/^[\W]*([0-9]{1,})([/|,]?)([\w]{0,})([\s]?)([\w]{1,})[\s]{1,}ct|crt[\s]{1,}([\sa-zA-Z0-9]{0,})$/gi, '$1$2$3$4$5 Court $6'],
106         [/^[\W]*([0-9]{1,})([/|,]?)([\w]{0,})([\s]?)([\w]{1,})[\s]{1,}cl[\s]{1,}([\sa-zA-Z0-9]{0,})$/gi, '$1$2$3$4$5 Close $6'],
107         [/^[\W]*([0-9]{1,})([/|,]?)([\w]{0,})([\s]?)([\w]{1,})[\s]{1,}sq[\s]{1,}([\sa-zA-Z0-9]{0,})$/gi, '$1$2$3$4$5 Square $6'],
108         [/^[\W]*([0-9]{1,})([/|,]?)([\w]{0,})([\s]?)([\w]{1,})[\s]{1,}cr[\s]{1,}([\sa-zA-Z0-9]{0,})$/gi, '$1$2$3$4$5 Crescent $6'],
109         [/^[\W]*([0-9]{1,})([/|,]?)([\w]{0,})([\s]?)([\w]{1,})[\s]{1,}dr[\s]{1,}([\sa-zA-Z0-9]{0,})$/gi, '$1$2$3$4$5 Drive $6'],
110         [/^[\W]*([0-9]{1,})([/|,]?)([\w]{0,})([\s]?)([\w]{1,})[\s]{1,}drv[\s]{1,}([\sa-zA-Z0-9]{0,})$/gi, '$1$2$3$4$5 Drive $6'],
111         [/^[\W]*([0-9]{1,})([/|,]?)([\w]{0,})([\s]?)([\w]{1,})[\s]{1,}dve[\s]{1,}([\sa-zA-Z0-9]{0,})$/gi, '$1$2$3$4$5 Drive $6'],
112         [/^[\W]*([0-9]{1,})([/|,]?)([\w]{0,})([\s]?)([\w]{1,})[\s]{1,}GDNS[\s]{1,}([\sa-zA-Z0-9]{0,})$/gi, '$1$2$3$4$5 Gardens $6'],
113         [/^[\W]*([0-9]{1,})([/|,]?)([\w]{0,})([\s]?)([\w]{1,})[\s]{1,}GR[\s]{1,}([\sa-zA-Z0-9]{0,})$/gi, '$1$2$3$4$5 Grove $6'],
114         [/^[\W]*([0-9]{1,})([/|,]?)([\w]{0,})([\s]?)([\w]{1,})[\s]{1,}lne[\s]{1,}([\sa-zA-Z0-9]{0,})$/gi, '$1$2$3$4$5 Lane $6'],
115         [/^[\W]*([0-9]{1,})([/|,]?)([\w]{0,})([\s]?)([\w]{1,})[\s]{1,}wy[\s]{1,}([\sa-zA-Z0-9]{0,})$/gi, '$1$2$3$4$5 Way $6'],
116         [/^[\W]*([0-9]{1,})([/|,]?)([\w]{0,})([\s]?)([\w]{1,})[\s]{1,}aly[\s]{1,}([\sa-zA-Z0-9]{0,})$/gi, '$1$2$3$4$5 Alley $6'],
117         [/^[\W]*([0-9]{1,})([/|,]?)([\w]{0,})([\s]?)([\w]{1,})[\s]{1,}ave[\s]{1,}([\sa-zA-Z0-9]{0,})$/gi, '$1$2$3$4$5 Avenue $6'],
118         [/^[\W]*([0-9]{1,})([/|,]?)([\w]{0,})([\s]?)([\w]{1,})[\s]{1,}
118lnk[\s]{1,}([\sa-zA-Z0-9]{0,})$/gi, '$1$2$3$4$5 LINK $6'],
119         [/^[\W]*([0-9]{1,})([/|,]?)([\w]{0,})([\s]?)([\w]{1,})[\s]{1,}pde[\s]{1,}([\sa-zA-Z0-9]{0,})$/gi, '$1$2$3$4$5 PARADE $6'],
120         [/^[\W]*([0-9]{1,})([/|,]?)([\w]{0,})([\s]?)([\w]{1,})[\s]{1,}trl[\s]{1,}([\sa-zA-Z0-9]{0,})$/gi, '$1$2$3$4$5 TRAIL $6'],
121         [/^[\W]*([0-9]{1,})([/|,]?)([\w]{0,})([\s]?)([\w]{1,})[\s]{1,}wkwy[\s]{1,}([\sa-zA-Z0-9]{0,})$/gi, '$1$2$3$4$5 WALKWAY $6'],
122         [/^[\W]*([0-9]{1,})([/|,]?)([\w]{0,})([\s]?)([\w]{1,})[\s]{1,}wkwy[\s]{1,}([\sa-zA-Z0-9]{0,})$/gi, '$1$2$3$4$5 WALKWAY $6'],
123	 [/^[\W]*([0-9]{1,})[\s]{1,}street[\s]{1}([\sa-zA-Z0-9]{0,})$/gi, '$1 ST $2'],
124
125 
126         [/^[\W]*un?i?t?([\s]{0,})([\w]{0,})/gi, ''],
127        [/^[\W]*([\/]{0,})/gi, ''],
128        [/\b\/\//gi, '/'],
129        [/[^a-zA-Z0-9\- \/\,]/gi, '']
130    ];
131
132    var tempAddress = address;
133    for (var i in streetPatterns) {
134        address = address.replace(streetPatterns[i][0], streetPatterns[i][1]);
135       
136    }
137    // if the address changed we are correcting data do not do wild search
138    if (tempAddress !== address) {
139       // zeroResults = false;
140    }
141   
142    return address;
143}
144function searchAgain(domSelectedAddress) {
145    $("#" + domSelectedAddress + "Suggestions").hide();
146    $("#address").val("").focus();
147}
148
149function searchAddressSubmit() {
150        $("#selectedAddressSuggestions").hide();
151    autoPost = true;
152    //$('#address').autocomplete('search');
153    $(".ui-menu-item").hide();
154
155}
156
157function setAddressAutoComplete(obj) {
158
159    $("#address").val(obj);
160    $("#address").autocomplete("search");
161  autoPost = true;
162
163}
164
165function selectedAddressReturnAll() {
166
167    if ($("#address").val() === "") {
168        zeroResults = false;
169    }
170
171
172    $("#sAddress").val($("#address").val());
173    $("#address").prop('disabled', false);
174    if (autoPost) {
175       // autoPost = false;
176       // $("#autoform").submit();
177    }
178}
179
180var submitted = false;
181function selectedAddressSubmit() {
182
183    $("#address").autocomplete("search");
184   
185    // pass current address through filters
186    var parsedAddress = getSmartAddress($("#address").val());
187    var domSelectedAddress = "selectedAddress";
188    
189
190     if($(".ui-menu-item").length===0 && parsedAddress.lastIndexOf(" ")>10){autoPost = true;  $("#" + domSelectedAddress + "Suggestions").hide();
191         
192       setAddressAutoComplete(ucwords(parsedAddress));
193      // searchAddressSubmit();
194         return false;
195
196
197     }
198
199    $('#address').autocomplete("close");
200    $("#" + domSelectedAddress + "Suggestions").show();
201         $("#" + domSelectedAddress + "Suggestions").empty();
202         $("#" + domSelectedAddress + "Suggestions").html("<strong><span class='noAddress'>Sorry we can't find that address. Please try again.</span></strong>");
203    if ($(".ui-menu-item").length > 0) {
204       
205             $("#" + domSelectedAddress + "Suggestions").empty();
206        $("#" + domSelectedAddress + "Suggestions").show();
207        $("<div class='margin-top-bottom-3'><strong>Did you mean?</strong></div><ul id='autoSuggest'></ul>").appendTo("#" + domSelectedAddress + "Suggestions");
208        $(".ui-menu-item").each(function(index) {
209            if (ucwords($(this).text()).toUpperCase() === ucwords(parsedAddress).toUpperCase()) {
210                    $("#" + domSelectedAddress + "Suggestions").hide();
211                        $("#sAddress").val(parsedAddress);
212                                        $("#address").val(parsedAddress);
213                //$("#autoform").submit();
214                
215                if($(".ui-menu-item").length===1){autoPost = true;  $("#" + domSelectedAddress + "Suggestions").hide();
216                  setAddressAutoComplete(ucwords($(this).text()));
217                 // searchAddressSubmit();
218                    
219           
220                    }
221            }
222            $("<li><a href='#' onclick=\"$('#'+"+ domSelectedAddress + "+'Suggestions').empty();setAddressAutoComplete('" + ucwords($(this).text()) + "');searchAddressSubmit();\">" + ucwords($(this).text()) + "</a></li>").appendTo("#autoSuggest");
223
224        });
225        $("<li><a href='#' onclick=\"searchAgain('" + domSelectedAddress + "')\">Search again</td></li>").appendTo("#autoSuggest");
226    }
227    $(".ui-menu-item").hide();
228
229  return false;
230}
231
232
233function requestGeoLocation() {
234
235    if (navigator.geolocation && !tryAutoAddress) {
236        navigator.geolocation.getCurrentPosition(function(position) {
237            // Add vicmap gd94
238            Proj4js.defs["EPSG:28355"] = "+proj=utm +zone=55 +south +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs";
239
240            var proj_wgs84 = new OpenLayers.Projection("EPSG:4326");
241            var proj_28355 = new OpenLayers.Projection("EPSG:28355");
242            var point = new OpenLayers.LonLat(position.coords.longitude, position.coords.latitude);
243            // transform to map native projection
244            var new_point = point.clone().transform(proj_wgs84, proj_28355);
245
246            // find the closest point within 10 metres we will take the first so it doesn't matter if it gets more than one.
247            $.ajax({
248                url: "https://geo.moreland.vic.gov.au/geoserver/Moreland/ows",
249                dataType: "jsonp",
250                data: {
251                    typename: "Moreland:Address",
252                    propertyName: "EZI_ADD,the_geom,COL_DAY,PROPNUM,WARD,GRN_WASTE,SUBURB,Intdescr,Ratetype",
253                    outputFormat: "text/javascript",
254                    service: "wfs",
255                    version: "1.0.0",
256                    request: "GetFeature",
257                    maxFeatures: 1,
258                    cql_filter: "DWITHIN(the_geom,POINT(" + new_point.lon + " " + new_point.lat + "),100,meters)"
259                },
260                jsonp: "false",
261                jsonpCallback: "parseResponse",
262                success: function(data) {
263
264
265                    //$("#address").autocomplete("search");
266                    if (data.features[0].properties["EZI_ADD"] !== '' && $("#propNum").val() == '') {
267                        $("#address").val(data.features[0].properties["EZI_ADD"]);
268                    }
269                }
270            });
271
272        }, function error(msg) {
273            ;
274
275        }, { maximumAge: 600000, timeout: 5000, enableHighAccuracy: true });
276    }
277}
278
279function ucwords(str) {
280    str = str.toLowerCase();
281    return str.replace(/(\b)([a-zA-Z])/g,
282        function(firstLetter) {
283            return firstLetter.toUpperCase();
284        });
285}
286
287function setFormFields(item) {
288   Proj4js.defs["ESPG:3857"] =  "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext  +no_defs";
289  Proj4js.defs["EPSG:28355"]="+proj=utm +zone=55 +south +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs";
290  var src = new OpenLayers.Projection('ESPG:3857');
291  var dest = new OpenLayers.Projection('EPSG:28355');
292 
293  var point = new OpenLayers.Geometry.Point(item.x, item.y).transform(src, dest);
294 
295    $("#sAddress").val(item.label);
296    $("#address").val(item.label);
297    $("#xPoint").val(point.x);
298    $("#yPoint").val(point.y);
299    $("#wasteDay").val(item.Day);
300    $("#zone").val(item.Zone);
301
302    $("#wasteRateCode").val(item.Waste_Rate_Code);
303
304    $("#recycleRateCode").val(item.Recycling_Rate_Code);
305    $("#fogoRateCode").val(item.FOGO_Rate_Code);
306    $("#glassRateCode").val(item.Glass_Rate_Code);
307    $("#glassWeekNumber").val(item.GlassWeek);
308  autoPost = true;
309}
310 
311
312
313function parseResponse(data) {
314    return data;
315}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.