File indexing completed on 2026-04-09 07:58:27
0001 GMaps.prototype.toImage = function(options) {
0002 var options = options || {},
0003 static_map_options = {};
0004
0005 static_map_options['size'] = options['size'] || [this.el.clientWidth, this.el.clientHeight];
0006 static_map_options['lat'] = this.getCenter().lat();
0007 static_map_options['lng'] = this.getCenter().lng();
0008
0009 if (this.markers.length > 0) {
0010 static_map_options['markers'] = [];
0011
0012 for (var i = 0; i < this.markers.length; i++) {
0013 static_map_options['markers'].push({
0014 lat: this.markers[i].getPosition().lat(),
0015 lng: this.markers[i].getPosition().lng()
0016 });
0017 }
0018 }
0019
0020 if (this.polylines.length > 0) {
0021 var polyline = this.polylines[0];
0022
0023 static_map_options['polyline'] = {};
0024 static_map_options['polyline']['path'] = google.maps.geometry.encoding.encodePath(polyline.getPath());
0025 static_map_options['polyline']['strokeColor'] = polyline.strokeColor
0026 static_map_options['polyline']['strokeOpacity'] = polyline.strokeOpacity
0027 static_map_options['polyline']['strokeWeight'] = polyline.strokeWeight
0028 }
0029
0030 return GMaps.staticMapURL(static_map_options);
0031 };
0032
0033 GMaps.staticMapURL = function(options){
0034 var parameters = [],
0035 data,
0036 static_root = (location.protocol === 'file:' ? 'http:' : location.protocol ) + '//maps.googleapis.com/maps/api/staticmap';
0037
0038 if (options.url) {
0039 static_root = options.url;
0040 delete options.url;
0041 }
0042
0043 static_root += '?';
0044
0045 var markers = options.markers;
0046
0047 delete options.markers;
0048
0049 if (!markers && options.marker) {
0050 markers = [options.marker];
0051 delete options.marker;
0052 }
0053
0054 var styles = options.styles;
0055
0056 delete options.styles;
0057
0058 var polyline = options.polyline;
0059 delete options.polyline;
0060
0061
0062 if (options.center) {
0063 parameters.push('center=' + options.center);
0064 delete options.center;
0065 }
0066 else if (options.address) {
0067 parameters.push('center=' + options.address);
0068 delete options.address;
0069 }
0070 else if (options.lat) {
0071 parameters.push(['center=', options.lat, ',', options.lng].join(''));
0072 delete options.lat;
0073 delete options.lng;
0074 }
0075 else if (options.visible) {
0076 var visible = encodeURI(options.visible.join('|'));
0077 parameters.push('visible=' + visible);
0078 }
0079
0080 var size = options.size;
0081 if (size) {
0082 if (size.join) {
0083 size = size.join('x');
0084 }
0085 delete options.size;
0086 }
0087 else {
0088 size = '630x300';
0089 }
0090 parameters.push('size=' + size);
0091
0092 if (!options.zoom && options.zoom !== false) {
0093 options.zoom = 15;
0094 }
0095
0096 var sensor = options.hasOwnProperty('sensor') ? !!options.sensor : true;
0097 delete options.sensor;
0098 parameters.push('sensor=' + sensor);
0099
0100 for (var param in options) {
0101 if (options.hasOwnProperty(param)) {
0102 parameters.push(param + '=' + options[param]);
0103 }
0104 }
0105
0106
0107 if (markers) {
0108 var marker, loc;
0109
0110 for (var i = 0; data = markers[i]; i++) {
0111 marker = [];
0112
0113 if (data.size && data.size !== 'normal') {
0114 marker.push('size:' + data.size);
0115 delete data.size;
0116 }
0117 else if (data.icon) {
0118 marker.push('icon:' + encodeURI(data.icon));
0119 delete data.icon;
0120 }
0121
0122 if (data.color) {
0123 marker.push('color:' + data.color.replace('#', '0x'));
0124 delete data.color;
0125 }
0126
0127 if (data.label) {
0128 marker.push('label:' + data.label[0].toUpperCase());
0129 delete data.label;
0130 }
0131
0132 loc = (data.address ? data.address : data.lat + ',' + data.lng);
0133 delete data.address;
0134 delete data.lat;
0135 delete data.lng;
0136
0137 for(var param in data){
0138 if (data.hasOwnProperty(param)) {
0139 marker.push(param + ':' + data[param]);
0140 }
0141 }
0142
0143 if (marker.length || i === 0) {
0144 marker.push(loc);
0145 marker = marker.join('|');
0146 parameters.push('markers=' + encodeURI(marker));
0147 }
0148
0149 else {
0150 marker = parameters.pop() + encodeURI('|' + loc);
0151 parameters.push(marker);
0152 }
0153 }
0154 }
0155
0156
0157 if (styles) {
0158 for (var i = 0; i < styles.length; i++) {
0159 var styleRule = [];
0160 if (styles[i].featureType){
0161 styleRule.push('feature:' + styles[i].featureType.toLowerCase());
0162 }
0163
0164 if (styles[i].elementType) {
0165 styleRule.push('element:' + styles[i].elementType.toLowerCase());
0166 }
0167
0168 for (var j = 0; j < styles[i].stylers.length; j++) {
0169 for (var p in styles[i].stylers[j]) {
0170 var ruleArg = styles[i].stylers[j][p];
0171 if (p == 'hue' || p == 'color') {
0172 ruleArg = '0x' + ruleArg.substring(1);
0173 }
0174 styleRule.push(p + ':' + ruleArg);
0175 }
0176 }
0177
0178 var rule = styleRule.join('|');
0179 if (rule != '') {
0180 parameters.push('style=' + rule);
0181 }
0182 }
0183 }
0184
0185
0186 function parseColor(color, opacity) {
0187 if (color[0] === '#'){
0188 color = color.replace('#', '0x');
0189
0190 if (opacity) {
0191 opacity = parseFloat(opacity);
0192 opacity = Math.min(1, Math.max(opacity, 0));
0193 if (opacity === 0) {
0194 return '0x00000000';
0195 }
0196 opacity = (opacity * 255).toString(16);
0197 if (opacity.length === 1) {
0198 opacity += opacity;
0199 }
0200
0201 color = color.slice(0,8) + opacity;
0202 }
0203 }
0204 return color;
0205 }
0206
0207 if (polyline) {
0208 data = polyline;
0209 polyline = [];
0210
0211 if (data.strokeWeight) {
0212 polyline.push('weight:' + parseInt(data.strokeWeight, 10));
0213 }
0214
0215 if (data.strokeColor) {
0216 var color = parseColor(data.strokeColor, data.strokeOpacity);
0217 polyline.push('color:' + color);
0218 }
0219
0220 if (data.fillColor) {
0221 var fillcolor = parseColor(data.fillColor, data.fillOpacity);
0222 polyline.push('fillcolor:' + fillcolor);
0223 }
0224
0225 var path = data.path;
0226 if (path.join) {
0227 for (var j=0, pos; pos=path[j]; j++) {
0228 polyline.push(pos.join(','));
0229 }
0230 }
0231 else {
0232 polyline.push('enc:' + path);
0233 }
0234
0235 polyline = polyline.join('|');
0236 parameters.push('path=' + encodeURI(polyline));
0237 }
0238
0239
0240 var dpi = window.devicePixelRatio || 1;
0241 parameters.push('scale=' + dpi);
0242
0243 parameters = parameters.join('&');
0244 return static_root + parameters;
0245 };