Skip to content

Latest commit

 

History

History
66 lines (53 loc) · 1.64 KB

File metadata and controls

66 lines (53 loc) · 1.64 KB

⚠️ This document is aim for older versions (from 2.0.0 to 2.2.9). Document for new version is https://github.com/mapsplugin/cordova-plugin-googlemaps-doc/blob/master/v2.6.0/README.md

polygon.setHoles()

You can make holes in polygon. setHoles() method takes Array of Array of LatLng.

<div id="map_canvas"></div>
var POINTS = [
  {"lat": 38.872804, "lng": -77.057354},
  {"lat": 38.872757, "lng": -77.058101},
  {"lat": 38.869999, "lng": -77.05852},
  {"lat": 38.869689, "lng": -77.057723},
  {"lat": 38.868822, "lng": -77.055574},
  {"lat": 38.870706, "lng": -77.05314},
  {"lat": 38.872939, "lng": -77.054602},
  {"lat": 38.872916, "lng": -77.054878},
  {"lat": 38.873207, "lng": -77.054959},
  {"lat": 38.873156, "lng": -77.055368},
  {"lat": 38.873367, "lng": -77.055418},
  {"lat": 38.87318,  "lng": -77.057427}
];

var HOLES = [
  [
    {"lat":38.870605, "lng":-77.05687},
    {"lat":38.87154,  "lng":-77.056657},
    {"lat":38.871734, "lng":-77.055464},
    {"lat":38.870885, "lng":-77.054884},
    {"lat":38.870203, "lng":-77.055801}
  ]
];
var mapDiv = document.getElementById("map_canvas");

// Create a map with specified camera bounds
var map = plugin.google.maps.Map.getMap(mapDiv, {
  camera: {
    target: POINTS
  }
});
map.addEventListener(plugin.google.maps.event.MAP_READY, function() {

  // Show a virtual dialog (loader.js)
  showVirtualDialog(mapDiv, "Click on the polygon");

  map.addPolygon({
    points: POINTS,
    clickable: true // default = false
  }, function(polygon) {
    polygon.on(plugin.google.maps.event.POLYGON_CLICK, function(latLng) {

      polygon.setHoles(HOLES);

    });
  });

});