Better maps.

master
q3k 2012-04-18 16:52:37 +02:00
parent 6df5f08a52
commit cfbe448549
7 changed files with 2761 additions and 1 deletions

View File

@ -287,4 +287,16 @@ div .twtr-ft {
div .twtr-widget p {
text-align: left !important;
}
#map {
width: 930px;
height: 550px;
}
.olControlAttribution {
font-size: 10px;
font-weight: bold;
opacity: 0.5;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 765 KiB

After

Width:  |  Height:  |  Size: 732 KiB

View File

@ -88,7 +88,7 @@
<p>
Warszawski Hackerspace znajduje się w budynku ITR, w piwnicy. Sam ITR mieści się na ulicy Długiej 44, tuż obok Metra Ratusz-Arsenał.
</p>
<center><img src="/img/mapka.png" style="border-radius: 4px;" /></center>
<center><div id="map"><img src="/img/mapka.png" style="border-radius: 4px;" /></div></center>
</div>
</div>
<footer>
@ -98,7 +98,9 @@
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/libs/jquery-1.7.1.min.js"><\/script>')</script>
<script src="/js/libs/jquery.timers.js"></script>
<script src="js/plugins.js"></script>
<script src="js/script.js"></script>
<script src="js/map.js"></script>
</body>
</html>

138
js/libs/jquery.timers.js Normal file
View File

@ -0,0 +1,138 @@
/**
* jQuery.timers - Timer abstractions for jQuery
* Written by Blair Mitchelmore (blair DOT mitchelmore AT gmail DOT com)
* Licensed under the WTFPL (http://sam.zoy.org/wtfpl/).
* Date: 2009/10/16
*
* @author Blair Mitchelmore
* @version 1.2
*
**/
jQuery.fn.extend({
everyTime: function(interval, label, fn, times) {
return this.each(function() {
jQuery.timer.add(this, interval, label, fn, times);
});
},
oneTime: function(interval, label, fn) {
return this.each(function() {
jQuery.timer.add(this, interval, label, fn, 1);
});
},
stopTime: function(label, fn) {
return this.each(function() {
jQuery.timer.remove(this, label, fn);
});
}
});
jQuery.extend({
timer: {
global: [],
guid: 1,
dataKey: "jQuery.timer",
regex: /^([0-9]+(?:\.[0-9]*)?)\s*(.*s)?$/,
powers: {
// Yeah this is major overkill...
'ms': 1,
'cs': 10,
'ds': 100,
's': 1000,
'das': 10000,
'hs': 100000,
'ks': 1000000
},
timeParse: function(value) {
if (value == undefined || value == null)
return null;
var result = this.regex.exec(jQuery.trim(value.toString()));
if (result[2]) {
var num = parseFloat(result[1]);
var mult = this.powers[result[2]] || 1;
return num * mult;
} else {
return value;
}
},
add: function(element, interval, label, fn, times) {
var counter = 0;
if (jQuery.isFunction(label)) {
if (!times)
times = fn;
fn = label;
label = interval;
}
interval = jQuery.timer.timeParse(interval);
if (typeof interval != 'number' || isNaN(interval) || interval < 0)
return;
if (typeof times != 'number' || isNaN(times) || times < 0)
times = 0;
times = times || 0;
var timers = jQuery.data(element, this.dataKey) || jQuery.data(element, this.dataKey, {});
if (!timers[label])
timers[label] = {};
fn.timerID = fn.timerID || this.guid++;
var handler = function() {
if ((++counter > times && times !== 0) || fn.call(element, counter) === false)
jQuery.timer.remove(element, label, fn);
};
handler.timerID = fn.timerID;
if (!timers[label][fn.timerID])
timers[label][fn.timerID] = window.setInterval(handler,interval);
this.global.push( element );
},
remove: function(element, label, fn) {
var timers = jQuery.data(element, this.dataKey), ret;
if ( timers ) {
if (!label) {
for ( label in timers )
this.remove(element, label, fn);
} else if ( timers[label] ) {
if ( fn ) {
if ( fn.timerID ) {
window.clearInterval(timers[label][fn.timerID]);
delete timers[label][fn.timerID];
}
} else {
for ( var fn in timers[label] ) {
window.clearInterval(timers[label][fn]);
delete timers[label][fn];
}
}
for ( ret in timers[label] ) break;
if ( !ret ) {
ret = null;
delete timers[label];
}
}
for ( ret in timers ) break;
if ( !ret )
jQuery.removeData(element, this.dataKey);
}
}
}
});
jQuery(window).bind("unload", function() {
jQuery.each(jQuery.timer.global, function(index, item) {
jQuery.timer.remove(item);
});
});

93
js/map.js Normal file
View File

@ -0,0 +1,93 @@
/** include - including .js files from JS - bfults@gmail.com - 2005-02-09 **
** Code licensed under Creative Commons Attribution-ShareAlike License **
** http://creativecommons.org/licenses/by-sa/2.0/ **/
var hIncludes = null;
function include(sURI, cls, id, ignore_duplicates)
{
if (document.getElementsByTagName) {
if (!ignore_duplicates && !hIncludes) {
hIncludes = {};
var cScripts = document.getElementsByTagName("script");
for (var i=0,len=cScripts.length; i < len; i++)
if (cScripts[i].src) hIncludes[cScripts[i].src] = cScripts[i];
}
if (ignore_duplicates || !hIncludes[sURI]) {
var oNew = document.createElement("script");
oNew.type = "text/javascript";
oNew.src = sURI;
if (cls != undefined) oNew.className = cls;
if (id != undefined) oNew.id = id;
if (hIncludes != undefined) hIncludes[sURI]=true;
document.getElementsByTagName("head")[0].appendChild(oNew);
}
return (ignore_duplicates || hIncludes[sURI]);
}
return false
}
/* code borrowed from rysiek at brama. */
include('/js/openlayers/OpenLayers.js', 'js-libs');
var osm, map, markers_layer, zoom, center, brama_pos, epsg4326;
function initOpenLayersMap(mapobj) {
zoom = 16
center = new OpenLayers.LonLat(21.002971, 52.246246);
hs_pos = new OpenLayers.LonLat(21.002971, 52.246246);
epsg4326 = new OpenLayers.Projection("EPSG:4326");
map = new OpenLayers.Map(mapobj, {maxResolution: 0.703125});
osm = new OpenLayers.Layer.OSM.Mapnik("OpenStreetMap (Mapnik)", {
displayOutsideMaxExtent: true,
wrapDateLine: true,
buffer: 0
});
map.addLayer(osm);
map.setCenter(center.clone().transform(epsg4326, map.getProjectionObject()), zoom);
markers_layer = new OpenLayers.Layer.Markers("Markery");
var icon_size = new OpenLayers.Size(50, 30);
var icon_offset = new OpenLayers.Pixel(-(icon_size.w/2), -(icon_size.h/2));
var hs = new OpenLayers.Marker(
hs_pos.clone().transform(epsg4326, map.getProjectionObject()),
new OpenLayers.Icon('/img/hackerspace.svg', icon_size, icon_offset)
);
markers_layer.setVisibility(true);
markers_layer.addMarker(hs);
map.addLayer(markers_layer);
}
var map_attempt_timeout = 500;
var map_attempts_no = 30;
function mapInitAttempt() {
if ( (typeof OpenLayers != 'undefined') && (typeof OpenLayers.Layer.OSM.Mapnik != 'undefined') ) {
$(this).stopTime()
$('#map img').fadeOut('fast', function(){
$("#map").addClass('osm')
initOpenLayersMap("map")
});
} else {
if ( ($("script[src='/js/openlayers/openstreetmap.js']").length == 0) && (typeof OpenLayers != 'undefined') && (typeof OpenLayers.Layer.OSM.Mapnik == 'undefined') ) {
include('/js/openlayers/openstreetmap.js', 'js-libs');
}
map_attempts_no--
if (map_attempts_no > 0) {
if (typeof console != 'undefined') console.debug('OSM/OL :: not yet... (' + map_attempts_no + ' attempts left)')
} else {
$(this).stopTime()
if (typeof console != 'undefined') console.debug('OSM/OL :: not yet... cancelling.')
}
}
}
$(document).ready(function(){
$(this).everyTime(map_attempt_timeout, mapInitAttempt);
});

2374
js/openlayers/OpenLayers.js Normal file

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,141 @@
/**
* Namespace: Util.OSM
*/
OpenLayers.Util.OSM = {};
/**
* Constant: MISSING_TILE_URL
* {String} URL of image to display for missing tiles
*/
OpenLayers.Util.OSM.MISSING_TILE_URL = "http://openstreetmap.org/openlayers/img/404.png";
/**
* Property: originalOnImageLoadError
* {Function} Original onImageLoadError function.
*/
OpenLayers.Util.OSM.originalOnImageLoadError = OpenLayers.Util.onImageLoadError;
/**
* Function: onImageLoadError
*/
OpenLayers.Util.onImageLoadError = function() {
if (this.src.match(/^http:\/\/[abc]\.[a-z]+\.openstreetmap\.org\//)) {
this.src = OpenLayers.Util.OSM.MISSING_TILE_URL;
} else if (this.src.match(/^http:\/\/[def]\.tah\.openstreetmap\.org\//)) {
// do nothing - this layer is transparent
} else {
OpenLayers.Util.OSM.originalOnImageLoadError;
}
};
/**
* Class: OpenLayers.Layer.OSM.Mapnik
*
* Inherits from:
* - <OpenLayers.Layer.OSM>
*/
OpenLayers.Layer.OSM.Mapnik = OpenLayers.Class(OpenLayers.Layer.OSM, {
/**
* Constructor: OpenLayers.Layer.OSM.Mapnik
*
* Parameters:
* name - {String}
* options - {Object} Hashtable of extra options to tag onto the layer
*/
initialize: function(name, options) {
var url = [
"http://a.tile.openstreetmap.org/${z}/${x}/${y}.png",
"http://b.tile.openstreetmap.org/${z}/${x}/${y}.png",
"http://c.tile.openstreetmap.org/${z}/${x}/${y}.png"
];
options = OpenLayers.Util.extend({ numZoomLevels: 19 }, options);
var newArguments = [name, url, options];
OpenLayers.Layer.OSM.prototype.initialize.apply(this, newArguments);
},
CLASS_NAME: "OpenLayers.Layer.OSM.Mapnik"
});
/**
* Class: OpenLayers.Layer.OSM.Osmarender
*
* Inherits from:
* - <OpenLayers.Layer.OSM>
*/
OpenLayers.Layer.OSM.Osmarender = OpenLayers.Class(OpenLayers.Layer.OSM, {
/**
* Constructor: OpenLayers.Layer.OSM.Osmarender
*
* Parameters:
* name - {String}
* options - {Object} Hashtable of extra options to tag onto the layer
*/
initialize: function(name, options) {
var url = [
"http://a.tah.openstreetmap.org/Tiles/tile/${z}/${x}/${y}.png",
"http://b.tah.openstreetmap.org/Tiles/tile/${z}/${x}/${y}.png",
"http://c.tah.openstreetmap.org/Tiles/tile/${z}/${x}/${y}.png"
];
options = OpenLayers.Util.extend({ numZoomLevels: 18 }, options);
var newArguments = [name, url, options];
OpenLayers.Layer.OSM.prototype.initialize.apply(this, newArguments);
},
CLASS_NAME: "OpenLayers.Layer.OSM.Osmarender"
});
/**
* Class: OpenLayers.Layer.OSM.CycleMap
*
* Inherits from:
* - <OpenLayers.Layer.OSM>
*/
OpenLayers.Layer.OSM.CycleMap = OpenLayers.Class(OpenLayers.Layer.OSM, {
/**
* Constructor: OpenLayers.Layer.OSM.CycleMap
*
* Parameters:
* name - {String}
* options - {Object} Hashtable of extra options to tag onto the layer
*/
initialize: function(name, options) {
var url = [
"http://a.andy.sandbox.cloudmade.com/tiles/cycle/${z}/${x}/${y}.png",
"http://b.andy.sandbox.cloudmade.com/tiles/cycle/${z}/${x}/${y}.png",
"http://c.andy.sandbox.cloudmade.com/tiles/cycle/${z}/${x}/${y}.png"
];
options = OpenLayers.Util.extend({ numZoomLevels: 19 }, options);
var newArguments = [name, url, options];
OpenLayers.Layer.OSM.prototype.initialize.apply(this, newArguments);
},
CLASS_NAME: "OpenLayers.Layer.OSM.CycleMap"
});
/**
* Class: OpenLayers.Layer.OSM.Maplint
*
* Inherits from:
* - <OpenLayers.Layer.OSM>
*/
OpenLayers.Layer.OSM.Maplint = OpenLayers.Class(OpenLayers.Layer.OSM, {
/**
* Constructor: OpenLayers.Layer.OSM.Maplint
*
* Parameters:
* name - {String}
* options - {Object} Hashtable of extra options to tag onto the layer
*/
initialize: function(name, options) {
var url = [
"http://d.tah.openstreetmap.org/Tiles/maplint/${z}/${x}/${y}.png",
"http://e.tah.openstreetmap.org/Tiles/maplint/${z}/${x}/${y}.png",
"http://f.tah.openstreetmap.org/Tiles/maplint/${z}/${x}/${y}.png"
];
options = OpenLayers.Util.extend({ numZoomLevels: 18, isBaseLayer: false, visibility: false }, options);
var newArguments = [name, url, options];
OpenLayers.Layer.OSM.prototype.initialize.apply(this, newArguments);
},
CLASS_NAME: "OpenLayers.Layer.OSM.Maplint"
});