-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathILikeOSM.min.js
22 lines (22 loc) · 8.43 KB
/
ILikeOSM.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/* Copyright (c) 2012 by Pascal Neis (neis-one.org).
* For more information: http://ilike.openstreetmap.de/
* Published under the 2-clause BSD license.
* See license.txt in the OpenLayers distribution or
* repository for the full text of the license.
*/
OpenLayers.ILikeOSM=OpenLayers.Class(OpenLayers.Control,{languages:{},defaultlanguage:"en",shareMapViews:false,thumbsDiv:null,thumbsTextDiv:null,counterDiv:null,shareDiv:null,buttons:null,uuid:null,callbackServerRequest:null,callbackShareMapViews:null,lastQueryTimeStamp:null,sharePopUp:null,initialize:function(){OpenLayers.Control.prototype.initialize.apply(this,arguments);this.uuid=this.getUUID();this.languages.en={Like:"I like this map section!",DisLike:"I dislike this map section!",ThumbsText:"for this map section",
CounterText:"and You are watching a part of this map section",ShareText:"See where others view the map",MessageText:"If you activate this feature, your current map view is sent to our server and stored in a database; in return, the server can tell you how many other people are looking at the same area. This allows anonymous data collection which can be shared with everyone for statistical analysis and helps us to find out how the OSM map is being used.",CheckboxYesText:"Yes, share my map view",CheckboxNoText:"No, thanks"};
this.languages.de={Like:"Du magst diesen Kartenausschnitt!",DisLike:"Du magst diesen Kartenausschnitt nicht!",ThumbsText:"für diesen Kartenausschnitt",CounterText:"und Du betrachten gerade einen Teil dieser Karte",ShareText:"Wie viele schauen auf die gleiche Karte",MessageText:"Wenn du dieses Feature aktivierst, wird deine derzeitige Kartenansicht an unseren Server gesendet und dort gespeichert. Im Gegenzug bekommst du angezeigt, wie viele andere Leute sich ebenfalls einen Teil deiner Kartenansicht anschauen. Die gesammelten Daten sind für Jeden in einer anonymisierten Form für statistische Analysen verfügbar und helfen uns zu erfahren wie die OSM Karte genutzt wird.",
CheckboxYesText:"Ja, teile meine Kartenansicht",CheckboxNoText:"Nein, danke"}},setMap:function(){OpenLayers.Control.prototype.setMap.apply(this,arguments);this.map.events.register("buttonclick",this,this.onButtonClick);this.map.events.on({moveend:this.onMapAction,changelayer:this.onMapAction,changebaselayer:this.onMapAction,scope:this})},draw:function(b){OpenLayers.Control.prototype.draw.apply(this,arguments);this.thumbsDiv=document.createElement("div");this.thumbsDiv.id=this.id+"_thumbsDiv";OpenLayers.Element.addClass(this.thumbsDiv,
"thumbsDiv");this.buttons=[];var a={w:24,h:24};b=new OpenLayers.Pixel(5,5);this._addButton("Like","http://ilike.openstreetmap.de/img/Like.png",b,a);this._addButton("DisLike","http://ilike.openstreetmap.de/img/DisLike.png",b.add(a.w+2,2),a);this.thumbsTextDiv=document.createElement("div");this.thumbsTextDiv.id=this.id+"_thumbsTextDiv";OpenLayers.Element.addClass(this.thumbsDiv,"_thumbsTextDiv");this.thumbsTextDiv.style.marginLeft=a.w*2+10+"px";this.thumbsTextDiv.style.marginTop="3px";this.thumbsTextDiv.style.paddingBottom=
"10px";this.thumbsTextDiv.style.fontSize="11px";this.thumbsTextDiv.style.fontWeight="bold";this.thumbsTextDiv.style.fontFamily="Verdana";this.thumbsTextDiv.innerHTML=this.getTextForLikeDiv("ThumbsText");this.counterDiv=document.createElement("div");this.counterDiv.id=this.id+"_counterDiv";OpenLayers.Element.addClass(this.counterDiv,"counterDiv");this.counterDiv.style.marginLeft="5px";this.counterDiv.style.fontSize="11px";this.counterDiv.style.fontWeight="bold";this.counterDiv.style.fontFamily="Verdana";
this.shareDiv=document.createElement("div");OpenLayers.Element.addClass(this.shareDiv,"shareDiv olButton");this.shareDiv.id=this.id+"_share";this.shareDiv.style.fontSize="11px";this.shareDiv.style.fontWeight="bold";this.shareDiv.style.fontFamily="Verdana";this.shareDiv.innerHTML=this.getTextForLikeDiv("ShareText")+'<a href="#"/>?</a>';this.shareDiv.title=this.getTextForLikeDiv("ShareText")+"?";this.shareDiv.action="Share";if(document.cookie!=""){a=document.cookie.split(";");for(var d=0;d<a.length;d++){var c=
a[d].split("=");if(c[0]=="sharemapviews"&&c[1]=="false")this.shareMapViews=false;else if(c[0]=="sharemapviews"&&c[1]=="true")this.shareMapViews=true}}if(this.shareMapViews)this.shareDiv.style.display="none";else this.counterDiv.style.display="none";this.div.appendChild(this.thumbsDiv);this.div.appendChild(this.thumbsTextDiv);this.div.appendChild(this.counterDiv);this.div.appendChild(this.shareDiv);this.onMapAction();return this.div},_addButton:function(b,a,d,c){a=OpenLayers.Util.createAlphaImageDiv(this.id+
"_"+b,d,c,a,"absolute");a.style.cursor="pointer";this.thumbsDiv.appendChild(a);a.action=b;a.className="olButton";a.title=b=="Like"?this.getTextForLikeDiv("Like"):this.getTextForLikeDiv("DisLike");this.buttons.push(a);return a},onButtonClick:function(b){b=b.buttonElement;switch(b.action){case "Like":this.rateMapSection(b);break;case "DisLike":this.rateMapSection(b);break;case "Share":this.checkShareMapViews(this.setShareMapViews,this);break}},rateMapSection:function(b){this.thumbsTextDiv.innerHTML=
b.action=="Like"?this.getTextForLikeDiv("Like"):this.getTextForLikeDiv("DisLike");for(var a=0;a<this.buttons.length;a++)this.buttons[a].style.display="none";b.style.display="";this.sendRequest(b.action.toLowerCase(),this.updateLikeDivTexts,null)},checkShareMapViews:function(b,a){this.sharePopUp!=null&&this.map.removePopup(this.sharePopUp);var d=new OpenLayers.Size(350,225),c=this.map.getPixelFromLonLat(this.map.getCenter());c.x-=d.w/2;c.y-=d.h/2;c=this.map.getLonLatFromPixel(c);OpenLayers.ILikeOSM.callbackShareMapView=
function(e){b(e,a)};this.sharePopUp=new OpenLayers.Popup("iLike OpenStreetMap",c,d,'<span style="font-family:Verdana; font-size: 12px;"><b>I Like OpenStreetMap Feature Plugin</b><br/><br/>'+this.getTextForLikeDiv("MessageText")+'<br/><br/><INPUT type="button" value="'+this.getTextForLikeDiv("CheckboxYesText")+'" onClick="OpenLayers.ILikeOSM.callbackShareMapView(\'true\'); return false;" name="buttonYes"> <INPUT type="button" value="'+this.getTextForLikeDiv("CheckboxNoText")+'" onClick="OpenLayers.ILikeOSM.callbackShareMapView(\'false\'); return false;" name="buttonNo"></span>',
true);this.map.addPopup(this.sharePopUp)},setShareMapViews:function(b,a){if(b=="true"){a.shareMapViews=true;a.counterDiv.style.display="";a.shareDiv.style.display="none"}else{a.shareMapViews=false;a.counterDiv.style.display="none";a.shareDiv.style.display="";b="false"}var d=new Date;d=new Date(d.getTime()+31536E6);document.cookie="sharemapviews="+b+";expires="+d.toGMTString()+";";a.sharePopUp!=null&&a.map.removePopup(a.sharePopUp);a.onMapAction()},onMapAction:function(){for(var b=0;b<this.buttons.length;b++)this.buttons[b].style.display=
"";this.thumbsTextDiv.innerHTML=this.getTextForLikeDiv("ThumbsText");this.shareMapViews&&this.sendRequest("watch",this.updateLikeDivTexts,this);this.sharePopUp!=null&&this.map.removePopup(this.sharePopUp)},updateLikeDivTexts:function(b,a){if(b&&a){a.thumbsTextDiv.innerHTML=a.getTextForLikeDiv("ThumbsText");OpenLayers.ILikeOSM.callbackShareMapViews=function(){a.checkShareMapViews(a.setShareMapViews,a)};a.counterDiv.innerHTML=b.u+" "+a.getTextForLikeDiv("CounterText")+' (<a href="#" onClick="OpenLayers.ILikeOSM.callbackShareMapViews(); return false;">?</a>)'}},
getTextForLikeDiv:function(b){var a=this.defaultlanguage;a=this.languages[a]?this.defaultlanguage:"en";return this.languages[a][b]},sendRequest:function(b,a,d){if(this.map.getCenter()){var c=(new Date).getTime();if(!(this.lastQueryTimeStamp!=null&&this.lastQueryTimeStamp>c-2E3&&b=="watch")){this.lastQueryTimeStamp=c;this.map.getCenter().transform(this.map.getProjection(),new OpenLayers.Projection("EPSG:4326"));c=this.map.getExtent().transform(this.map.getProjection(),new OpenLayers.Projection("EPSG:4326"));
c=c.left.toFixed(6)+","+c.bottom.toFixed(6)+","+c.right.toFixed(6)+","+c.top.toFixed(6);OpenLayers.ILikeOSM.callbackServerRequest=function(f){a(f,d)};var e=document.getElementById("jsonp");e&&document.body.removeChild(e);e=document.createElement("script");e.type="text/javascript";e.id="jsonp";e.src="http://ilike.openstreetmap.de/query.php?uuid="+this.uuid+"&status="+b+"&map="+encodeURIComponent(this.map.baseLayer.name)+"&zoom="+this.map.getZoom()+"&extent="+c+"&jsonp=OpenLayers.ILikeOSM.callbackServerRequest";
document.body.appendChild(e)}}},getUUID:function(){for(var b=[],a=0;a<36;a++)b[a]=Math.floor(Math.random()*16);b[14]=4;b[19]=b[19]&3|8;for(a=0;a<36;a++)b[a]="0123456789ABCDEF"[b[a]];b[8]=b[13]=b[18]=b[23]="-";return b.join("")},CLASS_NAME:"OpenLayers.ILikeOSM"});