| 3 | | this._map = map; |
| 4 | | this.options = Object.extend( |
| 5 | | { |
| 6 | | reload_data_timeout: 1800, |
| 7 | | rectangle_of_confusion: G_DEFAULT_ICON.iconSize |
| 8 | | } |
| 9 | | , opts || {} ); |
| 10 | | this.options.rectangle_of_confusion = new GSize( this.options.rectangle_of_confusion.width, this.options.rectangle_of_confusion.height ); |
| 11 | | if (this.options.rectangle_of_confusion.width<16) this.options.rectangle_of_confusion.width=16; |
| 12 | | if (this.options.rectangle_of_confusion.height<16) this.options.rectangle_of_confusion.height=16; |
| | 3 | this._map = map; |
| | 4 | this.options = Object.extend( |
| | 5 | { |
| | 6 | reload_data_timeout: 1800, |
| | 7 | rectangle_of_confusion: G_DEFAULT_ICON.iconSize |
| | 8 | } |
| | 9 | , opts || {} ); |
| | 10 | this.options.rectangle_of_confusion = new GSize( this.options.rectangle_of_confusion.width, this.options.rectangle_of_confusion.height ); |
| | 11 | if (this.options.rectangle_of_confusion.width<16) this.options.rectangle_of_confusion.width=16; |
| | 12 | if (this.options.rectangle_of_confusion.height<16) this.options.rectangle_of_confusion.height=16; |
| 38 | | this._urlMapData = urlMapData; |
| 39 | | GEvent.bind( this._map, "movestart", this, this.clearTimerReloadData ); |
| 40 | | GEvent.bind( this._map, "moveend", this, this._onMapMoveEnd ); |
| 41 | | this._loadData(); |
| | 38 | this._urlMapData = urlMapData; |
| | 39 | GEvent.bind( this._map, "movestart", this, this.clearTimerReloadData ); |
| | 40 | GEvent.bind( this._map, "moveend", this, this._onMapMoveEnd ); |
| | 41 | this._loadData(); |
| 81 | | var latRange = bounds.toSpan().lat(); |
| 82 | | var latPrec = latRange * this.options.rectangle_of_confusion.height / this._map.getSize().height; |
| | 79 | // BEGIN BUG in maps api 2.185 up to "today" 2.193 - when map wraps horizontally more than 360 deg - the getBounds is wrong |
| | 80 | if ( this._map.getZoom() <= 2 ) |
| | 81 | { |
| | 82 | bounds = new GLatLngBounds( |
| | 83 | new GLatLng( bounds.getSouthWest().lat(), -180 ), |
| | 84 | new GLatLng( bounds.getNorthEast().lat(), 180 ) |
| | 85 | ); |
| | 86 | } |
| | 87 | // END BUG |
| | 88 | var latRange = bounds.toSpan().lat(); |
| | 89 | var latPrec = latRange * this.options.rectangle_of_confusion.height / this._map.getSize().height; |
| 87 | | if ( this._previousLoadDataReq.box!=null ) |
| 88 | | { // not the first time |
| 89 | | if ( this._previousLoadDataReq.box.containsBounds( bounds ) ) |
| 90 | | { |
| 91 | | if ( this._previousLoadDataReq.resultBounds == null ) |
| 92 | | return; // no images here |
| 93 | | if ( this._map.getZoom() <= this._previousLoadDataReq.zoom ) |
| 94 | | return; |
| 95 | | else |
| 96 | | { |
| 97 | | if ( |
| 98 | | this._map.getZoom() == this._previousLoadDataReq.zoom + 1 |
| 99 | | && this._map.getZoom() < this._map.getBoundsZoomLevel(this._previousLoadDataReq.resultBounds) |
| 100 | | ) |
| 101 | | { |
| 102 | | if (document.is_debug) GLog.write('no load: zoom crt: '+this._map.getZoom()+'; prev: '+this._previousLoadDataReq.zoom+'; target: '+this._map.getBoundsZoomLevel(this._previousLoadDataReq.resultBounds)); |
| 103 | | return; |
| 104 | | } |
| 105 | | } |
| 106 | | } |
| 107 | | else |
| 108 | | { |
| 109 | | } |
| 110 | | } |
| | 94 | if ( this._previousLoadDataReq.box!=null ) |
| | 95 | { // not the first time |
| | 96 | if ( this._previousLoadDataReq.box.containsBounds( bounds ) ) |
| | 97 | { |
| | 98 | if ( this._previousLoadDataReq.resultBounds == null ) |
| | 99 | return; // no images here |
| | 100 | if ( this._map.getZoom() <= this._previousLoadDataReq.zoom ) |
| | 101 | return; |
| | 102 | else |
| | 103 | { |
| | 104 | if ( |
| | 105 | this._map.getZoom() == this._previousLoadDataReq.zoom + 1 |
| | 106 | && this._map.getZoom() < this._map.getBoundsZoomLevel(this._previousLoadDataReq.resultBounds) |
| | 107 | ) |
| | 108 | { |
| | 109 | if (document.is_debug) GLog.write('no load: zoom crt: '+this._map.getZoom()+'; prev: '+this._previousLoadDataReq.zoom+'; target: '+this._map.getBoundsZoomLevel(this._previousLoadDataReq.resultBounds)); |
| | 110 | return; |
| | 111 | } |
| | 112 | } |
| | 113 | } |
| | 114 | else |
| | 115 | { |
| | 116 | } |
| | 117 | } |
| 112 | | var nd=0, sd=0, ed=0, wd=0; |
| 113 | | if ( !bounds.isFullLat() ) |
| 114 | | { |
| 115 | | nd = latRange*12/100; |
| 116 | | sd = latRange*4/100; |
| 117 | | } |
| 118 | | if ( !bounds.isFullLng() ) |
| 119 | | { |
| 120 | | ed = lonRange*9/100; |
| 121 | | wd = lonRange*7/100; |
| 122 | | } |
| 123 | | var digits = Math.max( getLatLonDigits(latRange,4,2), getLatLonDigits(lonRange,4,2) ); |
| 124 | | var box = new GLatLngBounds( |
| 125 | | new GLatLng( Math.roundN(bounds.getSouthWest().lat()-sd,digits), Math.roundN( bounds.getSouthWest().lng()-wd,digits ) ), |
| 126 | | new GLatLng( Math.roundN(bounds.getNorthEast().lat()+nd,digits), Math.roundN(bounds.getNorthEast().lng()+ed,digits) ) |
| 127 | | ); |
| 128 | | |
| 129 | | var url = this._urlMapData; |
| 130 | | url += "&box=" + box.getSouthWest().toUrlValue(5) + "," + box.getNorthEast().toUrlValue(5); |
| 131 | | url += "&lap=" + Math.roundN( latPrec, getLatLonDigits(latPrec,1,1) ).toString(); |
| 132 | | url += "&lop=" + Math.roundN( lonPrec, getLatLonDigits(lonPrec,1,1) ).toString(); |
| 133 | | |
| 134 | | if (document.is_debug) { |
| 135 | | GLog.write( "bounds: " + bounds.getSouthWest().toUrlValue() + " " + bounds.getNorthEast().toUrlValue() +"; zoom: "+this._map.getZoom() +"; size: "+this._map.getSize().toString() +"; c: "+this._map.getCenter().toUrlValue() ); |
| 136 | | GLog.writeUrl( url ); |
| 137 | | } |
| 138 | | |
| 139 | | this._previousLoadDataReq.box = box; |
| 140 | | this._previousLoadDataReq.zoom = this._map.getZoom(); |
| 141 | | this._previousLoadDataReq.resultBounds = null; |
| 142 | | this._dataLoading = true; |
| | 119 | var nd=0, sd=0, ed=0, wd=0; |
| | 120 | if ( !bounds.isFullLat() ) |
| | 121 | { |
| | 122 | nd = latRange*12/100; |
| | 123 | sd = latRange*4/100; |
| | 124 | } |
| | 125 | if ( !bounds.isFullLng() ) |
| | 126 | { |
| | 127 | ed = lonRange*9/100; |
| | 128 | wd = lonRange*7/100; |
| | 129 | } |
| | 130 | var digits = Math.max( getLatLonDigits(latRange,4,2), getLatLonDigits(lonRange,4,2) ); |
| | 131 | var box = new GLatLngBounds( |
| | 132 | new GLatLng( Math.roundN(bounds.getSouthWest().lat()-sd,digits), Math.roundN( bounds.getSouthWest().lng()-wd,digits ) ), |
| | 133 | new GLatLng( Math.roundN(bounds.getNorthEast().lat()+nd,digits), Math.roundN( bounds.getNorthEast().lng()+ed,digits) ) |
| | 134 | ); |
| 144 | | try { |
| 145 | | GEvent.trigger( this, "dataloading" ); |
| 146 | | GDownloadUrl(url, this._onDataReceived.bind(this) ); |
| 147 | | } |
| 148 | | catch (e) { |
| 149 | | this._dataLoading = false; |
| 150 | | this._previousLoadDataReq.box=null; |
| 151 | | GEvent.trigger( this, "dataloadfailed", 600, e ); |
| 152 | | } |
| | 136 | var url = this._urlMapData; |
| | 137 | url += "&box=" + box.getSouthWest().toUrlValue(5) + "," + box.getNorthEast().toUrlValue(5); |
| | 138 | url += "&lap=" + Math.roundN( latPrec, getLatLonDigits(latPrec,1,1) ).toString(); |
| | 139 | url += "&lop=" + Math.roundN( lonPrec, getLatLonDigits(lonPrec,1,1) ).toString(); |
| | 140 | |
| | 141 | if (document.is_debug) { |
| | 142 | GLog.write( "bounds: " + this._map.getBounds().getSouthWest().toUrlValue() + " " + this._map.getBounds().getNorthEast().toUrlValue() +"; zoom: "+this._map.getZoom() +"; size: "+this._map.getSize().toString() +"; c: "+this._map.getCenter().toUrlValue() ); |
| | 143 | GLog.writeUrl( url ); |
| | 144 | } |
| | 145 | |
| | 146 | this._previousLoadDataReq.box = box; |
| | 147 | this._previousLoadDataReq.zoom = this._map.getZoom(); |
| | 148 | this._previousLoadDataReq.resultBounds = null; |
| | 149 | this._dataLoading = true; |
| | 150 | |
| | 151 | try { |
| | 152 | GEvent.trigger( this, "dataloading" ); |
| | 153 | GDownloadUrl(url, this._onDataReceived.bind(this) ); |
| | 154 | } |
| | 155 | catch (e) { |
| | 156 | this._dataLoading = false; |
| | 157 | this._previousLoadDataReq.box=null; |
| | 158 | GEvent.trigger( this, "dataloadfailed", 600, e ); |
| | 159 | } |
| 157 | | var resp; |
| 158 | | try |
| 159 | | { |
| 160 | | if (responseCode!=200) |
| 161 | | { |
| 162 | | this._previousLoadDataReq.box=null; |
| 163 | | GEvent.trigger( this, "dataloadfailed", responseCode, null ); |
| 164 | | } |
| 165 | | else |
| 166 | | try |
| 167 | | { |
| 168 | | eval('resp = ' + data); |
| 169 | | if (resp.nb_items == undefined) |
| 170 | | throw new Error( "DATA DECODING ERROR" ); |
| | 164 | var resp; |
| | 165 | try |
| | 166 | { |
| | 167 | if (responseCode!=200) |
| | 168 | { |
| | 169 | this._previousLoadDataReq.box=null; |
| | 170 | GEvent.trigger( this, "dataloadfailed", responseCode, null ); |
| | 171 | } |
| | 172 | else |
| | 173 | try |
| | 174 | { |
| | 175 | eval('resp = ' + data); |
| | 176 | if (resp.nb_items == undefined) |
| | 177 | throw new Error( "DATA DECODING ERROR" ); |
| 172 | | this._previousLoadDataReq.resultBounds = resp.bounds; |
| 173 | | if (document.is_debug && resp.debug) GLog.write( resp.debug ); |
| 174 | | GEvent.trigger( this, "dataloaded", resp ); |
| 175 | | } |
| 176 | | catch (e) { |
| 177 | | this._previousLoadDataReq.box=null; |
| 178 | | GEvent.trigger( this, "dataloadfailed", responseCode, e ); |
| 179 | | var s = e.message; |
| 180 | | s += '\n' + data.substr(0,1000); |
| 181 | | alert( s ); |
| 182 | | } |
| 183 | | } |
| 184 | | finally { |
| 185 | | this._dataLoading = false; |
| 186 | | } |
| | 179 | this._previousLoadDataReq.resultBounds = resp.bounds; |
| | 180 | if (document.is_debug && resp.debug) GLog.write( resp.debug ); |
| | 181 | GEvent.trigger( this, "dataloaded", resp ); |
| | 182 | } |
| | 183 | catch (e) { |
| | 184 | this._previousLoadDataReq.box=null; |
| | 185 | GEvent.trigger( this, "dataloadfailed", responseCode, e ); |
| | 186 | var s = e.message; |
| | 187 | s += '\n' + data.substr(0,1000); |
| | 188 | alert( s ); |
| | 189 | } |
| | 190 | } |
| | 191 | finally { |
| | 192 | this._dataLoading = false; |
| | 193 | } |