topical media & game development

talk show tell print

mashup-amazon-12-12-03-CustomerMap-js-mashup.js / js



  // JScript File
  var myMap;
      
      // Simple debug utility function
      function myPrint(strText){ 
          document.getElementById('debug').innerHTML = strText + "<br/>" + document.getElementById('debug').innerHTML;        
      } 
      
      function Init(){    
          // Create a map object
          myMap = new YMap(document.getElementById('myMap')); 
          // Display the map centered on given address 
          myMap.drawZoomAndCenter("Nebraska", 15); 
          // Add a zoom control
          myMap.addZoomLong();        
      }
      
      function FindCustomers() {    
          // Build a customer search URL 
          var strAWSAccessKey = "AWSAccessKeyId=0SF32ERN5WCAB6FYER02&";
          var strOperation = "Operation=CustomerContentSearch&";
          var strName="Name=" + document.getElementById("txtName").value + "&"
          
          var strRoot = "http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&";
          var strUrl = strRoot +  strOperation 
              + strName + strAWSAccessKey + 
              "Style=http://mashups.FrancisShanahan.com/11_03_CustomerMap/AmazonJSON.xsl&contentType=text/javascript";
          
          // Write out the URL for debugging purposes
          myPrint(strUrl);
                  
          var myTag = CreateScriptTag(strUrl);
          document.getElementById("myHead").appendChild(myTag);
      }
          
      function CreateMapMarker(strCustomerId, strCity, strState) {       
          // Create a new marker
          var myMarker = new YMarker(strCity + ", " + strState);
          
          // Add a label
          var label= "*";
          myMarker.addLabel(label);
          
          // Add some descriptive text
          var strText = "You Clicked: <b>Customer Id:</b>" + strCustomerId + " in " + strCity + ", " + strState;
          
          // Capture the click event
          YEvent.Capture(myMarker,EventsList.MouseClick, 
                  function() { myMarker.openSmartWindow(strText) ; 
                  document.getElementById('info').innerHTML = strText;});
                  
          // Return the completed marker ready for the map
          return myMarker;
      }
  
      // Parses out the JSON object Properties
      function MyFunction (myJSON){
  
          var strResults = "";
  
          if (myJSON.Customers) {
              var i; 
              // Loop through all the customers. 
              for (i = 0; i < myJSON.Customers.length ; i ++ ) {
                  var myCustomer = myJSON.Customers[i];
                  
                  // Check the customer
                  if (myCustomer) {
                  
                      // Check the address
                      if ((myCustomer.City) && (myCustomer.State)) {
                      
                          // Write out the Customer details
                          strResults += "<b>Customer Id:</b>" + myCustomer.CustomerId + ", ";
                          strResults += myCustomer.City + ", " + myCustomer.State;
                          strResults += "<br/>";
                          
                          // Create a new marker for the map
                          var myMarker = CreateMapMarker(myCustomer.CustomerId, myCustomer.City, myCustomer.State, 
                          myCustomer.City + ", " + myCustomer.State);     
                          
                          // Add the marker to the map
                          myMap.addOverlay(myMarker);
                      }
                  }
              }
          }
          
          // Print out the customer list
          document.getElementById("results").innerHTML = strResults;
      }
      
      function CreateScriptTag(strUrl){
          myScript = document.createElement("script");
              myScript.setAttribute("type", "text/javascript");
              myScript.setAttribute("src", strUrl);
                       
              return myScript; 
      }
      
  
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.