/* MAPSTRACTION vtimemap http://www.mapstraction.com Copyright (c) 2011 Tom Carden, Steve Coast, Mikel Maron, Andrew Turner, Henri Bergius, Rob Moran, Derek Fowler, Gary Gale All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the Mapstraction nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ (function(){var $m=mxn.util.$m;var init=function(){this.invoker.go("init",[this.currentElement,this.api]);this.applyOptions()};var Mapstraction=mxn.Mapstraction=function(element,api,debug){if(!api){api=mxn.util.getAvailableProviders()[0]}this.api=api;this.maps={};this.currentElement=$m(element);this.eventListeners=[];this.markers=[];this.polylines=[];this.images=[];this.controls=[];this.loaded={};this.onload={};this.onload[api]=[];this.element=element;this.options={enableScrollWheelZoom:false,enableDragging:true,enableMultipleBubbles:false};this.addControlsArgs={};this.invoker=new mxn.Invoker(this,"Mapstraction",function(){return this.api});mxn.addEvents(this,["load","click","endPan","changeZoom","markerAdded","markerRemoved","polylineAdded","polylineRemoved"]);init.apply(this)};Mapstraction.ROAD=1;Mapstraction.SATELLITE=2;Mapstraction.HYBRID=3;Mapstraction.PHYSICAL=4;mxn.addProxyMethods(Mapstraction,["addLargeControls","addMapTypeControls","addOverlay","addSmallControls","applyOptions","getBounds","getCenter","getMapType","getPixelRatio","getZoom","getZoomLevelForBoundingBox","mousePosition","resizeTo","setBounds","setCenter","setCenterAndZoom","setMapType","setZoom","toggleTileLayer","openBubble","closeBubble"]);Mapstraction.prototype.setOptions=function(oOpts){mxn.util.merge(this.options,oOpts);this.applyOptions()};Mapstraction.prototype.setOption=function(sOptName,vVal){this.options[sOptName]=vVal;this.applyOptions()};Mapstraction.prototype.enableScrollWheelZoom=function(){this.setOption("enableScrollWheelZoom",true)};Mapstraction.prototype.dragging=function(on){this.setOption("enableDragging",on)};Mapstraction.prototype.swap=function(element,api){if(this.api===api){return}var center=this.getCenter();var zoom=this.getZoom();this.currentElement.style.visibility="hidden";this.currentElement.style.display="none";this.currentElement=$m(element);this.currentElement.style.visibility="visible";this.currentElement.style.display="block";this.api=api;this.onload[api]=[];if(this.maps[this.api]===undefined){init.apply(this);for(var i=0;i0){this.onload[this.api].shift().apply(this)}};Mapstraction.prototype.clickHandler=function(lat,lon,me){this.callEventListeners("click",{location:new LatLonPoint(lat,lon)})};Mapstraction.prototype.moveendHandler=function(me){this.callEventListeners("moveend",{})};Mapstraction.prototype.addEventListener=function(){var listener={};listener.event_type=arguments[0];listener.callback_function=arguments[1];if(arguments.length==3){listener.back_compat_mode=false;listener.callback_object=arguments[2]}else{listener.back_compat_mode=true;listener.callback_object=null}this.eventListeners.push(listener)};Mapstraction.prototype.callEventListeners=function(sEventType,oEventArgs){oEventArgs.source=this;for(var i=0;i0){current_marker=this.markers.pop();this.invoker.go("removeMarker",[current_marker])}};Mapstraction.prototype.declutterMarkers=function(opts){if(this.loaded[this.api]===false){var me=this;this.onload[this.api].push(function(){me.declutterMarkers(opts)});return}var map=this.maps[this.api];switch(this.api){case"multimap":map.declutterGroup(opts.groupName);break;case" dummy":break;default:if(this.debug){alert(this.api+" not supported by Mapstraction.declutterMarkers")}}};Mapstraction.prototype.addPolyline=function(polyline,old){polyline.api=this.api;polyline.map=this.maps[this.api];var propPoly=this.invoker.go("addPolyline",arguments);polyline.setChild(propPoly);if(!old){this.polylines.push(polyline)}this.polylineAdded.fire({polyline:polyline})};var removePolylineImpl=function(polyline){this.invoker.go("removePolyline",arguments);polyline.onmap=false;this.polylineRemoved.fire({polyline:polyline})};Mapstraction.prototype.removePolyline=function(polyline){var current_polyline;for(var i=0;i0){current_polyline=this.polylines.pop();removePolylineImpl.call(this,current_polyline)}};Mapstraction.prototype.autoCenterAndZoom=function(){var lat_max=-90;var lat_min=90;var lon_max=-180;var lon_min=180;var lat,lon;var checkMinMax=function(){if(lat>lat_max){lat_max=lat}if(latlon_max){lon_max=lon}if(lonlat_max){lat_max=lat}if(latlon_max){lon_max=lon}if(lon0){latConv=(radius/mapstraction.polylines[i].points[j].latConv());lonConv=(radius/mapstraction.polylines[i].points[j].lonConv())}if((lat+latConv)>lat_max){lat_max=(lat+latConv)}if((lat-latConv)lon_max){lon_max=(lon+lonConv)}if((lon-lonConv)=100){opacity=100}var c=opacity/100;var d=document.getElementById(id);if(typeof(d.style.filter)=="string"){d.style.filter="alpha(opacity:"+opacity+")"}if(typeof(d.style.KHTMLOpacity)=="string"){d.style.KHTMLOpacity=c}if(typeof(d.style.MozOpacity)=="string"){d.style.MozOpacity=c}if(typeof(d.style.opacity)=="string"){d.style.opacity=c}};Mapstraction.prototype.setImagePosition=function(id){var imgElement=document.getElementById(id);var oContext={latLng:{top:imgElement.getAttribute("north"),left:imgElement.getAttribute("west"),bottom:imgElement.getAttribute("south"),right:imgElement.getAttribute("east")},pixels:{top:0,right:0,bottom:0,left:0}};this.invoker.go("setImagePosition",arguments,{context:oContext});imgElement.style.top=oContext.pixels.top.toString()+"px";imgElement.style.left=oContext.pixels.left.toString()+"px";imgElement.style.width=(oContext.pixels.right-oContext.pixels.left).toString()+"px";imgElement.style.height=(oContext.pixels.bottom-oContext.pixels.top).toString()+"px"};Mapstraction.prototype.addJSON=function(json){var features;if(typeof(json)=="string"){features=eval("("+json+")")}else{features=json}features=features.features;var map=this.maps[this.api];var html="";var item;var polyline;var marker;var markers=[];if(features.type=="FeatureCollection"){this.addJSON(features.features)}for(var i=0;i"+item.title+"

"+item.description+"

";marker=new Marker(new LatLonPoint(item.geometry.coordinates[1],item.geometry.coordinates[0]));markers.push(marker);this.addMarkerWithData(marker,{infoBubble:html,label:item.title,date:'new Date("'+item.date+'")',iconShadow:item.icon_shadow,marker:item.id,iconShadowSize:item.icon_shadow_size,icon:item.icon,iconSize:item.icon_size,category:item.source_id,draggable:false,hover:false});break;case"Polygon":var points=[];polyline=new Polyline(points);mapstraction.addPolylineWithData(polyline,{fillColor:item.poly_color,date:'new Date("'+item.date+'")',category:item.source_id,width:item.line_width,opacity:item.line_opacity,color:item.line_color,polygon:true});markers.push(polyline);break;default:}}return markers};Mapstraction.prototype.addTileLayer=function(tile_url,opacity,copyright_text,min_zoom,max_zoom,map_type){if(!tile_url){return}this.tileLayers=this.tileLayers||[];opacity=opacity||0.6;copyright_text=copyright_text||"Mapstraction";min_zoom=min_zoom||1;max_zoom=max_zoom||18;map_type=map_type||false;return this.invoker.go("addTileLayer",[tile_url,opacity,copyright_text,min_zoom,max_zoom,map_type])};Mapstraction.prototype.addFilter=function(field,operator,value){if(!this.filters){this.filters=[]}this.filters.push([field,operator,value])};Mapstraction.prototype.removeFilter=function(field,operator,value){if(!this.filters){return}var del;for(var f=0;ff[2]){vis=false}break;case"eq":if(o.getAttribute(f[0])==f[2]){vis=false}break}return vis};Mapstraction.prototype.getAttributeExtremes=function(field){var min;var max;for(var m=0;mthis.markers[m].getAttribute(field)){min=this.markers[m].getAttribute(field)}if(!max||maxthis.polylines[p].getAttribute(field)){min=this.polylines[p].getAttribute(field)}if(!max||max=this.sw.lat&&point.lat<=this.ne.lat&&point.lon>=this.sw.lon&&point.lon<=this.ne.lon};BoundingBox.prototype.toSpan=function(){return new LatLonPoint(Math.abs(this.sw.lat-this.ne.lat),Math.abs(this.sw.lon-this.ne.lon))};BoundingBox.prototype.extend=function(point){var box=this;if(box.sw.lat===undefined||box.sw.lat>point.lat){box.sw.lat=point.lat}if(box.sw.lon===undefined||box.sw.lon>point.lon){box.sw.lon=point.lon}if(box.ne.lat===undefined||box.ne.lat=tolerance){reduced[reduced.length]=this.points[i];markerPoint=i}}reduced[reduced.length]=this.points[this.points.length-1];this.points=reduced};var Radius=mxn.Radius=function(center,quality){this.center=center;var latConv=center.latConv();var lonConv=center.lonConv();var rad=Math.PI/180;this.calcs=[];for(var i=0;i<360;i+=quality){this.calcs.push([Math.cos(i*rad)/latConv,Math.sin(i*rad)/lonConv])}};Radius.prototype.getPolyline=function(radius,color){var points=[];for(var i=0;i