Created
December 24, 2012 07:29
-
-
Save thingsinjars/4368218 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
(function(e,t,n){function h(t,n){this.element=t,this.options=e.extend({},s,n),this._defaults=s,this._plugin=r,this.init()}function p(e,t){var n=new u.kml.Manager;n.addObserver("state",l(function(e){e.state==="finished"&&t.call(this,e)},this)),n.parseKML(e)}function d(t){var n=t.target[t.type];if(e.isFunction(n)){var r=e.Event(t.type,{originalEvent:t,geo:{latitude:t.target.coordinate.latitude,longitude:t.target.coordinate.longitude},target:t.target});n.call(this.element,r)}}function v(e){return typeof e=="function"}var r="jHERE",i="0.2.0",s,o,u,a,f,l=e.proxy,c;s={appId:"_peU-uCkp-j8ovkzFGNU",authToken:"gBoUkAMoxoqIWfxWA5DuMQ",zoom:12,center:[52.49,13.37],enable:["behavior","zoombar","scalebar","typeselector"],type:"map",marker:{text:"",textColor:"#333333",fill:"#ff6347",stroke:"#333333",shape:"balloon",icon:undefined},bubble:{content:"",closable:!0,onclose:e.noop},heatmap:{max:20,opacity:.8,coarseness:2}},e[r]=c={},o=h.prototype,c.defaultCredentials=function(e,t){f={appId:e,authenticationToken:t},a.load().is.done(function(){u.util.ApplicationContext.set(f)})},o.init=function(){var e=this.options;a.load().is.done(l(this.makemap,this))},o.makemap=function(){var t=this.options,n=u.map.component,i=[];n.Positioning=u.positioning.component.Positioning,f=f||{appId:t.appId,authenticationToken:t.authToken},u.util.ApplicationContext.set(f),e.data(this.element,r,!0),e.each(n,l(function(t,n){e.inArray(t.toLowerCase(),this.options.enable)>-1&&i.push(new n)},this)),this.map=new u.map.Display(this.element,{zoomLevel:t.zoom,center:t.center,components:i}),this.type(t.type)},o.center=function(e){this.map.setCenter(e)},o.zoom=function(e){this.map.set("zoomLevel",e)},o.type=function(e){var t=this.map,n={map:t.NORMAL,satellite:t.SATELLITE,smart:t.SMARTMAP,terrain:t.TERRAIN,pt:t.SMART_PT};e=n[e]||n.map,t.set("baseMapType",e)},o.marker=function(t,n){var r={},i="mouse",o="click",a=[o,"dbl"+o,i+"move",i+"over",i+"out",i+"enter",i+"leave","longpress"],f=l(d,this);e.each(a,function(e,t){r[t]=[f,!1,null]}),n=e.extend({},s.marker,n),n.textPen=n.textPen||{strokeColor:n.textColor},n.pen=n.pen||{strokeColor:n.stroke},n.brush=n.brush||{color:n.fill},n.eventListener=r,n.icon?this.map.objects.add(new u.map.Marker(t,n)):this.map.objects.add(new u.map.StandardMarker(t,n))},o.bubble=function(t,n){var r;n=e.extend({},s.bubble,n),n.content.jquery&&(n.content.css("white-space","normal"),n.content=e("<div/>").append(n.content.clone()).html()),bubbles=this.map.getComponentById("InfoBubbles")||this.map.addComponent(new u.map.component.InfoBubbles),bubbles.openBubble(n.content,{latitude:t[0],longitude:t[1]},n.onclose,!n.closable)},o.kml=function(e,t,n){v(t)&&(n=t,t=!1),p.call(this,e,l(function(e){var r=new u.kml.component.KMLResultSet(e.kmlDocument,this.map);r.addObserver("state",l(function(e){var r,i;e.state=="finished"&&(t&&(r=e.container.objects.get(0),i=r.getBoundingBox(),i&&this.map.zoomTo(i)),v(n)&&n.call(this,e))},this)),this.map.objects.add(r.create())},this))},o.heatmap=function(t,n,r){var i;n=n||"value",n.match(/^density|value$/)||(n="value"),r=r||{},r.type=n,r=e.extend({},s.heatmap,r),i=new u.heatmap.Overlay(r),i.addData(t),this.map.overlays.add(i)},o.originalMap=function(e){e.call(this.element,this.map,u)},o.destroy=function(){this.map.destroy(),e.removeData(this.element),e(this.element).empty()},a={},a.is=!1,a.load=function(){var t,r,i;return a.is&&a.is.state().match(/pending|resolved/)?this:(a.is=e.Deferred(),i=function(){u=nokia.maps,u.Features.load({map:"auto",ui:"auto",search:"auto",routing:"auto",positioning:"auto",behavior:"auto",kml:"auto",heatmap:"auto"},function(){a.is.resolve()})},t=n.getElementsByTagName("head")[0],r=n.createElement("script"),r.src="http://api.maps.nokia.com/2.2.3/jsl.js",r.type="text/javascript",r.charset="utf-8",r.onreadystatechange=function(){r.readyState.match(/loaded|complete/)&&i()},r.onload=i,t.appendChild(r),this)},c._JSLALoader=a,c.extend=function(e,t){typeof e=="string"&&v(t)&&(o[e]=t)},e.fn[r]=function(t){var n=arguments;return this.each(function(){var i,s,o="plugin_"+r;i=e.data(this,o),i?(typeof t!="string"&&e.error(r+"::Plugin already initialized on this element, expected method."),s=t,n=Array.prototype.slice.call(n,1),v(i[s])||e.error(r+"::Method "+s+" does not exist"),a.load().is.done(function(){i[s].apply(i,n)})):(i=new h(this,t),e.data(this,o,i))})}})(jQuery,window,document);(function(e){function n(e){return typeof e=="function"}function r(r,i,s,o){var u=e.Deferred();return i=n(i)?i:e.noop,s=n(s)?s:e.noop,t._JSLALoader.load().is.done(function(){function n(e,t){var n=e.location;n=o?e.location.address:e.location.position,t==="OK"?(u.resolve(n),i(n)):(u.reject(),s())}var e={latitude:0,longitude:0},t=nokia.places.search.manager;o?t.reverseGeoCode({latitude:r.latitude||r[0],longitude:r.longitude||r[1],onComplete:n}):t.geoCode({searchTerm:r,onComplete:n})}),u}var t=e.jHERE;t.geocode=function(e,t,n){return r(e,t,n)},t.reverseGeocode=function(e,t,n){return r(e,t,n,!0)}})(jQuery); |
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
/* CSS */ | |
html,body, #mapContainer { | |
font-family:sans-serif; | |
background:#fff; | |
color:#444; | |
height:100%; | |
padding:0; | |
margin:0; | |
} |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Maps made simple with jHERE</title> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script> | |
<script src="jhere-custom.js"></script> | |
<script src="jquery.xdomainajax.js"></script> | |
<link rel="icon" href="http://jhere.net/favicon.ico"> | |
</head> | |
<body> | |
<div id="mapContainer"></div> | |
</body> | |
</html> |
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
/* Javascript | |
* | |
* See http://jhere.net/docs.html for full documentation | |
*/ | |
$(window).on('load', function() { | |
$.jHERE.defaultCredentials('_peU-uCkp-j8ovkzFGNU', 'gBoUkAMoxoqIWfxWA5DuMQ'); | |
$('#mapContainer').jHERE({ | |
enable: ['behavior', 'positioning'], | |
center: [51,10.3], | |
zoom: 6 | |
}); | |
navigator.geolocation.getCurrentPosition(show_map, handle_error); | |
}); | |
function show_map(position) { | |
//Position Map in the user's location | |
$('#mapContainer').jHERE('center',position.coords); | |
//Set a useful zoom | |
$('#mapContainer').jHERE('zoom', 13); | |
// Revese Geocode so we can get the user's posticode for the service lookup | |
$.jHERE.reverseGeocode(position.coords, | |
function(address){ | |
if(address && address.postalCode) { | |
// Call the Apotheke service with the postcode to find the nearest open one | |
$.get('http://www.apotheken.de/index.php?id=47&typ=4&plz='+address.postalCode+'&radius=5', function(responseText, response, text) { | |
// This returns HTML so we parse it | |
var allResults = $(responseText.responseText).find('table tr'); | |
// Map the table data into a JSON object | |
var AoA = allResults.map(function(){ | |
return [ | |
$('td',this).map(function(){ | |
return $(this).text(); | |
}).get() | |
]; | |
}).get(); | |
// Get rid of the table head | |
AoA.shift(); | |
// For each result, geocode and get their position | |
for(var i=0;i<AoA.length;i++) { | |
var pharmacyName = AoA[i][0].replace(/\n/g,"").replace(/\s{2,}/g," "); | |
// Tidy the address | |
var pharmacyAddress = (AoA[i][1].replace(/\n.*\n\s+$/gm,'')+', Germany').replace(/\n/g,"").replace(/\s{2,}/g," "); | |
var pharmacyOpeningHours = AoA[i][3]; | |
debugger; | |
// Get the lat/lng | |
$.jHERE.geocode(pharmacyAddress, function(pharmacyName, pharmacyAddress, pharmacyOpeningHours) { | |
return function(position) { | |
// Add a marker at the right position containing the opening ours | |
// in the marker data | |
$('#mapContainer').jHERE('marker', position, {text: "!", click: function(e){ | |
$('#mapContainer').jHERE('bubble', [e.geo.latitude,e.geo.longitude], {content: pharmacyName+"<br>"+pharmacyAddress+"<br>"+pharmacyOpeningHours}); | |
}}); | |
} | |
}(pharmacyName, pharmacyAddress, pharmacyOpeningHours),function(error) {console.log(error);}) | |
} | |
}) | |
} | |
}, | |
function(){/*error*/}); | |
} | |
function handle_error(error) {} |
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
/** | |
* jQuery.ajax mid - CROSS DOMAIN AJAX | |
* --- | |
* @author James Padolsey (http://james.padolsey.com) | |
* @version 0.11 | |
* @updated 12-JAN-10 | |
* --- | |
* Note: Read the README! | |
* --- | |
* @info http://james.padolsey.com/javascript/cross-domain-requests-with-jquery/ | |
*/ | |
jQuery.ajax = (function(_ajax){ | |
var protocol = location.protocol, | |
hostname = location.hostname, | |
exRegex = RegExp(protocol + '//' + hostname), | |
YQL = 'http' + (/^https/.test(protocol)?'s':'') + '://query.yahooapis.com/v1/public/yql?callback=?', | |
query = 'select * from html where url="{URL}" and xpath="*"'; | |
function isExternal(url) { | |
return !exRegex.test(url) && /:\/\//.test(url); | |
} | |
return function(o) { | |
var url = o.url; | |
if ( /get/i.test(o.type) && !/json/i.test(o.dataType) && isExternal(url) ) { | |
// Manipulate options so that JSONP-x request is made to YQL | |
o.url = YQL; | |
o.dataType = 'json'; | |
o.data = { | |
q: query.replace( | |
'{URL}', | |
url + (o.data ? | |
(/\?/.test(url) ? '&' : '?') + jQuery.param(o.data) | |
: '') | |
), | |
format: 'xml' | |
}; | |
// Since it's a JSONP request | |
// complete === success | |
if (!o.success && o.complete) { | |
o.success = o.complete; | |
delete o.complete; | |
} | |
o.success = (function(_success){ | |
return function(data) { | |
if (_success) { | |
// Fake XHR callback. | |
_success.call(this, { | |
responseText: (data.results[0] || '') | |
// YQL screws with <script>s | |
// Get rid of them | |
.replace(/<script[^>]+?\/>|<script(.|\s)*?\/script>/gi, '') | |
}, 'success'); | |
} | |
}; | |
})(o.success); | |
} | |
return _ajax.apply(this, arguments); | |
}; | |
})(jQuery.ajax); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment