<commit_before>var argscheck = require('cordova/argscheck'),
    utils = require('cordova/utils'),
    cordova_exec = require('cordova/exec'),
    common = require('./Common'),
    BaseClass = require('./BaseClass'),
    BaseArrayClass = require('./BaseArrayClass'),
    LatLng = require('./LatLng'),
    LatLngBounds = require('./LatLngBounds'),
    MapTypeId = require('./MapTypeId'),
    event = require('./event');

var Marker = require('./Marker');
var Circle = require('./Circle');
var Polyline = require('./Polyline');
var Polygon = require('./Polygon');
var TileOverlay = require('./TileOverlay');
var GroundOverlay = require('./GroundOverlay');
var KmlOverlay = require('./KmlOverlay');
var CameraPosition = require('./CameraPosition');


/**
 * Google Maps model.
 */
var exec;
var Map = function(id, _exec) {
    exec = _exec;
    var self = this;
    BaseClass.apply(self);

    self.MARKERS = {};
    self.KML_LAYERS = {};
    self.OVERLAYS = {};

    Object.defineProperty(self, "type", {
        value: "Map",
        writable: false
    });

    Object.defineProperty(self, "id", {
        value: id,
        writable: false
    });

    self.on("active_marker_id_changed", function(prevId, newId) {
        if (prevId in self.MARKERS) {
            self.MARKERS[prevId].trigger.call(self.MARKERS[prevId], event.INFO_CLOSE);
        }
        exec(null, null, self.id, 'setActiveMarkerId', [newId]);
    });
};

utils.extend(Map, BaseClass);

Map.prototype.getId = function() {
    return this.id;
};

/**
 * @desc Recalculate the position of HTML elements
 */
Map.prototype.refreshLayout = function(event) {
    exec(null, null, this.id, 'resizeMap', []);
};

Map.prototype.getMap = function(mapId, div, options) {
    var self = this,
        args = [mapId];

    if (!common.isDom(div)) {
        self.set("visible", false);
        options = div;
        options = options || {};
        if (options.camera) {
          if (options.camera.latLng) {
              options.camera.target = options.camera.latLng;
              delete options.camera.latLng;
          }
          this.set('camera', options.camera);
          if (options.camera.target) {
            this.set('camera_target', options.camera.target);
          }
          if (options.camera.bearing) {
            this.set('camera_bearing', options.camera.bearing);
          }
          if (options.camera.zoom) {
            this.set('camera_zoom', options.camera.zoom);
          }
          if (options.camera.tilt) {
            this.set('camera_tilt', options.camera.tilt);
          }
        }
        args.push(options);
    } else {

        var positionCSS = common.getStyle(div, "position");
        if (!positionCSS || positionCSS === "static") {
          // important for HtmlInfoWindow
          div.style.position = "relative";
        }
        self.set("visible", true);
        options = options || {};
        if (options.camera) {
          if (options.camera.latLng) {
              options.camera.target = options.camera.latLng;
              delete options.camera.latLng;
          }
          this.set('camera', options.camera);
          if (options.camera.target) {
            this.set('camera_target', options.camera.target);
          }
          if (options.camera.bearing) {
            this.set('camera_bearing', options.camera.bearing);
          }
          if (options.camera.zoom) {
            this.set('camera_zoom', options.camera.zoom);
          }
          if (options.camera.tilt) {
            this.set('camera_tilt', options.camera.tilt);
          }
        }
        if (options.styles) {
          options.styles = JSON.stringify(options.styles);
        }
        args.push(options);

        div.style.overflow = "hidden";
        self.set("div", div);

        if (div.offsetWidth < 100 || div.offsetHeight < 100) {
          // If the map Div is too small, wait a little.
          var callee = arguments.callee;
          setTimeout(function() {
            callee.call(self, mapId, div, options);
          }, 250 + Math.random() * 100);
          return;
        }
        var elements = [];
        var elemId, clickable, size;


        // Gets the map div size.
        // The plugin needs to consider the viewport zoom ratio
        // for the case window.innerHTML > body.offsetWidth.
        elemId = div.getAttribute("__pluginDomId");
        if (!elemId) {
            elemId = "pgm" + Math.floor(Math.random() * Date.now());
            div.setAttribute("__pluginDomId", elemId);
        }
        args.push(elemId);

        while (div.parentNode) {
            div.style.backgroundColor = 'rgba(0,0,0,0)';

            // prevent multiple readding the class
            if (div.classList && !div.classList.contains('_gmaps_cdv_')) {
                div.classList.add('_gmaps_cdv_');
            } else if (div.className && div.className.indexOf('_gmaps_cdv_') === -1) {
                div.className = div.className + ' _gmaps_cdv_';
            }

            div = div.parentNode;
        }
    }

    cordova.fireDocumentEvent('plugin_touch', {});

    exec(function() {
      cordova.fireDocumentEvent('plugin_touch', {});
      // In order to work map.getVisibleRegion() correctly, wait a little.
      setTimeout(function() {
        self.refreshLayout();
        self.trigger(event.MAP_READY, self);
      }, 250);
    }, self.errorHandler, 'CordovaGoogleMaps', 'getMap', args, {sync: true});
};

