Friday, 14 October 2011

Can someone correct the highlighted code in blue.



I  have two objects called  1Project__c,  2.  Enterprise__c.
There are two fields in the Enterprise object called Latitude__c and Longitude__c There is a relationshipdefined on the Enterprise object with  lookup to Project Title.
NowI would like to create a map on the Project page layout showing all the Enterprises related to thatproject using the latitude and longitude fields.
Please find the code here:

<apex:page standardcontroller="Project__c">
This map shows the locations of enterprises which are associated with {!Project__c.Nameproject.
    <apex:includeScript value="http://api.maps.yahoo.com/ajaxymap?v=3.0&appid=salesforce.com"/>
    <script type="text/javascript">
        var map;
        var geoPoints = [];
        var counter = 0;
        var pointCounter = 0;
       
        function geoCodeEnd(r) {
            if (r.success == 1) {
                if (r.GeoPoint.Lat != 0) {
                    geoPoints[geoPoints.length] = r.GeoPoint;
                    pointCounter++;
                }
            else {
                pointCounter++;
            }
            if (pointCounter >= counter) {
                var bestZoomLevel = map.getZoomLevel(geoPoints);
                if (bestZoomLevel < 5bestZoomLevel = 5;
                var geoCenter = map.getCenterGeoPoint(geoPoints);
                map.drawZoomAndCenter(geoCenterbestZoomLevel);
                map.panToLatLon(geoCenter);
            }
        }
       
        function loadMap(domId) {
            // Create a map object
            map = new YMap(document.getElementById(domId));
            // Display the map centered on given address
            YEvent.Capture(mapEventsList.onEndGeoCodegeoCodeEnd);
            map.addZoomLong();
            plotMarkers();
        }       
        function plotMarkers() {
            <apex:repeat var="javalue="{!Project__c.enterprises__r}">
                counter++;
                var marker        new YMarker("{!ja.Latitude__c}, {!ja.Longitude__c}");
                marker.enterpriseName = "{!SUBSTITUTE(LINKTO(ja.Enterprise__r,$Action.Enterprise__c.View,ja.Enterprise__c),'"','')}";                                 
                marker.addLabel(counter);
               
               YEvent.Capture(markerEventsList.MouseClick,
                     function() {this.openSmartWindow
                        ("<div>This is where " +
                        this.enterpriseName +
                        is located!<BR> </div>") });
                        map.addOverlay(marker); 
    
           </apex:repeat>
           
            if(counter == 0) {
             // Display map of US if no Enterprises found
                var myPoint = new YGeoPoint(40,-95);
                map.drawZoomAndCenter(myPoint14);
                alert("There are no enterprises for this project to map.");
            }
        }
    </script>
        <apex:outputPanel layout="blockid="mapContainerstyle="height300px">Loading map...</apex:outputPanel>
    <script>
    loadMap('{!$Component.mapContainer}');
    </script>
</apex:page>

No comments:

Post a Comment