Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #3565 (closed defect: wontfix)

Opened 3 years ago

Last modified 3 years ago

prototype.js breaks Yahoo Maps

Reported by: daemmon@daemmonhughes.com Assigned to: sam@conio.net
Priority: normal Milestone:
Component: Prototype Version:
Severity: normal Keywords: Object extend inheritance
Cc:

Description

If you take the basic helloworld example from the Yahoo Maps API documentation http://developer.yahoo.net/maps/ajax/index.html and include the script.aculo.us prototype.js file, the yahoo map will load but is no longer draggable. Firefox reports:

"Error: nm.calculatePosition is not a function

Source File: http://api.maps.yahoo.com/v2.0/aj/ymapapi.js Line: 866"

(note that the yahoo developer key in this example is not valid):

<html> <head>

<script type="text/javascript" src="http://api.maps.yahoo.com/ajaxymap?v=2.0&appid=some_valid_yahoo_key"></script>

// add this line and it breaks draggable maps <script src="/path/to/scriptaculous/prototype.js" type="text/javascript"></script> <style type="text/css"> #mapContainer {

height: 600px; width: 600px;

} </style> </head> <body> <div id="mapContainer"></div>

<script type="text/javascript">

// Create a lat/lon object

var myPoint = new YGeoPoint(30.244047, -97.747175);

// Create a map object var map = new YMap(document.getElementById('mapContainer'));

// Display the map centered on a latitude and longitude map.drawZoomAndCenter(myPoint, 3);

</script>

</body> </html>

Change History

01/21/06 07:34:07 changed by devslashnull@gmail.com

From looking at ymapapi.js, my guess is that it is breaking because it makes use of JavaScript's for..in construct on the _mTb object, an array. Since an array is actually a hash with numeric keys by default, for..in works as long as there's no non-numeric keys in the hash.

Prototype adds non-numeric key elements to Array instances like _each and all the methods of Enumerable. You could replace the instances of for (a in b) {...} in the yahoo map files with b.each(function(a) {...}.bind(this)), though that might be painful since the files are dynamically included by yahoo.

In short, I think this is a property of Prototype that is unlikely to change.

01/21/06 07:35:46 changed by devslashnull@gmail.com

Or change it to for (var i = 0; i < b.length; i++) { // replace a with b[i] }, of course.

01/21/06 07:57:58 changed by madrobby

  • component changed from script.aculo.us to Prototype.

01/22/06 17:24:30 changed by madrobby

  • owner changed from thomas@fesch.at to sam@conio.net.

07/24/06 06:45:08 changed by petermichaux@gmail.com

  • keywords set to Object extend inheritance.

11/04/06 18:58:28 changed by mislav

  • status changed from new to closed.
  • resolution set to wontfix.

This is not a fault of Prototype. People shouldn't use Array as associative arrays (devslashnull@gmail.com explained it nicely)