Map.prototype.setOptions = function(options) {
    options = options || {};

    if (options.camera) {
      if (options.camera.latLng) {
          options.camera.target = options.camera.latLng;
          delete options.camera.latLng;
      }
      this.set('camera', options.camera);
      if (options.camera.target) {
        this.set('camera_target', options.camera.target);
      }
      if (options.camera.bearing) {
        this.set('camera_bearing', options.camera.bearing);
      }
      if (options.camera.zoom) {
        this.set('camera_zoom', options.camera.zoom);
      }
      if (options.camera.tilt) {
        this.set('camera_tilt', options.camera.tilt);
      }
    }
    if (options.styles) {
      options.styles = JSON.stringify(options.styles);
    }
    exec(null, this.errorHandler, this.id, 'setOptions', [options]);
    return this;
};

Map.prototype.setCameraTarget = function(latLng) {
    this.set('camera_target', latLng);
    exec(null, this.errorHandler, this.id, 'setCameraTarget', [latLng.lat, latLng.lng]);
    return this;
};

Map.prototype.setCameraZoom = function(zoom) {
    this.set('camera_zoom', zoom);
    exec(null, this.errorHandler, this.id, 'setCameraZoom', [zoom]);<commit_msg>fix(map): fixes issue with invalid string length when options.styles is specified<commit_after>var argscheck = require('cordova/argscheck'),
    utils = require('cordova/utils'),
    cordova_exec = require('cordova/exec'),
    common = require('./Common'),
    BaseClass = require('./BaseClass'),
    BaseArrayClass = require('./BaseArrayClass'),
    LatLng = require('./LatLng'),
    LatLngBounds = require('./LatLngBounds'),
    MapTypeId = require('./MapTypeId'),
    event = require('./event');

var Marker = require('./Marker');
var Circle = require('./Circle');
var Polyline = require('./Polyline');
var Polygon = require('./Polygon');
var TileOverlay = require('./TileOverlay');
var GroundOverlay = require('./GroundOverlay');
var KmlOverlay = require('./KmlOverlay');
var CameraPosition = require('./CameraPosition');


/**
 * Google Maps model.
 */
var exec;
var Map = function(id, _exec) {
    exec = _exec;
    var self = this;
    BaseClass.apply(self);

    self.MARKERS = {};
    self.KML_LAYERS = {};
    self.OVERLAYS = {};

    Object.defineProperty(self, "type", {
        value: "Map",
        writable: false
    });

    Object.defineProperty(self, "id", {
        value: id,
        writable: false
    });

    self.on("active_marker_id_changed", function(prevId, newId) {
        if (prevId in self.MARKERS) {
            self.MARKERS[prevId].trigger.call(self.MARKERS[prevId], event.INFO_CLOSE);
        }
        exec(null, null, self.id, 'setActiveMarkerId', [newId]);
    });
};

utils.extend(Map, BaseClass);

Map.prototype.getId = function() {
    return this.id;
};

/**
 * @desc Recalculate the position of HTML elements
 */
Map.prototype.refreshLayout = function(event) {
    exec(null, null, this.id, 'resizeMap', []);
};

Map.prototype.getMap = function(mapId, div, options) {
    var self = this,
        args = [mapId];

    if (!common.isDom(div)) {
        self.set("visible", false);
        options = div;
        options = options || {};
        if (options.camera) {
          if (options.camera.latLng) {
              options.camera.target = options.camera.latLng;
              delete options.camera.latLng;
          }
          this.set('camera', options.camera);
          if (options.camera.target) {
            this.set('camera_target', options.camera.target);
          }
          if (options.camera.bearing) {
            this.set('camera_bearing', options.camera.bearing);
          }
          if (options.camera.zoom) {
            this.set('camera_zoom', options.camera.zoom);
          }
          if (options.camera.tilt) {
            this.set('camera_tilt', options.camera.tilt);
          }
        }
        args.push(options);
    } else {

        var positionCSS = common.getStyle(div, "position");
        if (!positionCSS || positionCSS === "static") {
          // important for HtmlInfoWindow
          div.style.position = "relative";
        }
        self.set("visible", true);
        options = options || {};
        if (options.camera) {
          if (options.camera.latLng) {
              options.camera.target = options.camera.latLng;
              delete options.camera.latLng;
          }
          this.set('camera', options.camera);
          if (options.camera.target) {
            this.set('camera_target', options.camera.target);
          }
          if (options.camera.bearing) {
            this.set('camera_bearing', options.camera.bearing);
          }
          if (options.camera.zoom) {
            this.set('camera_zoom', options.camera.zoom);
          }
          if (options.camera.tilt) {
            this.set('camera_tilt', options.camera.tilt);
          }
        }
        if (utils.isArray(options.styles)) {
          options.styles = JSON.stringify(options.styles);
        }
        args.push(options);

        div.style.overflow = "hidden";
        self.set("div", div);

        if (div.offsetWidth < 100 || div.offsetHeight < 100) {
          // If the map Div is too small, wait a little.
          var callee = arguments.callee;
          setTimeout(function() {
            callee.call(self, mapId, div, options);
          }, 250 + Math.random() * 100);
          return;
        }
        var elements = [];
        var elemId, clickable, size;


        // Gets the map div size.
        // The plugin needs to consider the viewport zoom ratio
        // for the case window.innerHTML > body.offsetWidth.
        elemId = div.getAttribute("__pluginDomId");
        if (!elemId) {
            elemId = "pgm" + Math.floor(Math.random() * Date.now());
            div.setAttribute("__pluginDomId", elemId);
        }
        args.push(elemId);

        while (div.parentNode) {
            div.style.backgroundColor = 'rgba(0,0,0,0)';

            // prevent multiple readding the class
            if (div.classList && !div.classList.contains('_gmaps_cdv_')) {
                div.classList.add('_gmaps_cdv_');
            } else if (div.className && div.className.indexOf('_gmaps_cdv_') === -1) {
                div.className = div.className + ' _gmaps_cdv_';
            }

            div = div.parentNode;
        }
    }

    cordova.fireDocumentEvent('plugin_touch', {});

    exec(function() {
      cordova.fireDocumentEvent('plugin_touch', {});
      // In order to work map.getVisibleRegion() correctly, wait a little.
      setTimeout(function() {
        self.refreshLayout();
        self.trigger(event.MAP_READY, self);
      }, 250);
    }, self.errorHandler, 'CordovaGoogleMaps', 'getMap', args, {sync: true});
};

Map.prototype.setOptions = function(options) {
    options = options || {};

    if (options.camera) {
      if (options.camera.latLng) {
          options.camera.target = options.camera.latLng;
          delete options.camera.latLng;
      }
      this.set('camera', options.camera);
      if (options.camera.target) {
        this.set('camera_target', options.camera.target);
      }
      if (options.camera.bearing) {
        this.set('camera_bearing', options.camera.bearing);
      }
      if (options.camera.zoom) {
        this.set('camera_zoom', options.camera.zoom);
      }
      if (options.camera.tilt) {
        this.set('camera_tilt', options.camera.tilt);
      }
    }
    if (utils.isArray(options.styles)) {
      options.styles = JSON.stringify(options.styles);
    }
    exec(null, this.errorHandler, this.id, 'setOptions', [options]);
    return this;
};

Map.prototype.setCameraTarget = function(latLng) {
    this.set('camera_target', latLng);
    exec(null, this.errorHandler, this.id, 'setCameraTarget', [latLng.lat, latLng.lng]);
    return this;
};

Map.prototype.setCameraZoom = function(zoom) {
    this.set('camera_zoom', zoom);
    exec(null, this.errorHandler, this.id, 'setCameraZoom', [zoom]);
{'fraction_non_alphanumeric': 0.14846188140882746, 'fraction_numerical': 0.002972209838014564, 'mean_word_length': 2.24000962927299, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6555264', 'n_tokens_mistral': 4047, 'n_tokens_neox': 3993, 'n_words': 761}