/** * Tosom Google Maps Handler * * @licence; * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! * * It's strictly prohibited the use, re-use, copy, re-sell or alteration * of this code without the explicit consent from Tosom s.r.l. * email: info[at]tosom.it * * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! * * @author: Toniolo Marco * @version: 1.1 * * @uses: jQuery and GoogleMaps Api * * @features: * - create google maps * - hadle basic and controls options * - create/set markers * - handle markers icons * - create info-windows * * @Updates * 1.1 * - Better info doc with all usable parmaters. * - Verified loading * - Fixed the gmap id in initMap * - Removed function "trace(...)" reverted back to console.log * - Added attribute "debug" * */ /** * TOSOM GMAP CLASS * @param o * id : the HTML map id * center : [LAT,LON] * zoom : [0,n] * zoomMin : [0,n] * zoomMax : [0,n] * minZoom : Alias for zoomMin * maxZoom : Alias for zoomMax * mapTypeId : The google map type like "roadmap"(default), "satellite", "hybrid", "terrain" * styles : WIth the gmap styles to apply Refer to https://mapstyle.withgoogle.com/ * poi : * controls : * confCtrl["wheel"] : * confCtrl["drag"] : * confCtrl["zoom"] : * confCtrl["scale"] : * confCtrl["type"] : * confCtrl["streetView"] : * confCtrl["fullscreen"] : * markers : Of object containing markers configurations: * position : [LAT,LON] * title : The Marker Title * icon : The path for the icon * */ function TosomMap(o) { var conf = false ; var elem = false ; var self = false ; var gmap = false ; var gmapOpts = false ; var debug = true ; function build(o) { // Check debug mode if( debug===true ) { console.log("") } //{ debug=true; delete conf.debug ; } self=this; // Scope Hack conf=o ; // quick options assign // CHECK OPTIONS EXISTENCE if( typeof o != "object" ){ console.log("TOSOM GMAP:: BUILD ERROR"+"0x001"); return ; } conf = o ; // Setup map options from configuration gmapOpts = confToGmap() // CHECK CONF MANDATORY FIELDS if( typeof conf.id=="undefiend" ){ console.log("TOSOM GMAP:: BUILD ERROR"+"0x002"); return ; } elem = jQuery( "#"+conf.id ) if( !elem || elem.length!=1 ){ console.log("TOSOM GMAP:: BUILD ERROR"+"0x003"); return ; } initGmap(); } /** Convert configuration into google map compliant options */ function confToGmap() { if( typeof conf != "object" ){ return false ; } // SET DAFAULT GMAP OPTS var tmp = { center : new google.maps.LatLng(45,12), zoom : 10 , zoomMin : 5 , zoomMax : 15 , mapTypeId : "roadmap" , styles : [] } ; // OVERRIDE AND APPLY CUSTOM GMAP OPTIONS for( var key in conf ) { switch(key) { case "center": tmp.center = aToLL(conf[key]) ; break ; case "zoom": if(!isNaN(conf[key]) && conf[key]>0 ) { tmp.zoom=conf[key]; } break ; case "zoomMin": case "minZoom": if(!isNaN(conf[key]) && conf[key]>0 ) { tmp.minZoom=conf[key]; } break ; case "zoomMax": case "maxZoom": if(!isNaN(conf[key]) && conf[key]>0 ) { tmp.maxZoom=conf[key]; } break ; case "type": // roadmap, satellite, hybrid, terrain if( conf[key]=="roadmap" || conf[key]=="satellite" || conf[key]=="hybrid" || conf[key]=="terrain" ) { tmp.mapTypeId=conf[key] } break ; // Points Of Interests and Styles case "poi" : if( conf[key]===false ) {tmp.styles.push( {featureType:"poi",stylers:[{visibility:"off"}]} )} break ; case "styles": for( var j=0 ; j"); } var tmp = false ; var gopts = false ; var gmark = false ; var ginfo = false ; gmap = new google.maps.Map(document.getElementById(conf.id),gmapOpts); if( typeof conf.markers !="undefined" ) { if(debug){console.log("<|-- TOSOM GMAP SETUP MARKERS -->") ;} for( var i=0 ; i") ;} gopts = { position : aToLL(tmp.pos) , title : (typeof tmp.title=="string"?tmp.title:"") , map : gmap , draggable : false , animation : google.maps.Animation.DROP, } if( typeof tmp.icon=="string" ) { gopts.icon = { url : tmp.icon /*size : new google.maps.Size(40,79), origin : new google.maps.Point(0,0), // origin anchor : new google.maps.Point(0,0) // anchor*/ }; } gmark = new google.maps.Marker(gopts); if(debug) { console.log( (typeof tmp.icon=="string"?{ url : tmp.icon /*size : new google.maps.Size(40,79), origin : new google.maps.Point(0,0), // origin anchor : new google.maps.Point(0,0) // anchor*/ }:false ) ) } if( typeof tmp.info=="object" ) { if( debug ) { console.log( "<|-- ENABLE INFO WINDOW ON CLICK -->" ); } ginfo = new google.maps.InfoWindow({ content : typeof tmp.info.content=="string"?tmp.info.content: "" , maxWidth : typeof tmp.info.sizeMax=="object"?tmp.info.sizeMax[0]:200 , maxHeight : typeof tmp.info.sizeMax=="object"?tmp.info.sizeMax[1]:140 }); google.maps.event.addListener(gmark, 'click', function(){ginfo.open(gmap,gmark);}); if( typeof tmp.info.auto !="undefined" && tmp.info.auto===true ) {google.maps.event.trigger(gmark,'click');} } } } } build(o); }