2

I'm using Bing Maps Ajax Control 6.3 and previously I succeded on attaching a click event, but now I'm getting the following error on a different page I tried to repeat the same behavior:

Error: DISPATCH_REQUEST_ERR: DOM Events Exception 1

That error is thrown in Chrome. I tried IE10 and the console threw:

error TypeError: Unable to get property 'GetCurrentDefaultSymbol' of undefined or null reference

this is the function where I load the map and attach the events:

function GetMap() {
    map = new VEMap('myMap');
    map.SetDashboardSize(VEDashboardSize.Tiny);
    var latLong = new VELatLong(16.864061, -99.882588);
    map.LoadMap();
    map.SetCenterAndZoom(latLong, 15);

    map.AttachEvent("onclick", MouseHandler);
    map.AttachEvent("ondoubleclick", MouseHandler);
}

this is my handler:

function MouseHandler(e) {
    try{
        var pixel = new VEPixel(e.mapX, e.mapY);
        var latLong = map.PixelToLatLong(pixel);
        points.push(latLong);
        if (points.length > 2 && shapeCreated) {
            shape.SetPoints(points);
        }
        if (points.length == 3 && !shapeCreated) {
            shape = new VEShape(VEShapeType.Polygon, points);
            map.AddShape(shape);
            shapeCreated = true;
        }
    }
    catch(e)
    {
        console.error(e);
    }
}

That handles the clicks done on a map and draws a polygon after 3 clicks and continues to redraw the polygon when the map is clicked more times.

I'm doing exactly the same stuff as in my previous attempt, but I don't understand why it is not working. I've read here about the error and it says it's caused because the event has been dispatched already, why is that happening?

EDIT

I had some variables initiated as null, I removed the null and it started to work, but the moment I load the page that uses the points of the shape is starts to show the following error when I click:

Invalid argument; input argument 'points[0]' is not a valid 'VELatLong' value.

I print on the console the array of points and I can't see anything wrong with. This is the array.

[
    {
        "Latitude": 16.86689437290364,
        "Longitude": -99.90971088343942,
        "Altitude": null,
        "AltitudeMode": null,
        "_reserved": null
    },
    {
        "Latitude": 16.861596373665986,
        "Longitude": -99.905676841081,
        "Altitude": null,
        "AltitudeMode": null,
        "_reserved": null
    },
    {
        "Latitude": 16.860199977046786,
        "Longitude": -99.89400386744819,
        "Altitude": null,
        "AltitudeMode": null,
        "_reserved": null
    },
    {
        "Latitude": 16.864265926727835,
        "Longitude": -99.89550590515138,
        "Altitude": null,
        "AltitudeMode": null,
        "_reserved": null
    }
]

So for example, if I create a shape with 3 points before calling to that page and inserting it into the div, I get a polygon to display on the map with 3 sides, but the moment that page is loaded and inserted into the div, then I click on the map, the point is added to the points array and tries to replace the current shape's points with the new array, that error is shown, even though there's no problem as far as I can see on the array of points.

Also, after this happens, when I hover the mouse on the pin, another error appears :

Unable to get property '1359639624430' of undefined or null reference

This only happens on IE. Chrome manages to update the shape but keeps showing the DISPATCH_REQUEST_ERR: DOM Events Exception 1 error and Firefox doesn't show any error Any ideas as to why is this happening?

5
  • I don't think it is related to your code but it seems to be rather linked to the Map control. I've tried it on various supported browsers, the only browser that had difficulties was Chrome. Jan 30, 2013 at 9:42
  • yeah, I tried IE and the console threw error TypeError: Unable to get property 'GetCurrentDefaultSymbol' of undefined or null reference Jan 30, 2013 at 17:02
  • try this fiddle jsfiddle.net/7Dj4v
    – G-Man
    Jan 30, 2013 at 17:17
  • I got the same error, I don't understand why is not working. Jan 30, 2013 at 18:10
  • Also I wish to know how to solve that problem in Chrome. Any ideas? Jan 30, 2013 at 18:21

1 Answer 1

3

There is nothing wrong with your code, you'll get the same error clicking on Bing Maps in Chrome with simply this new VEMap('myMap').LoadMap(); Example: Fiddle.

The problem is in the Bing Maps Web.Browser.AttachSafariCompatibility method that gets applied when navigator.userAgent.indexOf("KHTML") !== -1.

As you mentioned this error occurs when "the Event object is already dispatched in the tree." This is happening because Bing Maps is re-dispatching the event Example: Fiddle.

Bing Maps Bug

Event dispatch and DOM event flow Event dispatch and DOM event flow http://www.w3.org/TR/DOM-Level-3-Events/#event-flow

Since the browser is working according to the W3C events specification, and the issue is in third party code you don't control, your options are limited. You might try simply trapping (and logging) JavaScript errors on the page Example: Fiddle.

1
  • thanks for the insight, yeah this problem I decided to ignore it, but it was unnerving how often it showed on the console. It's annoying how each browser has its own restrictions, so making a clean looking code that works for every browser and different versions is a nightmare. Jul 16, 2013 at 15:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.