MQA.Nominatim: how do you pass various information to multiple MQA.Nominatim.constructPOI callbacks?

I am using the mapquest MQA.Nominatim module to geocode addresses inside my java script code. I would like to pass additional information to the MQA.Nominatim.constructPOI callback function.
This information should be different for each geolocation.
I use javascript closure to encapsulate data in each callback function (this works as desired in the Google api geocoding).
MQA.Nominatim always names the last installed callback function. By assumption, MQA.Nominatim.constructPOI is some kind of pointer to a global address.
Thus, I get all the flags and additional information that looks the same for all locations on the map.
Any ideas how to solve this?

My code looks like this:

<html>
<head>
    <script src="http://open.mapquestapi.com/sdk/js/v7.0.s/mqa.toolkit.js?key=xxxxxxx"></script>

    <script type="text/javascript">

        var flags = ['icons/flag_green.png', 'icons/flag_red.png'];

        var addressArr = [
     [', 49084 Osnabrueck, Germany','R','/trac/start/ticket/6677','Repair #6677'],
     [', 39599 Uchtspringe, Germany','R','/trac/start/ticket/6670','Repair #6670'],
     [', 17491 Greifswald, Germany','I','/trac/start/ticket/6625','Install #6625'],
     [', 37269 Eschwege, Germany','R','/trac/start/ticket/6620','Repair #6620'],
     [', 57076 Siegen, Germany','R','/trac/start/ticket/6602','Repair #6602'],
     [', 3109 St Poelten, Germany','I','/trac/start/ticket/6598','Install #6598'],
     [', 45884 Gelsenkirchen, Austria','R','/trac/start/ticket/6594','Repair #6594'],
     [', 48653 Coesfeld, Germany','R','/trac/start/ticket/6588','Repair #6588']
        ];

     function locationsCallback (location, osmLocation) {
            var type = location[1];
            var url = location[2];
            var title = location[3];
            var image = flags[0];
            if ('R' == type)
                  image = flags[1];

            /*Override the custom POI generation*/
            var lat = osmLocation.lat;
            var lng = osmLocation.lon;
            var p = new MQA.Poi({
               lat : lat,
               lng : lng
            });
            var customIcon = new MQA.Icon(image, 20, 29);
            p.setIcon(customIcon);

            /*Override the custom text populating the InfoWindow content*/
            p.setRolloverContent('<div style="font-size:14px;">' + title + '</div>');
            p.setInfoContentHTML('<div style="font-size:14px; width:180px;">' + url + '</div>');
            return p;
        };

        // define a function wich does the actual work of the callback and a func
        function setMarker (location) {
            MQA.Nominatim.constructPOI = function (osmLocation) {
                var callbackLoc = location;
                return locationsCallback(callbackLoc, osmLocation);
            };

            /*Executes a Nominatim search and adds the result to the map*/
            map.nominatimSearchAndAddLocation(location[0], null);
        }

       function setMarkers () {
           for (var i = 0; i < addressArr.length; i++) {
                var thisLoc = addressArr[i];
                // alert("Iteration: " + i + "   Geocode: " + location);

                /*This uses the MQA.withModule support to download and initialize the Nominatim support module. The constructPOI
                method is called to override the default behavior of constructing a POI.*/
                setMarker(thisLoc);
            }

       }
        function initialize() {

            /*Create an object for options*/
            var options = {
               elt : document.getElementById('map'), /*ID of element on the page where you want the map added*/
               zoom : 11, /*initial zoom level of map*/
               latLng: { lat:50.202250, lng:10.079730 },    /*center of the map is Bad Kissingen*/
               mtype:'osm',                                 /*map type (osm)*/
               bestFitMargin: 0,                            /*margin offset from the map viewport when applying a bestfit on shapes*/
               zoomOnDoubleClick: true                      /*zoom in when double-clicking on map*/
            };

            /*Construct an instance of MQA.TileMap with the options object*/
            window.map = new MQA.TileMap(options);

            /*This uses the MQA.withModule support to download and initialize the Nominatim support module. The constructPOI
              method is called to override the default behavior of constructing a POI.*/
            MQA.withModule('nominatim', setMarkers);
        };

        MQA.EventUtil.observe(window, 'load', initialize);

    </script>
</head>

<body>
    <div id='map' style='width:100%; height:750px;'></div>
</body>

+4

Source: https://habr.com/ru/post/1538055/


All Articles