web/data/cubicweb.gmap.js
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 23 Sep 2011 12:16:29 +0200
branchstable
changeset 7855 54283a5b7afc
parent 5774 0d792bceb25d
child 8154 151058945234
permissions -rw-r--r--
[web request] fix cookie 'expires' formating (closes #1953945) This was because cookie.expires wasn't processed in cw.etwist.http, though this code should had never existed, instead proper twisted method should be called. Also, move on the way to headers handling simplification and rewrite cw request.set_cookie / remove_cookie to directly use the Cookie class in cw.web.http_headers rather than going back and forth simple cookie <-> raw string <-> http_headers.Cookie IMO more on this should be done.

/**
 *  :organization: Logilab
 *  :copyright: 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 *  :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
 */

Widgets.GMapWidget = defclass('GMapWidget', null, {
    __init__: function(wdgnode) {
        // Assume we have imported google maps JS
        if (GBrowserIsCompatible()) {
            var uselabelstr = wdgnode.getAttribute('cubicweb:uselabel');
            var uselabel = true;
            if (uselabelstr) {
                if (uselabelstr == 'True') {
                    uselabel = true;
                }
                else {
                    uselabel = false;
                }
            }
            var map = new GMap2(wdgnode);
            map.addControl(new GSmallMapControl());
            var jsonurl = wdgnode.getAttribute('cubicweb:loadurl');
            var self = this; // bind this to a local variable
            jQuery.getJSON(jsonurl, function(geodata) {
                if (geodata.center) {
                    var zoomLevel = geodata.zoomlevel;
                    map.setCenter(new GLatLng(geodata.center.latitude, geodata.center.longitude), zoomLevel);
                }
                for (var i = 0; i < geodata.markers.length; i++) {
                    var marker = geodata.markers[i];
                    self.createMarker(map, marker, i + 1, uselabel);
                }
            });
            jQuery(wdgnode).after(this.legendBox);
        } else { // incompatible browser
            jQuery.unload(GUnload);
        }
    },

    createMarker: function(map, marker, i, uselabel) {
        var point = new GLatLng(marker.latitude, marker.longitude);
        var icon = new GIcon();
        icon.image = marker.icon[0];
        icon.iconSize = new GSize(marker.icon[1][0], marker.icon[1][1]);
        icon.iconAnchor = new GPoint(marker.icon[2][0], marker.icon[2][1]);
        if (marker.icon[3]) {
            icon.shadow4 = marker.icon[3];
        }
        if (typeof LabeledMarker == "undefined") {
            var gmarker = new GMarker(point, {
                icon: icon,
                title: marker.title
            });
        } else {
            var gmarker = new LabeledMarker(point, {
                icon: icon,
                title: marker.title,
                labelText: uselabel ? '<strong>' + i + '</strong>': '',
                labelOffset: new GSize(2, - 32)
            });
        }
        map.addOverlay(gmarker);
        GEvent.addListener(gmarker, 'click', function() {
            jQuery.post(marker.bubbleUrl, function(data) {
                map.openInfoWindowHtml(point, data);
            });
        });
    }

});