简体   繁体   中英

Disable drawing if polygon already exists

With set map.data.setControls(null) I still can draw another polygon. How to draw only one polygon?

http://jsfiddle.net/atrxw00x/1

function savePolygon() {
  map.data.toGeoJson(function (json) {
    localStorage.setItem('geoData', JSON.stringify(json));
    if(json.features.length > 0) {
      map.data.setControls(null);
    } else {
      map.data.setControls(['Polygon']);
    }
    initControls(json);
  });
}

You need to use the setDrawingMode call:

if (json.features.length) {
  map.data.setControls(null);
  map.data.setDrawingMode(null);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM