javascript - google-maps marker location -
ok... below js web template - can't find update map marker location lat , long.
/*! * jquery fn google map 3.0-rc * http://code.google.com/p/jquery-ui-map/ * copyright (c) 2010 - 2012 johan säll larsson * licensed under mit license: http://www.opensource.org/licenses/mit-license.php */ ( function($) { /** * @param name:string * @param prototype:object */ $.a = function(name, prototype) { var namespace = name.split('.')[0]; name = name.split('.')[1]; $[namespace] = $[namespace] || {}; $[namespace][name] = function(options, element) { if ( arguments.length ) { this._setup(options, element); } }; $[namespace][name].prototype = $.extend({ 'namespace': namespace, 'pluginname': name }, prototype); $.fn[name] = function(options) { var ismethodcall = typeof options === "string", args = array.prototype.slice.call(arguments, 1), returnvalue = this; if ( ismethodcall && options.substring(0, 1) === '_' ) { return returnvalue; } this.each(function() { var instance = $.data(this, name); if (!instance) { instance = $.data(this, name, new $[namespace][name](options, this)); } if (ismethodcall) { returnvalue = instance[options].apply(instance, args); } }); return returnvalue; }; }; $.a('ui.gmap', { /** * map options * @see http://code.google.com/intl/sv-se/apis/maps/documentation/javascript/reference.html#mapoptions */ options: { maptypeid: 'roadmap', zoom: 5 }, /** * or set options * @param key:string * @param options:object * @return object */ option: function(key, options) { if (options) { this.options[key] = options; this.get('map').set(key, options); return this; } return this.options[key]; }, /** * setup plugin basics, * @param options:object * @param element:node */ _setup: function(options, element) { this.el = element; options = options || {}; jquery.extend(this.options, options, { 'center': this._latlng(options.center) }); this._create(); if ( this._init ) { this._init(); } }, /** * instanciate google maps object */ _create: function() { var self = this; this.instance = { 'map': new google.maps.map(self.el, self.options), 'markers': [], 'overlays': [], 'services': [] }; google.maps.event.addlisteneronce(self.instance.map, 'bounds_changed', function() { $(self.el).trigger('init', self.instance.map); }); self._call(self.options.callback, self.instance.map); }, /** * adds latitude longitude pair bounds. * @param position:google.maps.latlng/string */ addbounds: function(position) { var bounds = this.get('bounds', new google.maps.latlngbounds()); bounds.extend(this._latlng(position)); this.get('map').fitbounds(bounds); return this; }, /** * helper function check if latlng within viewport * @param marker:google.maps.marker */ inviewport: function(marker) { var bounds = this.get('map').getbounds(); return (bounds) ? bounds.contains(marker.getposition()) : false; }, /** * adds custom control map * @param panel:jquery/node/string * @param position:google.maps.controlposition * @see http://code.google.com/intl/sv-se/apis/maps/documentation/javascript/reference.html#controlposition */ addcontrol: function(panel, position) { this.get('map').controls[position].push(this._unwrap(panel)); return this; }, /** * adds marker map * @param markeroptions:google.maps.markeroptions * @param callback:function(map:google.maps.map, marker:google.maps.marker) (optional) * @return $(google.maps.marker) * @see http://code.google.com/intl/sv-se/apis/maps/documentation/javascript/reference.html#markeroptions */ addmarker: function(markeroptions, callback) { markeroptions.map = this.get('map'); markeroptions.position = this._latlng(markeroptions.position); var marker = new (markeroptions.marker || google.maps.marker)(markeroptions); var markers = this.get('markers'); if ( marker.id ) { markers[marker.id] = marker; } else { markers.push(marker); } if ( marker.bounds ) { this.addbounds(marker.getposition()); } this._call(callback, markeroptions.map, marker); return $(marker); }, /** * clears type * @param ctx:string e.g. 'markers', 'overlays', 'services' */ clear: function(ctx) { this._c(this.get(ctx)); this.set(ctx, []); return this; }, _c: function(obj) { ( var property in obj ) { if ( obj.hasownproperty(property) ) { if ( obj[property] instanceof google.maps.mvcobject ) { google.maps.event.clearinstancelisteners(obj[property]); if ( obj[property].setmap ) { obj[property].setmap(null); } } else if ( obj[property] instanceof array ) { this._c(obj[property]); } obj[property] = null; } } }, /** * returns objects specific property , value, e.g. 'category', 'tags' * @param ctx:string in context, e.g. 'markers' * @param options:object property:string property search within, value:string, operator:string (optional) (and/or) * @param callback:function(marker:google.maps.marker, isfound:boolean) */ find: function(ctx, options, callback) { var obj = this.get(ctx); options.value = $.isarray(options.value) ? options.value : [options.value]; ( var property in obj ) { if ( obj.hasownproperty(property) ) { var isfound = false; ( var value in options.value ) { if ( $.inarray(options.value[value], obj[property][options.property]) > -1 ) { isfound = true; } else { if ( options.operator && options.operator === 'and' ) { isfound = false; break; } } } callback(obj[property], isfound); } } return this; }, /** * returns instance property key. has ability set object if property not exist * @param key:string * @param value:object(optional) */ get: function(key, value) { var instance = this.instance; if ( !instance[key] ) { if ( key.indexof('>') > -1 ) { var e = key.replace(/ /g, '').split('>'); ( var = 0; < e.length; i++ ) { if ( !instance[e[i]] ) { if (value) { instance[e[i]] = ( (i + 1) < e.length ) ? [] : value; } else { return null; } } instance = instance[e[i]]; } return instance; } else if ( value && !instance[key] ) { this.set(key, value); } } return instance[key]; }, /** * triggers infowindow open * @param infowindowoptions:google.maps.infowindowoptions * @param marker:google.maps.marker (optional) * @param callback:function (optional) * @see http://code.google.com/intl/sv-se/apis/maps/documentation/javascript/reference.html#infowindowoptions */ openinfowindow: function(infowindowoptions, marker, callback) { var iw = this.get('iw', infowindowoptions.infowindow || new google.maps.infowindow); iw.setoptions(infowindowoptions); iw.open(this.get('map'), this._unwrap(marker)); this._call(callback, iw); return this; }, /** * triggers infowindow close */ closeinfowindow: function() { if ( this.get('iw') != null ) { this.get('iw').close(); } return this; }, /** * sets instance property * @param key:string * @param value:object */ set: function(key, value) { this.instance[key] = value; return this; }, /** * refreshes map */ refresh: function() { var map = this.get('map'); var latlng = map.getcenter(); $(map).triggerevent('resize'); map.setcenter(latlng); return this; }, /** * destroys plugin. */ destroy: function() { this.clear('markers').clear('services').clear('overlays')._c(this.instance); jquery.removedata(this.el, this.name); }, /** * helper method calling function * @param callback */ _call: function(callback) { if ( callback && $.isfunction(callback) ) { callback.apply(this, array.prototype.slice.call(arguments, 1)); } }, /** * helper method google.maps.latlng * @param latlng:string/google.maps.latlng */ _latlng: function(latlng) { if ( !latlng ) { return new google.maps.latlng(0.0, 0.0); } if ( latlng instanceof google.maps.latlng ) { return latlng; } else { latlng = latlng.replace(/ /g,'').split(','); return new google.maps.latlng(latlng[0], latlng[1]); } }, /** * helper method unwrapping jquery/dom/string elements * @param obj:string/node/jquery */ _unwrap: function(obj) { return (!obj) ? null : ( (obj instanceof jquery) ? obj[0] : ((obj instanceof object) ? obj : $('#'+obj)[0]) ) } }); jquery.fn.extend( { triggerevent: function(eventtype) { google.maps.event.trigger(this[0], eventtype); return this; }, addeventlistener: function(eventtype, eventdataorcallback, eventcallback) { if ( google.maps && this[0] instanceof google.maps.mvcobject ) { google.maps.event.addlistener(this[0], eventtype, eventdataorcallback); } else { if (eventcallback) { this.bind(eventtype, eventdataorcallback, eventcallback); } else { this.bind(eventtype, eventdataorcallback); } } return this; } /*removeeventlistener: function(eventtype) { if ( google.maps && this[0] instanceof google.maps.mvcobject ) { if (eventtype) { google.maps.event.clearlisteners(this[0], eventtype); } else { google.maps.event.clearinstancelisteners(this[0]); } } else { this.unbind(eventtype); } return this; }*/ }); jquery.each(('click rightclick dblclick mouseover mouseout drag dragend').split(' '), function(i, name) { jquery.fn[name] = function(a, b) { return this.addeventlistener(name, a, b); } }); } (jquery) );
Comments
Post a Comment