Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:58:27

0001 //==========================

0002 // Polygon containsLatLng

0003 // https://github.com/tparkin/Google-Maps-Point-in-Polygon

0004 // Poygon getBounds extension - google-maps-extensions

0005 // http://code.google.com/p/google-maps-extensions/source/browse/google.maps.Polygon.getBounds.js

0006 if (!google.maps.Polygon.prototype.getBounds) {
0007   google.maps.Polygon.prototype.getBounds = function(latLng) {
0008     var bounds = new google.maps.LatLngBounds();
0009     var paths = this.getPaths();
0010     var path;
0011 
0012     for (var p = 0; p < paths.getLength(); p++) {
0013       path = paths.getAt(p);
0014       for (var i = 0; i < path.getLength(); i++) {
0015         bounds.extend(path.getAt(i));
0016       }
0017     }
0018 
0019     return bounds;
0020   };
0021 }
0022 
0023 if (!google.maps.Polygon.prototype.containsLatLng) {
0024   // Polygon containsLatLng - method to determine if a latLng is within a polygon

0025   google.maps.Polygon.prototype.containsLatLng = function(latLng) {
0026     // Exclude points outside of bounds as there is no way they are in the poly

0027     var bounds = this.getBounds();
0028 
0029     if (bounds !== null && !bounds.contains(latLng)) {
0030       return false;
0031     }
0032 
0033     // Raycast point in polygon method

0034     var inPoly = false;
0035 
0036     var numPaths = this.getPaths().getLength();
0037     for (var p = 0; p < numPaths; p++) {
0038       var path = this.getPaths().getAt(p);
0039       var numPoints = path.getLength();
0040       var j = numPoints - 1;
0041 
0042       for (var i = 0; i < numPoints; i++) {
0043         var vertex1 = path.getAt(i);
0044         var vertex2 = path.getAt(j);
0045 
0046         if (vertex1.lng() < latLng.lng() && vertex2.lng() >= latLng.lng() || vertex2.lng() < latLng.lng() && vertex1.lng() >= latLng.lng()) {
0047           if (vertex1.lat() + (latLng.lng() - vertex1.lng()) / (vertex2.lng() - vertex1.lng()) * (vertex2.lat() - vertex1.lat()) < latLng.lat()) {
0048             inPoly = !inPoly;
0049           }
0050         }
0051 
0052         j = i;
0053       }
0054     }
0055 
0056     return inPoly;
0057   };
0058 }
0059 
0060 if (!google.maps.Circle.prototype.containsLatLng) {
0061   google.maps.Circle.prototype.containsLatLng = function(latLng) {
0062     if (google.maps.geometry) {
0063       return google.maps.geometry.spherical.computeDistanceBetween(this.getCenter(), latLng) <= this.getRadius();
0064     }
0065     else {
0066       return true;
0067     }
0068   };
0069 }
0070 
0071 google.maps.LatLngBounds.prototype.containsLatLng = function(latLng) {
0072   return this.contains(latLng);
0073 };
0074 
0075 google.maps.Marker.prototype.setFences = function(fences) {
0076   this.fences = fences;
0077 };
0078 
0079 google.maps.Marker.prototype.addFence = function(fence) {
0080   this.fences.push(fence);
0081 };
0082 
0083 google.maps.Marker.prototype.getId = function() {
0084   return this['__gm_id'];
0085 };
0086 
0087 //==========================

0088 // Array indexOf

0089 // https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/indexOf

0090 if (!Array.prototype.indexOf) {
0091   Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
0092       "use strict";
0093       if (this == null) {
0094           throw new TypeError();
0095       }
0096       var t = Object(this);
0097       var len = t.length >>> 0;
0098       if (len === 0) {
0099           return -1;
0100       }
0101       var n = 0;
0102       if (arguments.length > 1) {
0103           n = Number(arguments[1]);
0104           if (n != n) { // shortcut for verifying if it's NaN

0105               n = 0;
0106           } else if (n != 0 && n != Infinity && n != -Infinity) {
0107               n = (n > 0 || -1) * Math.floor(Math.abs(n));
0108           }
0109       }
0110       if (n >= len) {
0111           return -1;
0112       }
0113       var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
0114       for (; k < len; k++) {
0115           if (k in t && t[k] === searchElement) {
0116               return k;
0117           }
0118       }
0119       return -1;
0120   }
0121 }