Created
June 28, 2010 13:49
-
-
Save thinkphp/455859 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| MooGeo_map={};var MooGeo=new Class({Implements:[Options,Events],options:{endpoint:"http://query.yahooapis.com/v1/public/yql?q=",format:"json",injectScript:document.head},initialize:function(){var args=arguments;for(var i=0;i<args.length;i++){if(typeof args[i]==="object"&&typeof args[i].join==="undefined"){this.setOptions(args[i])}}if(args[0]==="ipvisitor"){this.grabIP()}if(args[0]==="visitor"){this.getVisitor()}if(typeof args[0]==="string"&&args[0]!="visitor"&&args[0]!="ipvisitor"){if(args[0]){if(/^http:\/\/.*/.test(args[0])){this.getFromURL(args[0])}else{if(/^[\d+\.?]+$/.test(args[0])){this.getFromIP(args[0])}else{this.getFromText(args[0])}}}}var lat=args[0],lon=args[1];if(typeof lat.join!=="undefined"&&args[0][1]){lat=args[0][0];lon=args[0][1]}if(isFinite(lat)&&isFinite(lon)){if(lat>-90&&lat<90&&lon>-180&&lon<180){this.getFromLatLon(lat,lon)}}},getFromIP:function(ip){var yql="select * from geo.places where woeid in (select place.woeid from flickr.places where (lat,lon) in (select Latitude,Longitude from ip.location where ip='"+ip+"'))";this.fireEvent("request",yql);if(window.console){console.log(yql)}this.load(yql,"MooGeo_map.request")},load:function(yql,cb){if(document.id("yqlgeodata")){var old=document.id("yqlgeodata");old.parentNode.removeChild(old)}var src=this.options.endpoint+encodeURIComponent(yql)+"&format="+this.options.format+"&callback="+cb+"&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys";new Element("script",{id:"yqlgeodata",src:src}).inject(this.options.injectScript);MooGeo_map.request=function(data){this.retrieved(data)}.bind(this)},retrieved:function(o){if(o.query.results){this.fireEvent("complete",o.query.results).fireEvent("success",o.query.results)}else{this.fireEvent("failure",{error:o.query}).fireEvent("error",{error:o.query})}},grabIP:function(){this.fireEvent("request");this.jsonp("http://jsonip.appspot.com/?callback=MooGeo_map.request")},jsonp:function(src){if(document.id("yqlgeodata")){var old=document.id("yqlgeodata");old.parentNode.removeChild(old)}new Element("script",{id:"yqlgeodata",src:src}).inject(this.options.injectScript);MooGeo_map.request=function(data){this.ipgrab(data)}.bind(this);MooGeo_map.ipin=function(data){this.ipin(data)}.bind(this)},ipin:function(o){this.getFromIP(o.ip)},ipgrab:function(o){if(o.ip){this.fireEvent("complete",{ip:o.ip}).fireEvent("success",{ip:o.ip})}else{this.fireEvent("failure",{error:"Internal Error"}).fireEvent("error",{error:"Internal Error"})}},getVisitor:function(){if(navigator.geolocation){navigator.geolocation.getCurrentPosition(function(position){this.getFromLatLon(position.coords.latitude,position.coords.longitude)}.bind(this),function(error){this.retrieveIP()}.bind(this))}else{this.retrieveIP()}},retrieveIP:function(){this.fireEvent("request");this.jsonp("http://jsonip.appspot.com/?callback=MooGeo_map.ipin")},getFromLatLon:function(lat,lon){var yql="select * from geo.places where woeid in (select place.woeid from flickr.places where lat='"+lat+"' and lon='"+lon+"')";this.fireEvent("request",yql);if(window.console){console.log(yql)}this.load(yql,"MooGeo_map.request")},getFromText:function(text){var yql="select * from geo.places where woeid in (select match.place.woeId from geo.placemaker where documentContent='"+text+"' and documentType='text/plain' and appid='')";this.fireEvent("request",yql);if(window.console){console.log(yql)}this.load(yql,"MooGeo_map.request")},getFromURL:function(url){var yql="select * from geo.places where woeid in (select match.place.woeId from geo.placemaker where documentURL='"+url+"' and documentType='text/html' and appid='')";this.fireEvent("request",yql);if(window.console){console.log(yql)}this.load(yql,"MooGeo_map.request")}}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment