Edit C:\galaxie\Back\galaxie\sales\enterprise\map.jsp
<!-- DEPRECATED : use the generic map displayer instead webapps/edealCRM/common/maps/map.jsp --> <%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <% /****************************************************************************** * Copyright (c) 2000-2004 e-Deal * * e-Deal S.A. * 55 rue Brillat Savarin * 75013 Paris * France * * T: +33 (0)1 53 80 80 30 * F: +33 (0)1 73 01 69 77 * http://www.e-deal.com * * La diffusion de ce code source sous quelque forme que ce soit sans * l'autorisation de E-DEAL est interdite. * * Vous êtes autorisés à modifier ce code source uniquement pour votre usage * propre et sous réserve que les mentions de copyright demeurent intactes. * * Ce code est fourni en l'état. Aucune garantie d'aucune sorte, explicite ou * implicite n'est donnée. En aucun cas E-DEAL ne pourra être tenu pour * responsable des dommages pouvant résulter de l'utilisation de ce code * source. * * ******************************************************************************/ %><%@page session="true" import="com.edeal.frontline.*,java.util.*,java.net.*,java.io.*"%> <%@ page import="com.edeal.frontline.helper.BasicHelper"%> <%@ page import="com.edeal.frontline.helper.custom.ActorHelper"%> <%@taglib uri="http://www.e-deal.com/taglib/fl" prefix="fl" %> <% final org.apache.commons.logging.Log logger = org.apache.commons.logging.LogFactory.getLog(getClass()); String contextPath = (String) session.getAttribute("contextPath"); FlContext context = null; if (contextPath!=null) { context = Frontline.getContext(contextPath); } else { context = Frontline.getContext(request.getContextPath()); } DataDictionary dico = context.getDataDictionary(); String id = (String) request.getParameter("id"); String latitude =(String) request.getParameter("latitude"); String longitude=(String) request.getParameter("longitude"); EnterpriseBean entBean = new EnterpriseBean(id,context); String add1=null; String add2=null; String add3=null; String zip=null; String country=null; String countryStr=null; try { add1 = entBean.getEntAd1(); }catch (FieldNotInitializedException e){} try { add2 = entBean.getEntAd2(); }catch (FieldNotInitializedException e){} try { add3 = entBean.getEntAd3(); }catch (FieldNotInitializedException e){} try { zip = entBean.getEntZip(); }catch (FieldNotInitializedException e){} try { country = entBean.getEntCtrID(); countryStr=(String) dico.getRefDisp("EntCtrID", country); }catch (FieldNotInitializedException e){} float latitudeF=Float.parseFloat(latitude); float longitudeF=Float.parseFloat(longitude); float latitudeS=0; try { latitudeS =entBean.getEntLa(); } catch (FieldNotInitializedException e){} float longitudeS=0; try { longitudeS =entBean.getEntLa(); } catch (FieldNotInitializedException e){} if (latitudeS==0 && longitudeS==0){ try { entBean.setEntLa(latitudeF); entBean.setEntLo(longitudeF); entBean.save(); } catch(AccessDeniedException e){} } String address=""; if (add1 != null) { address+=add1+" "; } if (add2 != null) { address+=add2+" "; } if (add3 != null) { address+=add3+" "; } if (zip != null) { address+=zip+" "; } if (countryStr != null) { address+=countryStr; } String entAcronym = ""; try{ entAcronym = entBean.getEntAcronym(); }catch(FieldNotInitializedException e){} String entCorpName = ""; try{ entCorpName = entBean.getEntCorpName(); }catch(FieldNotInitializedException e){} int entTurnOver = 0; try{ entTurnOver = entBean.getEntTurnOver(); }catch(FieldNotInitializedException e){} String entPosID = ""; try{ entPosID = entBean.getEntPosID(); }catch(FieldNotInitializedException e){} String entPosition = (String)dico.getRefDisp(session,"entPosID", entPosID); String key=(String) context.getContextParameter("GoogleMapKey"); String html = (Utils.isEmpty(entAcronym)) ? entCorpName : entAcronym; String currency = BasicHelper.getContextParameter(context, "Grid.Currency", "�"); html += (!Utils.isEmpty(address)) ? "<BR/>" + address : ""; html += (entTurnOver > 0) ? "<BR/><img src=\"" + context.getContextName() + "/icons/ico/opportunite.gif\" style=\"vertical-align: bottom;\"/> " + entTurnOver + " " + currency : ""; html += (!Utils.isEmpty(entPosition)) ? "<BR/>" + entPosition : ""; html = Utils.formatToJavascript(html); ActorBean actor = ActorHelper.getSessionActor(session); ActorHelper actorHelper = new ActorHelper(actor); String actorAddress = actorHelper.getActorAddress(); %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> <title>Google Maps Multi-Point Routing</title> <link rel="stylesheet" href="<fl:webapp/>/css/common_css.jsp" type="text/css"/> <script src="http://maps.google.com/maps?file=api&v=2.x&key=<%=key%>&hl=fr" type="text/javascript"></script> <script type="text/javascript" src="<fl:webapp/>/js/master_js.jsp"></script> <link rel="stylesheet" type="text/css" href="<fl:webapp/>/css/master_css.jsp"/> </head> <body onunload="GUnload()"> <fl:bigTabs objectTitle="<%= Utils.getMessage(session, \"FXXX\", \"Google Map\") %>"> <script type="text/javascript"> var map = null; </script> <table width="950px" height="480px" cellpadding="0" cellspacing="0"> <tr> <td valign="top"><div id="map" style="width: 740px; height: 600px; margin-left: 5px; margin-top:5px"></div></td> <td valign="top"><div id="side_bar" style="overflow:scroll;height:605px; width:210px"></div></td> </tr> <tr> <td colspan="2"> <table width="100%"> <tr><td NOWRAP> <span>Chercher les entreprises autour</span> <input id="around" name="around" type="checkbox" class="inputCheckBox" style="vertical-align: bottom" checked="checked" onchange="if($(this).is(':checked')){getEntsArround(map.getBounds());}"/> | <a href="#" onClick="directions();">Calculer l'itinéraire</span></a> (depuis <input id="from" name="from" type="text" class="input" value="<%=actorAddress %>" style="width:300px"/>) | <a href="#" onclick="window.print();">Imprimer</a><img id="loading" src="<fl:webapp/>/icons/dico-loader.gif" style="display:none;"/><span id="detail"></span></td></tr> </table> </td> </tr> </table> <table width="940px"> <tr> <td colspan="2"><div id="path" style="height: 100%;width:940px; overflow:auto;"></div></td> </tr> </table> <script type="text/javascript"> //<![CDATA[ if (GBrowserIsCompatible()) { var map = null; var geocoder = null; var side_bar_html = ""; var gmarkers = []; var selectedMarkers = []; var labels = []; var addresses = []; var htmls = []; var i = 0; var latitude = <%=latitude%>; var longitude=<%=longitude%>; var myMarker; //var getDirections = false; var poly; var initialPoint; var userPoint; var alphabet = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T']; // ====== Create a Client Geocoder ====== var geo = new GClientGeocoder(new GGeocodeCache()); // ====== Array for decoding the failure codes ====== var reasons=[]; reasons[G_GEO_SUCCESS] = "Success"; reasons[G_GEO_MISSING_ADDRESS] = "Missing Address: The address was either missing or had no value."; reasons[G_GEO_UNKNOWN_ADDRESS] = "Unknown Address: No corresponding geographic location could be found for the specified address."; reasons[G_GEO_UNAVAILABLE_ADDRESS]= "Unavailable Address: The geocode for the given address cannot be returned due to legal or contractual reasons."; reasons[G_GEO_BAD_KEY] = "Bad Key: The API key is either invalid or does not match the domain for which it was given"; reasons[G_GEO_TOO_MANY_QUERIES] = "Too Many Queries: The daily geocoding quota for this site has been exceeded."; reasons[G_GEO_SERVER_ERROR] = "Server error: The geocoding request could not be successfully processed."; reasons[G_GEO_BAD_REQUEST] = "A directions request could not be successfully parsed."; reasons[G_GEO_MISSING_QUERY] = "No query was specified in the input."; reasons[G_GEO_UNKNOWN_DIRECTIONS] = "The GDirections object could not compute directions between the points."; function getEntsArround(bounds){ var entLaMin = bounds.getSouthWest().lat(); var entLoMin = bounds.getSouthWest().lng(); var entLaMax = bounds.getNorthEast().lat(); var entLoMax = bounds.getNorthEast().lng(); $.getJSON("<fl:webapp/>/enterprise_get_ents_around.fl?id=<%=id%>&EntLaMin="+parseFloat(entLaMin)+"&EntLoMin="+parseFloat(entLoMin)+"&EntLaMax="+parseFloat(entLaMax)+"&EntLoMax="+parseFloat(entLoMax)+"&la=<%=latitude%>&lo=<%=longitude%>", function(data) { var displayResult = true; if(typeof data.markers != 'undefined'){ if(data.markers.length > 20){ if(window.confirm("Votre niveau de zoom ramène ["+data.markers.length+"] entreprises.\nVoulez-vous afficher quand même les résultats?") == false){ $("#around").attr("checked", false); displayResult = false; } } } if(displayResult){ i=0; side_bar_html = ""; gmarkers = []; selectedMarkers = new Array(); htmls = []; labels = []; addresses = []; map.clearOverlays(); plotMainMarker(); $.each(data.markers, function(index,object){ var point = new GLatLng(object.lat, object.lng); var marker = createMarker(point, object.entID, decodeURIComponent(object.label), decodeURIComponent(object.html), decodeURIComponent(object.address)); map.addOverlay(marker); }); document.getElementById("side_bar").innerHTML = "<table><tr valign=\"top\"><td><input type=\"checkbox\" checked=\"true\" onClick=\"handleAllMarkers(this)\" /></td><td><span class=\"dataLabel\">Tous</span></td></tr>"+side_bar_html+"</table>"; } if (poly) map.addOverlay(poly); //if(getDirections == true){ directions()}; }); } function createMarker(point,entID,name,html, address) { var marker = new GMarker(point, {zIndexProcess:importanceOrder}); marker.importance = 1; GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml(html); }); // save the info we need to use later for the side_bar gmarkers[i] = marker; var selectedMarker = new Object(); selectedMarker.marker = marker; selectedMarker.name = name; selectedMarker.address = address; selectedMarkers[i] = selectedMarker; htmls[i] = html; labels[i] = name; addresses[i] = address; // add a line to the side_bar html side_bar_html += "<tr valign=\"top\"><td><input class=\"entInput\" id=\"" + entID + "\" name=\"" + entID + "\" type=\"checkbox\" checked=\"true\" onChange=\"javascript:handleMarker('"+i+"', this);\" /></td><td><a href=\"#\" onClick=\"javascript:myclick('" + i + "');handleCheckbox(this);\">" + name + "<\/a></td></tr>"; i++; return marker; } // This function picks up the click and opens the corresponding info window function myclick(i) { gmarkers[i].openInfoWindowHtml(htmls[i]); } function handleMarker(i, obj){ if (poly) map.removeOverlay(poly); if($(obj).is(':checked')){ map.addOverlay(gmarkers[i]); index = (selectedMarkers)? selectedMarkers.length : 0; var selectedMarker = new Object(); selectedMarker.marker = gmarkers[i]; selectedMarker.name = labels[i]; selectedMarker.address = addresses[i]; selectedMarkers[index] = selectedMarker; }else{ map.removeOverlay(gmarkers[i]); selectedMarkers = $.grep(selectedMarkers, function(s) { return s.name != labels[i]; }); //indexToRemove = $.inArray(selectedMarker, selectedMarkers); //selectedMarkers.splice(indexToRemove, 1); } } function importanceOrder (marker) { return GOverlay.getZIndex(marker.getPoint().lat()) + marker.importance*1000000; } function plotMainMarker(){ var myicon = new GIcon(G_DEFAULT_ICON); myicon.sprite = {image:"<fl:webapp/>/icons/sprites.png", top:34*5}; var point = new GLatLng(latitude,longitude); myMarker = new GMarker(point, {icon:myicon,zIndexProcess:importanceOrder}); myMarker.importance = 2; GEvent.addListener(myMarker, "click", function() { myMarker.openInfoWindowHtml("<%=html%>"); }); map.addOverlay(myMarker); } var gdir=new GDirections(null, document.getElementById("path")); GEvent.addListener(gdir,"error", function() { var code = gdir.getStatus().code; var reason="Code "+code; if (reasons[code]) { reason = "Code "+code +" : "+reasons[code] } alert("Failed to obtain directions, "+reason); //getDirections = false; }); GEvent.addListener(gdir, "load", function() { if (poly) map.removeOverlay(poly); poly = gdir.getPolyline(); map.addOverlay(poly); }); function directions() { if(selectedMarkers[0]){ if(selectedMarkers.length > 20){ alert("Il y a trop d'entreprises pour calculer une itinéraire.\nVeuillez réduire le nombre d'entreprises affichées."); return; } } //var goForDirections = false; initialPoint = myMarker.getPoint(); //if the user specified an address geolocalize it and then get directions if($("#from").val() != '' ){ geolocalizeUserAddress(); }else{ getOptimizedDirections(); } } function removeMarker(id){ $('#'+id).attr('checked', false); $('#'+id).change(); } function handleCheckbox(obj){ $(obj).prev().parent().parent().find('.entInput').attr('checked', 'true'); $(obj).prev().parent().parent().find('.entInput').change(); } function handleAllMarkers(obj){ if($(obj).is(':checked')){ $('.entInput').each(function(index){ $(this).attr('checked', true); $(this).change(); }); }else{ selectedLabels = []; selectedMarkers = []; $('.entInput').each(function(index){ $(this).attr('checked', false); $(this).change(); }); } } var jsondata = ""; var nbDirectionsDone = 0; var indexDestination = 0; var directionsToGet = []; var directionsGetters = []; var delay = 10; var markersToOptimize = []; var labelsForMarkersToOptimize = []; function getOptimizedDirections(){ nbDirectionsDone = 0; indexDestination = 0; jsondata = ""; directionsToGet = []; directionsGetters = []; delay = 10; markersToOptimize = []; markersToOptimize = selectedMarkers.slice(0); if($("#from").val()!=''){ var markerToOptimize = new Object(); markerToOptimize.marker = myMarker; markerToOptimize.name = "<%=entCorpName%>"; markerToOptimize.address = "<%=address%>"; markersToOptimize[selectedMarkers.length] = markerToOptimize; } //Get all the distance between each points of the selected Markers //getDirectionFor2Points(); for( var index = -1; index < markersToOptimize.length; ++index){ for( var j = 0; j < markersToOptimize.length; ++j){ if(index != j){ getDirectionFor2Points(index, j); } } } directionsGetters[0].load(directionsToGet[0]); //setTimeout("getStatus();", 1000); //getDirection = true; $("#loading").attr("style","display: block"); document.getElementById("path").innerHTML = ""; } //Get the distance between each points and append them into the JSON data function getDirectionFor2Points(initial, destination){ if(initial == -1){ if($("#from").val() != ''){ a = "from: @" + userPoint.toUrlValue(6) + " to: @" + markersToOptimize[destination].marker.getPoint().toUrlValue(6); }else{ a = "from: @" + initialPoint.toUrlValue(6) + " to: @" + markersToOptimize[destination].marker.getPoint().toUrlValue(6); } }else{ a = "from: @" + markersToOptimize[initial].marker.getPoint().toUrlValue(6) + " to: @" + markersToOptimize[destination].marker.getPoint().toUrlValue(6); } var directions = new GDirections(); GEvent.addListener(directions,"load",function() { if(nbDirectionsDone > 0){ jsondata += ", "; } jsondata += "{\"initial\": "+initial+", \"dest\": "+destination+", \"distance\": "+this.getDistance().meters+", \"duration\": "+this.getDuration().seconds+"}"; nbDirectionsDone++; if(nbDirectionsDone < directionsGetters.length){ setTimeout("directionsGetters[nbDirectionsDone].load(directionsToGet[nbDirectionsDone])",delay); }else{ jsondata = "["+jsondata+"]"; sendDirectionsForOptimization(jsondata); } }); GEvent.addListener(directions,"error",function() { if(directions.getStatus().code == G_GEO_TOO_MANY_QUERIES){ delay = delay+10; setTimeout("directionsGetters[nbDirectionsDone].load(directionsToGet[nbDirectionsDone])",delay); }else{ alert(reasons[directions.getStatus().code]); } }); directionsToGet[directionsToGet.length] = a; directionsGetters[directionsGetters.length] = directions; } function sendDirectionsForOptimization(jsondata){ $.ajax({ data: jsondata, type: "POST", url: '<fl:webapp/>/enterprise_get_optimized_directions.fl?size='+nbDirectionsDone, timeout: 20000, contentType: "application/json;charset=utf-8", dataType: 'json', async: false, success: function(data){ $("#loading").attr("style","display: none"); //map.clearOverlay(); if($("#from").val() != ''){ var a = "from: "+$("#from").val()+ " @" + userPoint.toUrlValue(6); plotDirectionMarker(alphabet[0], userPoint.lat(), userPoint.lng()); }else{ var a = "from: <%=entCorpName%> - <%=address%>" + " @" + myMarker.getPoint().toUrlValue(6); plotDirectionMarker(alphabet[0], myMarker.getPoint().lat(), myMarker.getPoint().lng()); } var b = ""; $.each(data.markers, function(index,object){ if(object.id > -1){ plotDirectionMarker(alphabet[index], markersToOptimize[object.id].marker.getPoint().lat(), markersToOptimize[object.id].marker.getPoint().lng()); b += " to: "+markersToOptimize[object.id].name + " - " + markersToOptimize[object.id].address + " @" + markersToOptimize[object.id].marker.getPoint().toUrlValue(6); } }); gdir.load(a+b, {getPolyline:true}); //getDirections = true; } }); } function geolocalizeUserAddress(){ geo.getLocations($("#from").val(), function (result) { // If that was successful if (result.Status.code == G_GEO_SUCCESS) { // Lets assume that the first marker is the one we want var p = result.Placemark[0].Point.coordinates; var lat=p[1]; var lng=p[0]; userPoint = new GLatLng(lat, lng); getOptimizedDirections(); } // ====== Decode the error status ====== else { alert(reasons[result.Status.code]); } }); } function plotDirectionMarker(letter, lat, lng){ var myDirectionIcon = new GIcon(G_DEFAULT_ICON); myDirectionIcon.image = "http://maps.google.com/mapfiles/marker" + letter + ".png"; var directionPoint = new GLatLng(lat,lng); var directionMarker = new GMarker(directionPoint, {icon:myDirectionIcon,zIndexProcess:importanceOrder}); directionMarker.importance = 2; map.addOverlay(directionMarker); } //Initialize map map = new GMap(document.getElementById("map")); map.addControl(new GSmallMapControl()); map.addControl(new GMapTypeControl()); map.setCenter(new GLatLng(latitude,longitude), 15); map.enableScrollWheelZoom(); var bounds = map.getBounds(); getEntsArround(bounds); GEvent.addListener(map, "dragend", function(){ if($('#around').is(':checked')){ getEntsArround(map.getBounds()); } }); GEvent.addListener(map, "zoomend", function(){ if($('#around').is(':checked')){ getEntsArround(map.getBounds()); } }); plotMainMarker(); myMarker.openInfoWindowHtml("<%=html%>"); } // display a warning if the browser was not compatible else { alert("Sorry, the Google Maps API is not compatible with this browser"); } // This Javascript is based on code provided by the // Community Church Javascript Team // http://www.bisphamchurch.org.uk/ // http://econym.org.uk/gmap/ //]]> </script> </fl:bigTabs> <table class="container" width="100%"> <tr class="fieldline"> <td colspan="2" style="text-align: center;"> <a href="javascript:window.close()"><img src="<fl:webapp/>/icons/ico/fermer_red_long.gif"></a> </td> </tr> </table> </body> </html> <% /****************************************************************************** * CVS Log File - This is no longer maintained! * * Revision 1.1 2004/07/23 17:52:10 brian * Initial Revision * *****************************************************************************/ %>
Ms-Dos/Windows
Unix
Write backup
jsp File Browser version 1.2 by
www.vonloesch.de