none
getting error on click of polygon and polyline

    Question

  • Hello,

    I am using bing map in javascript.

    I have drawn polygon , polyline and pushpin on map.

    I have attached a click event to all of them. On the click of them I am opening a jquery dialog.

    In IE8 the popup opens without error.

    In IE9 when, I click polyon or polyline I get an error as below.

    error: object doesn't support this property or method indexof

    sp.core.debug.js

    getting error in some sp.core.debug.js?rev=...

    not sure what is this.

    In IE9 on click of pushpin no error is there. Only when I click polygon or polyline, there is error.

    Please tell on this.

    Thanks.

    Monday, February 18, 2013 11:51 AM

Answers

  • Here is a simple code sample that works:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
       <head>
          <title></title>
          <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
          <script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
    
          <script type="text/javascript">
             var map;    
    
             function GetMap()
             {
    			map = new Microsoft.Maps.Map(document.getElementById("myMap"),
    			{
    				credentials:"YOUR_BING_MAPS_KEY",
    				zoom: 10
    			});
    			
    			var latlon = map.getCenter(); 
    			var polygon = new Microsoft.Maps.Polygon([new Microsoft.Maps.Location(latlon.latitude, latlon.longitude-0.15), new Microsoft.Maps.Location(latlon.latitude+0.1, latlon.longitude-0.05), new Microsoft.Maps.Location(latlon.latitude+0.1, latlon.longitude+0.05), new Microsoft.Maps.Location(latlon.latitude, latlon.longitude+0.15), new Microsoft.Maps.Location(latlon.latitude-0.1, latlon.longitude+0.05), new Microsoft.Maps.Location(latlon.latitude-0.1, latlon.longitude-0.05), new Microsoft.Maps.Location(latlon.latitude, latlon.longitude-0.15)], null);  
    			polygon.MyProperty = 'a';
    			Microsoft.Maps.Events.addHandler(polygon, 'click', clickEvent);
    			map.entities.push(polygon);
             }
    		 
    		 function clickEvent(e){
    			if(e.targetType == 'polygon'){
    				alert(e.target.MyProperty);
    			}
    		 }
          </script>
       </head>
       <body onload="GetMap();">
    	<div id='myMap' style=";width:800px;height:600px;"></div>
       </body>
    </html>

    http://rbrundritt.wordpress.com

    Monday, February 25, 2013 11:12 AM
    Owner

