-
Notifications
You must be signed in to change notification settings - Fork 1
/
gmaps.drawnLayer.min.js
137 lines (137 loc) · 10.5 KB
/
gmaps.drawnLayer.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
function DrawnLayer(key,features,callback){this.key=key;this.features=features;this.callback=callback;this.tileSize=new google.maps.Size(256,256);}
DrawnLayer.prototype.getTile=function(coord,zoom,ownerDocument){var getTileBounds=function(tilePoint){var tx=tilePoint.x;var ty=tilePoint.y;var zoom=tilePoint.z;var originShift=2*Math.PI*6378137/2;var pixelsToMeters=function(px,py,zoom){var res=(2*Math.PI*6378137/256)/Math.pow(2,zoom);var mx=px*res-originShift;var my=py*res-originShift;return[mx,my];}
var minMeters=pixelsToMeters(tx*256,ty*256,zoom);var maxMeters=pixelsToMeters((tx+1)*256,(ty+1)*256,zoom);bounds=[minMeters[0],minMeters[1],maxMeters[0],maxMeters[1]];var metersToLatLng=function(mx,my){var lng=(mx/originShift)*180.0;var lat=(my/originShift)*180.0;lat=-180/Math.PI*(2*Math.atan(Math.exp(lat*Math.PI/180.0))-Math.PI/2.0);return[lat,lng];};var sw=metersToLatLng(bounds[0],bounds[1]);var ne=metersToLatLng(bounds[2],bounds[3]);return{north:ne[0],south:sw[0],east:ne[1],west:sw[1]};};var xyify=function(geometry,bounds){if(geometry.length&&typeof geometry[0]==='number'){var lat=geometry[1];var lng=geometry[0];return{x:Math.round(256*(lng-bounds.west)/(bounds.east-bounds.west)),y:(256-Math.round(256*(bounds.north-lat)/(bounds.north-bounds.south)))};}else{for(var pt=0;pt<geometry.length;pt++){geometry[pt]=xyify(geometry[pt],bounds);}
return geometry;}};var geojsonTileUrl='//vector.mapzen.com/osm/'+this.features+'/{z}/{x}/{y}.json?api_key=vector-tiles-'.replace("{z}",zoom).replace("{x}",coord.x).replace("{y}",coord.y);geojsonTileUrl+=this.key;var callback=this.callback;var canvas=ownerDocument.createElement('canvas');canvas.width=256;canvas.height=256;fetch(geojsonTileUrl).then(function(response){return response.json();}).then(function(json){var ctx=canvas.getContext('2d');var bounds=getTileBounds({x:coord.x,y:coord.y,z:zoom});var newfeatures=[];for(var f=0;f<json.features.length;f++){json.features[f].geometry.coordinates=xyify(json.features[f].geometry.coordinates,bounds);}
try{callback(json,ctx);}catch(e){console.error(e);}}).catch(function(err){console.log('Vector Tile download or render failed',err);});return canvas;};(function(self){'use strict';if(self.fetch){return}
var support={searchParams:'URLSearchParams'in self,iterable:'Symbol'in self&&'iterator'in Symbol,blob:'FileReader'in self&&'Blob'in self&&(function(){try{new Blob()
return true}catch(e){return false}})(),formData:'FormData'in self,arrayBuffer:'ArrayBuffer'in self}
function normalizeName(name){if(typeof name!=='string'){name=String(name)}
if(/[^a-z0-9\-#$%&'*+.\^_`|~]/i.test(name)){throw new TypeError('Invalid character in header field name')}
return name.toLowerCase()}
function normalizeValue(value){if(typeof value!=='string'){value=String(value)}
return value}
function iteratorFor(items){var iterator={next:function(){var value=items.shift()
return{done:value===undefined,value:value}}}
if(support.iterable){iterator[Symbol.iterator]=function(){return iterator}}
return iterator}
function Headers(headers){this.map={}
if(headers instanceof Headers){headers.forEach(function(value,name){this.append(name,value)},this)}else if(headers){Object.getOwnPropertyNames(headers).forEach(function(name){this.append(name,headers[name])},this)}}
Headers.prototype.append=function(name,value){name=normalizeName(name)
value=normalizeValue(value)
var list=this.map[name]
if(!list){list=[]
this.map[name]=list}
list.push(value)}
Headers.prototype['delete']=function(name){delete this.map[normalizeName(name)]}
Headers.prototype.get=function(name){var values=this.map[normalizeName(name)]
return values?values[0]:null}
Headers.prototype.getAll=function(name){return this.map[normalizeName(name)]||[]}
Headers.prototype.has=function(name){return this.map.hasOwnProperty(normalizeName(name))}
Headers.prototype.set=function(name,value){this.map[normalizeName(name)]=[normalizeValue(value)]}
Headers.prototype.forEach=function(callback,thisArg){Object.getOwnPropertyNames(this.map).forEach(function(name){this.map[name].forEach(function(value){callback.call(thisArg,value,name,this)},this)},this)}
Headers.prototype.keys=function(){var items=[]
this.forEach(function(value,name){items.push(name)})
return iteratorFor(items)}
Headers.prototype.values=function(){var items=[]
this.forEach(function(value){items.push(value)})
return iteratorFor(items)}
Headers.prototype.entries=function(){var items=[]
this.forEach(function(value,name){items.push([name,value])})
return iteratorFor(items)}
if(support.iterable){Headers.prototype[Symbol.iterator]=Headers.prototype.entries}
function consumed(body){if(body.bodyUsed){return Promise.reject(new TypeError('Already read'))}
body.bodyUsed=true}
function fileReaderReady(reader){return new Promise(function(resolve,reject){reader.onload=function(){resolve(reader.result)}
reader.onerror=function(){reject(reader.error)}})}
function readBlobAsArrayBuffer(blob){var reader=new FileReader()
reader.readAsArrayBuffer(blob)
return fileReaderReady(reader)}
function readBlobAsText(blob){var reader=new FileReader()
reader.readAsText(blob)
return fileReaderReady(reader)}
function Body(){this.bodyUsed=false
this._initBody=function(body){this._bodyInit=body
if(typeof body==='string'){this._bodyText=body}else if(support.blob&&Blob.prototype.isPrototypeOf(body)){this._bodyBlob=body}else if(support.formData&&FormData.prototype.isPrototypeOf(body)){this._bodyFormData=body}else if(support.searchParams&&URLSearchParams.prototype.isPrototypeOf(body)){this._bodyText=body.toString()}else if(!body){this._bodyText=''}else if(support.arrayBuffer&&ArrayBuffer.prototype.isPrototypeOf(body)){}else{throw new Error('unsupported BodyInit type')}
if(!this.headers.get('content-type')){if(typeof body==='string'){this.headers.set('content-type','text/plain;charset=UTF-8')}else if(this._bodyBlob&&this._bodyBlob.type){this.headers.set('content-type',this._bodyBlob.type)}else if(support.searchParams&&URLSearchParams.prototype.isPrototypeOf(body)){this.headers.set('content-type','application/x-www-form-urlencoded;charset=UTF-8')}}}
if(support.blob){this.blob=function(){var rejected=consumed(this)
if(rejected){return rejected}
if(this._bodyBlob){return Promise.resolve(this._bodyBlob)}else if(this._bodyFormData){throw new Error('could not read FormData body as blob')}else{return Promise.resolve(new Blob([this._bodyText]))}}
this.arrayBuffer=function(){return this.blob().then(readBlobAsArrayBuffer)}
this.text=function(){var rejected=consumed(this)
if(rejected){return rejected}
if(this._bodyBlob){return readBlobAsText(this._bodyBlob)}else if(this._bodyFormData){throw new Error('could not read FormData body as text')}else{return Promise.resolve(this._bodyText)}}}else{this.text=function(){var rejected=consumed(this)
return rejected?rejected:Promise.resolve(this._bodyText)}}
if(support.formData){this.formData=function(){return this.text().then(decode)}}
this.json=function(){return this.text().then(JSON.parse)}
return this}
var methods=['DELETE','GET','HEAD','OPTIONS','POST','PUT']
function normalizeMethod(method){var upcased=method.toUpperCase()
return(methods.indexOf(upcased)>-1)?upcased:method}
function Request(input,options){options=options||{}
var body=options.body
if(Request.prototype.isPrototypeOf(input)){if(input.bodyUsed){throw new TypeError('Already read')}
this.url=input.url
this.credentials=input.credentials
if(!options.headers){this.headers=new Headers(input.headers)}
this.method=input.method
this.mode=input.mode
if(!body){body=input._bodyInit
input.bodyUsed=true}}else{this.url=input}
this.credentials=options.credentials||this.credentials||'omit'
if(options.headers||!this.headers){this.headers=new Headers(options.headers)}
this.method=normalizeMethod(options.method||this.method||'GET')
this.mode=options.mode||this.mode||null
this.referrer=null
if((this.method==='GET'||this.method==='HEAD')&&body){throw new TypeError('Body not allowed for GET or HEAD requests')}
this._initBody(body)}
Request.prototype.clone=function(){return new Request(this)}
function decode(body){var form=new FormData()
body.trim().split('&').forEach(function(bytes){if(bytes){var split=bytes.split('=')
var name=split.shift().replace(/\+/g,' ')
var value=split.join('=').replace(/\+/g,' ')
form.append(decodeURIComponent(name),decodeURIComponent(value))}})
return form}
function headers(xhr){var head=new Headers()
var pairs=(xhr.getAllResponseHeaders()||'').trim().split('\n')
pairs.forEach(function(header){var split=header.trim().split(':')
var key=split.shift().trim()
var value=split.join(':').trim()
head.append(key,value)})
return head}
Body.call(Request.prototype)
function Response(bodyInit,options){if(!options){options={}}
this.type='default'
this.status=options.status
this.ok=this.status>=200&&this.status<300
this.statusText=options.statusText
this.headers=options.headers instanceof Headers?options.headers:new Headers(options.headers)
this.url=options.url||''
this._initBody(bodyInit)}
Body.call(Response.prototype)
Response.prototype.clone=function(){return new Response(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new Headers(this.headers),url:this.url})}
Response.error=function(){var response=new Response(null,{status:0,statusText:''})
response.type='error'
return response}
var redirectStatuses=[301,302,303,307,308]
Response.redirect=function(url,status){if(redirectStatuses.indexOf(status)===-1){throw new RangeError('Invalid status code')}
return new Response(null,{status:status,headers:{location:url}})}
self.Headers=Headers
self.Request=Request
self.Response=Response
self.fetch=function(input,init){return new Promise(function(resolve,reject){var request
if(Request.prototype.isPrototypeOf(input)&&!init){request=input}else{request=new Request(input,init)}
var xhr=new XMLHttpRequest()
function responseURL(){if('responseURL'in xhr){return xhr.responseURL}
if(/^X-Request-URL:/mi.test(xhr.getAllResponseHeaders())){return xhr.getResponseHeader('X-Request-URL')}
return}
xhr.onload=function(){var options={status:xhr.status,statusText:xhr.statusText,headers:headers(xhr),url:responseURL()}
var body='response'in xhr?xhr.response:xhr.responseText
resolve(new Response(body,options))}
xhr.onerror=function(){reject(new TypeError('Network request failed'))}
xhr.ontimeout=function(){reject(new TypeError('Network request failed'))}
xhr.open(request.method,request.url,true)
if(request.credentials==='include'){xhr.withCredentials=true}
if('responseType'in xhr&&support.blob){xhr.responseType='blob'}
request.headers.forEach(function(value,name){xhr.setRequestHeader(name,value)})
xhr.send(typeof request._bodyInit==='undefined'?null:request._bodyInit)})}
self.fetch.polyfill=true})(typeof self!=='undefined'?self:this);