Maps Areas modification to lat lng instead of lng lat

Hi all,

I’m hoping to send out emails with links to static Google Maps showing the delivery areas for our paper rounds. However sadly the Maps-Areas module stores the coordinates as “Longitude, Latitude, Elevation” instead of the more conventional “Latitude, Longitude” required by the Google API.

Instead of giving up, I dipped into the code, and found that with the following modification I could create a second field with the corrected format. This should allow me to pass this to a URL to generate the map. Hurray!

From row 219 of /modules/jjwg_Areas/views/view.area_edit_map.php

        // Define polygon(s) coordinates as lng,lat,elv string and set to 'coordinates' field
    $('#showData').click(function() {

        $('#dataPanel').empty();
        var myCoords = Array();
        var myDataString = '';
        var myDataString2 = '';

        for (var i=0; i<myAreaPolygon.length; i++) {
            var polygon = myAreaPolygon[i];
            if (polygon != '') {
                myCoords = polygon.getPath().getArray();
                if (myCoords.length > 1) {
                    for (var j=0; j<myCoords.length; j++) {
                        var myCoord = myCoords[j];
                        // Return format: lng,lat,elv
                        // Reduce percision to 8 after decimal and trim zeros
                        var lng = myCoord.lng().toFixed(8).replace(/0+$/g, "");
                        var lat = myCoord.lat().toFixed(8).replace(/0+$/g, "");
                        myDataString += lng + ',' + lat + ',0 ';
                        myDataString2 += lat + ',' + lng + '|';
                    }
                    myDataString = myDataString.replace(/^\s+|\s+$/g,"");
                    myDataString2 = myDataString2.replace(/^\s+\s+$/g,"");
                    myDataString += "\n\n";
                    myDataString2 += "\n\n";
                }
            }
        }

        // Update Coordinates display
        myDataString = myDataString.replace(/^[\s\n\r]+|[\s\n\r]+$/g,"");
        $('#dataPanel').append(myDataString.replace(/[\n\r]/g,"<br />"));
        // Update parent form 'coordinates' field
        parent.document.getElementById('coordinates').value = myDataString;
        parent.document.getElementById('latlngcoordinates_c').value = myDataString2;

    });

However, I’m a complete n00b at this, so I’ve got a couple of queries:

To what extent is my modification “upgrade safe”? Do I need to do something special to ensure my changes aren’t overwritten later?

How come the text is overspilling its TextArea box?

@menness

Your code will broke after upgrade. You should move the file into custom directory:

  • custom/modules/jjwg_Areas/views/view.area_edit_map.php

The file can be make as a children class for the file from system area.

Your string doesn’t have space character.