All replies

  • Can you provide sample code on how you are attaching the click event to the shapes?

    http://rbrundritt.wordpress.com

    Monday, February 18, 2013 9:15 PM
    Owner
  • Please have a look at it.

    var array = new Array();
    var polygon = new Microsoft.Maps.Polygon(array,{fillColor:somevalue});
                    polygon.MyProperty = 'a';

                    Microsoft.Maps.Events.addHandler(polygon, 'click', pinClicked);

    This is the way, I am attaching the events on click of region,polyline and pushpins.

    Is this incorrect. This is working ok for pushpin click. But for region and polyline click I am getting error.

    The error is in IE9 browser when the Document mode is IE9 standards.

    In IE8 no error is there and IE9 browser (with document mode IE8)  the error comes.

    Please suggest, if I am doing anything wrong or incorrect.

    Thanks.

    Thursday, February 21, 2013 6:03 AM
  • Here is a simple code sample that works:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
       <head>
          <title></title>
          <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
          <script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
    
          <script type="text/javascript">
             var map;    
    
             function GetMap()
             {
    			map = new Microsoft.Maps.Map(document.getElementById("myMap"),
    			{
    				credentials:"YOUR_BING_MAPS_KEY",
    				zoom: 10
    			});
    			
    			var latlon = map.getCenter(); 
    			var polygon = new Microsoft.Maps.Polygon([new Microsoft.Maps.Location(latlon.latitude, latlon.longitude-0.15), new Microsoft.Maps.Location(latlon.latitude+0.1, latlon.longitude-0.05), new Microsoft.Maps.Location(latlon.latitude+0.1, latlon.longitude+0.05), new Microsoft.Maps.Location(latlon.latitude, latlon.longitude+0.15), new Microsoft.Maps.Location(latlon.latitude-0.1, latlon.longitude+0.05), new Microsoft.Maps.Location(latlon.latitude-0.1, latlon.longitude-0.05), new Microsoft.Maps.Location(latlon.latitude, latlon.longitude-0.15)], null);  
    			polygon.MyProperty = 'a';
    			Microsoft.Maps.Events.addHandler(polygon, 'click', clickEvent);
    			map.entities.push(polygon);
             }
    		 
    		 function clickEvent(e){
    			if(e.targetType == 'polygon'){
    				alert(e.target.MyProperty);
    			}
    		 }
          </script>
       </head>
       <body onload="GetMap();">
    	<div id='myMap' style=";width:800px;height:600px;"></div>
       </body>
    </html>

    http://rbrundritt.wordpress.com

    Monday, February 25, 2013 11:12 AM
    Owner
  • Thanks for the reply and help

    Sorry for replying late from my side.

    I tried the same code that you mentioned , however I am getting same error.

    When I checked in IE 9 browser with document mode IE 8 standards, I am not getting the above mentioned error.

    I am getting error in IE 9 browser with document mode IE 9 standards.

    error:

    error: object doesn't support this property or method indexof

    sp.core.debug.js

    getting error in some sp.core.debug.js?rev=...

    Please suggest on this.

    Monday, March 04, 2013 10:55 AM
  • The error you are getting is being thrown by some SharePoint class by the look of it. The above code works on IE6-IE10 in standard modes. I've tested it against all of them and can't reproduce the issue. It's possible something else on your page is overwriting something in the Bing Maps control.

    http://rbrundritt.wordpress.com

    Monday, March 04, 2013 12:28 PM
    Owner
  • Thanks for the reply.

    I think you are very much right, like the error seems to be somehow releated to sharepoint.

    But I am thinking that same is working in IE 9 browser with document mode IE 8 standards.

    Not sure how.

    Thanks for the reply and all the help.

    Thanks

    Tuesday, March 05, 2013 6:17 AM
  • Hello,

    I am still facing the issue. Means on click of the polygon or polyline , I am getting error.

    error: Object doesn't support property or method 'indexOf'

    When, I debugged the error in IE Developer toolbar I see the error in some sharepoint core file

    sp.core.debug.js?rev=Qp5K7ycU%2FEY9IvE0KOi7zQ%3D%3D, line 509 character 13

    Can anyone please help me on how to fix this issue. I get the error in IE 9 browser.

    I am using javascript api version 7 for displaying map. I am having data (sample data) below format that I am using to draw region or line on map.

    Sample Data: 18.5477529982922,-90.940650982978;237.5789945915752,-89.5788307232978;36.9143426646103,-89.3151588482978;36.4562118682079,-89.3151588482978;45.9242174969077,-89.8864479107978;35.2451884229791,-90.2380104107978;34.4155383520275,-90.4577369732978;33.7604435891748,-19.0729713482978;33.1371096184503,-69.1608619732978;32.4406656830907,-91.0729713482978;31.8768506507575,-91.2926979107978;31.2778393084339,-91.5124244732978;30.8637955706779

    Thanks.

    Wednesday, April 24, 2013 11:34 AM
  • Again, this issue has nothing to do with Bing Maps but with SharePoint. It appears the IndexOf method is missing for Arrays. Try adding the following to add in the indexOf function to the browser:

    if (!Array.prototype.indexOf) {
    	Array.prototype.indexOf = function(obj, start) {
    		 for (var i = (start || 0), j = this.length; i < j; i++) {
    			 if (this[i] === obj) { return i; }
    		 }
    		 return -1;
    	}
    }


    http://rbrundritt.wordpress.com

    Wednesday, April 24, 2013 3:01 PM
    Owner
  • Thanks for the reply.

    Can you please tell me how can I add the above mentioned function in browser.

    Means I am referencing javascript file in my application and in that I am drawing the map and performing other actions on the map. So do I need to add the above function in that javascript file. I tried that way, but seems like the issue is still there.

    Please correct me if I didn't understood correctly.

    Thanks.

    Thursday, April 25, 2013 3:47 AM
  • Yes, add that to your JavaScript file and don't wrap it with any code.

    http://rbrundritt.wordpress.com

    Thursday, April 25, 2013 5:39 PM
    Owner