Views.Map = Views.Base.extend({ classType: "Views.Map", tagName: "div", nowLoadingImage: "skins/default/images/nowLoadingSmall.gif", nowLoadingLabel: "", listenEvents: function() { //See Views.Base listenDefaultEvents() this.on("oninitialize", this.onInitialize); this.on("onrender", this.onRender); }, onInitialize: function() { if (edApplication().isgeolocalizationactivated) { if (!this.options.enablepreview) { this.options.enablepreview = false; } if (!this.options.geolocalizable.mustnotbegeolocalized) { this.options.geolocalizable.mustnotbegeolocalized = false; } if (!edApplication().googleMapsAPILoaded && !edApplication().googleMapsAPIInvalidKey) { var that = this; $(document).one("googleMapsAPI_loaded", function() { that.onRender(); }); Utils.loadGoogleMapAPI(); } else { this.onRender(); } } }, onRender: function() { if (!edApplication().googleMapsAPILoaded || edApplication().googleMapsAPIInvalidKey) { //console.log("onRender : api not loaded or invalid key"); this.$el.css("display", "none"); return; } if ((this.options.geolocalizable.latitude && this.options.geolocalizable.longitude) &&(this.options.geolocalizable.latitude != "1.4E-45" && this.options.geolocalizable.longitude != "1.4E-45")) { //console.log("onRender : valid coordinates so display map"); this.showGeolocalizationSuccess(); } else { // try to geocode once (to prevent asynchronous bean with reinitialized latitude and longitude after a saved and during the java geocoding process) if (!this.options.geolocalizable.mustnotbegeolocalized) { //in this case, ask the server for the latitude and longitude var url = "geolocalization_latitude_longitude.fl"; var data = {objid: this.options.geolocalizable.objId, objtype: this.options.geolocalizable.objType}; var that = this; $.ajax({ url: url , data: data, dataType: "json", context: this, success: function(data, textStatus, jqXHR) { if (!data.latitude) { that.showGeolocalizationFailed(); } else { that.options.geolocalizable.latitude = data.latitude; that.options.geolocalizable.longitude = data.longitude; that.showGeolocalizationSuccess(); } }, error: function(jqXHR, textStatus, errorThrown) { console.log("error :"); console.log("jqXHR :"); console.log(jqXHR); console.log("textStatus :"); console.log(textStatus); console.log("errorThrown :"); console.log(errorThrown); } }); /*if (edApplication().geocoder) { if (this.options.geolocalizable.address) { var that = this; edApplication().geocoder.geocode({'address': this.options.geolocalizable.address}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { that.options.geolocalizable.latitude = results[0].geometry.location.lat(); that.options.geolocalizable.longitude = results[0].geometry.location.lng(); that.showGeolocalizationSuccess(); } else { //console.log("onRender : geocode failed so display error"); that.showGeolocalizationFailed(); } }); } } else { //console.log("onRender : there is no geocoder so hide icon"); this.$el.css("display", "none"); }*/ } else { //console.log("onRender : this address has already been geolocalized in java and it failed"); this.showGeolocalizationFailed(); } } }, showGeolocalizationFailed: function() { this.$el.off("mouseenter"); this.$el.off("click"); $("a", this.$el).off("click"); this.options.edtooltip = {}; this.options.edtooltip.show = {}; this.options.edtooltip.show.delay = 0; this.options.edtooltip.content = {}; this.options.edtooltip.content.text = edApplication().labels.GEOLOCFAILED; this.createToolTip(); this.off("ontooltipshow"); this.$el.css("display", ""); }, showGeolocalizationSuccess: function() { if (this.options.geolocalizable.objId) { if (this.options.geolocalizable.objType) { var that = this; this.$el.on("click", function() { //window.open("./display_map.fl?id=" + that.options.geolocalizable.objId + "&objtype=" + that.options.geolocalizable.objType.toLowerCase(), // 'Map', 'width=1024, height=768, top=' + (($(window).height() / 2) - (768/2)) + ' left=' + (($(window).width() / 2) - (1024/2)) + ' menubar=no, status=no, toolbar=no, scrollbars=yes, resizable=no'); }); } } if (this.options.enablepreview) { this.options.edtooltip = {}; this.options.edtooltip.content = '
'; this.options.edtooltip.hide = {}; this.createToolTip(); this.on("ontooltipshow", function(event) { var that = this; setTimeout( function() { that.loadMapContent(); }, 500); }); if (this.options.isreadonly) { this._originalCSS = this._originalCSS + " withTooltip"; } } this.$el.css("display", ""); }, loadMapContent: function() { var view = this; //Create Point var point = new google.maps.LatLng(view.options.geolocalizable.latitude, view.options.geolocalizable.longitude); //Create Map var optionsCarte = { zoom: 17, //0 - 19 center: point, mapTypeId: google.maps.MapTypeId.ROADMAP, disableDefaultUI: false, navigationControl: false, mapTypeControl: true, scaleControl: false }; var gMap = new google.maps.Map(document.getElementById("previewmap_" + view.id), optionsCarte); //Create Image var imageMarker = new google.maps.MarkerImage(edApplication().getImagePath() + "maps/InitialPoint.png", new google.maps.Size(32, 32), new google.maps.Point(0, 0), new google.maps.Point(16, 32) ); //Create Marker var marker = new google.maps.Marker({ position: point, map: gMap, icon: imageMarker }); view.off("ontooltipshow"); }, updateAddressForGeolocalization: function(newAddress) { this.options.geolocalizable.address = newAddress; this.options.geolocalizable.latitude = null; this.options.geolocalizable.longitude = null; this.onRender(); } }); Views.MapList = Views.BaseList.extend({ classType: "VIEWS.MAPLIST" });