开发者

Weird prototype-jquery problem when using a google maps

I've a cakePhp website, I use prototype for all the ajax stuff, and jQuery for animation, ...

I've managed the jquery-prototype problem like this:

echo $javascript->link('jquery-1.6.2');
echo $javascript->link('jquery.cookie');
echo $javascript->link('jQueryNoConflict');
echo $javascript->link('prototype');

And the jQuerynoConflict contains only

$.noConflict();

I've done a small JS script, which show items with a defined class and hide other items with the other class:

if(jQuery.cookie('isRawPrice')==1){ 
    jQuery('.priceWithoutTva').show();
    jQuery('.priceWithTva').hide(); 
}else{

    jQuery('.priceWithoutTva').hide();
    jQuery('.priceWithTva').show(); 
}

This working on every page I've, except the one on which I've a Google map item. which I add like this:

  function InitMap(elementId, initPosition, initZoom, multiplePolygonsString) {
   var pos = initPosition.split(',');
    var myLatLng = new google.maps.LatLng(pos[0], pos[1]    );
    var myOptions = {
      zoom:initZoom,
      center: myLatLng,
      mapTypeId: google.maps.MapTypeId.TERRAIN
    };

    map = new google.maps.Map(document.getElementById(elementId),       myOptions);
    var multiplePolygons = multiplePolygonsString.split(';');
    for(var i=0;i<multiplePolygons.length;i++){
        var currentPolygon,match,coordinates = [];

        var reg = /\(\s*([0-9.-]+)\s*,\s*([0-9.-]+)\s*\)/g ;

        while((match =  reg.exec(multiplePolygons[i]))!==null){
            coordinates.push(   new google.maps.LatLng(+match[1], +match[2]));  
        }

        currentPolygon = new google.maps.Polygon({
            paths: coordinates,
            strokeColor: "#FF0000",
            strokeOpacity: 0.8,
            strokeWeight: 3,
            fillColor: "#FF0000",
            fillOpacity: 0.35
        });

        currentPolygon.setMap(map);

        // Add a listener for the click event
        google.maps.event.addListener(currentPolygon, 'click', function(event){         showArrays(event, "testInfoBulle");     });
    }



    infowindow = new google.maps.InfoWindow();
  }

(this basically load a map and create some polygons on defined regions.). This map is well generated every time I display it.

But when I display it and try to hide/show with the previous code, I got this exception:

Uncaught TypeError: Object #<SVGAnimatedString> has no method 'match'prototype.js:300
Enumerable.eachprototype.js:300
Enumerable.injectprototype.js:372
document.getElementsByClassNameprototype.js:932
Sizzlejquery-1.6.2.js:4869
jQuery.fn.extend.findjquery-1.6.2.js:5188
jQuery.fn.jQuery.initjquery-1.6.2.js:189
jQueryjquery-1.6.2.js:27
updat开发者_StackOverfloweDisplay.js:26 ---> This is the jQuery('.priceWithoutTva').show(); line
(anonymous function)cat3:3000:643
onclickcat3:3000:644

Why does it goes through the Prototype library when he is in the jquery method???


Could it be a conflict with your match variable and perhaps a global match variable or function in the prototype or jquery files? try renaming yours to something more unique and see what happens.


I was having jQuery 1.6.2 and prototype 1.4, I now updated to jquery 1.6.4 and protoype 1.7 and it's working!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