block by dribnet 4326899

MatthewMueller's array working with leaflet.js

Full Screen

index.html

<!DOCTYPE html>
<html>
<head>
  <title>Leaflet Quick Start Guide Example</title>
  <meta charset="utf-8" />

  <meta name="viewport" content="width=device-width, initial-scale=1.0">

  <link rel="stylesheet" href="//cdn.leafletjs.com/leaflet-0.5.1/leaflet.css" />
  <!--[if lte IE 8]><link rel="stylesheet" href="../dist/leaflet.ie.css" /><![endif]-->
</head>
<body>
  <div id="map" style="width: 960px; height: 500px"></div>

  <script src="isArray-polyfill.js"></script>
  <script src="array.js"></script>
  <script src="//cdn.leafletjs.com/leaflet-0.5.1/leaflet.js"></script>
  <script>
    var centerPoint = array(51.505, -0.09);
    var circleCenter = array(51.508, -0.11);
    var polygonPoints = array(
      array(51.509, -0.08),
      array(51.503, -0.06),
      array(51.51, -0.047)
    );

    var map = L.map('map').setView(centerPoint, 13);

    L.tileLayer('//{s}.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/997/256/{z}/{x}/{y}.png', {
      maxZoom: 18,
      attribution: 'Map data &copy; <a href="//openstreetmap.org">OpenStreetMap</a> contributors, <a href="//creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="//cloudmade.com">CloudMade</a>'
    }).addTo(map);


    L.marker(centerPoint).addTo(map)
      .bindPopup("<b>Hello world!</b><br />I am a popup.").openPopup();

    L.circle(circleCenter, 500, {
      color: 'red',
      fillColor: '#f03',
      fillOpacity: 0.5
    }).addTo(map).bindPopup("I am a circle.");

    L.polygon(polygonPoints).addTo(map).bindPopup("I am a polygon.");


    var popup = L.popup();

    function onMapClick(e) {
      popup
        .setLatLng(e.latlng)
        .setContent("You clicked the map at " + e.latlng.toString())
        .openOn(map);
    }

    map.on('click', onMapClick);

  </script>
</body>
</html>

isArray-polyfill.js

/**
 * Provides isArray.js support for for libraries that verify an object
 * is an array via either Object.prototype.toString or Array.isArray.
 *
 * For more information: https://github.com/dribnet/isArray.js
 */

// this method patches (or implements) Array.isArray
// and stores the original function so it can be restored
(function(ar) {
  var isArray = ar.isArray;
  // toString is only used if Array.isArray does not exist
  var toString = Object.prototype.toString;
  ar["$originalToString"] = isArray;
  ar.isArray = function(obj) {
    var that = this;
    if(obj && obj.isArray === '[object Array]') {
      return true;
    }
    else if (isArray) {
      return isArray.call(that, obj);
    }
    else {
      // fallback - polyfill the Array.isArray method
      return toString.call(obj) === "[object Array]";
    }
  }
})(Array);

// this method patches Object.prototype.toString
// and stores the original function so it can be restored
(function(op) {
  var toString = op.toString;
  op["$originalToString"] = toString;
  op.toString = function(args) {
    var that = this;
    if(that && that.isArray === '[object Array]') {
      return '[object Array]';
    }
    else {
      return toString.call(that);
    }
  }
})(Object.prototype);