tileSizeConfig = [
{w:1720.320000, h:409.600000},
{w:860.160000, h:204.800000},
{w:430.080000, h:102.400000},
{w:215.040000, h:51.200000},
{w:107.520000, h:25.600000},
{w:53.760000, h:12.800000},
{w:26.880000, h:6.400000},
{w:13.440000, h:3.200000},
{w:6.720000, h:1.600000},
{w:3.360000, h:.800000},
{w:1.680000, h:.400000},
{w:.840000, h:.200000},
{w:.420000, h:.100000},
{w:.210000, h:.050000},
{w:.105000, h:.025000},
{w:.052500, h:.012500},
{w:.026250, h:.006250},
{w:.013125, h:.003125},
{w:.006562, h:.001562},
{w:.003281, h:.000781},
{w:.001640, h:.000390},
{w:.000820, h:.000195},
]
MAGTILEFACTOR = 2;
/* zope mapcontrol javascripts */
function LovelyMapControl(){
this.cityName = "Berlin";
this.mapElement = $("#karte");
this.mapContainer = document.getElementById("karte");
this.privateLat = 52.43676;
this.privateLon = 13.64614;
this.zoomLevels = {
city: 13,
district: 15,
street: 17
};
this.zoomRanges = {
city: [11, 12, 13],
district: [14, 15, 16],
street: [17, 18, 19, 20, 21]
};
this.pinRepos = [];
this.googlePinPrefix = "mtgt_";
this.flags = [];
this.header = {
getImageUrl : function(title) { return LPM.getGlobals().portalUrl +"/district/"+title+"/header.png"},
district: false,
defaultDistrict: this.cityName
};
};
LovelyMapControl.prototype.init = function(manager, startup){
this.manager = manager;
this.grid = new MapGrid();
this.grid.init(this);
this.map = new GMap2(this.mapContainer);
this.map.setCenter(new GLatLng(startup.c_lat, startup.c_lon), parseInt(startup.zoom), G_HYBRID_MAP);
this.tiles = new TileBasedPinHandler();
this.tiles.init(this);
this.startUp = startup;
this.attachMapEvents();
this.magazineheader = false;
this.lookupMagazineHeader();
var self = this;
$(window).resize(function(){
if (LPM.mode == "map")
self.onResize();
});
this.isReady = true;
};
LovelyMapControl.prototype.preloadFlags = function(){
if(!document.getElementById("flag-repository"))
$("#footer").after("
");
$("#flag-repository").empty();
for (var i = 0; i
\n");
};
LovelyMapControl.prototype.createMagazinHeader = function(){
if (this.magazineheader)
this.magazineheader.hide();
var y = this.adjustMagazineHeader();
var imageUrl = this.header.getImageUrl(this.getHeader());
this.magazineheader = false;
this.magazineheader = new GScreenOverlay(imageUrl,
new GScreenPoint(200, y), // screenXY
new GScreenPoint(0, 0), // overlayXY
new GScreenSize(600, 70) // size on screen
);
this.map.addOverlay(this.magazineheader);
};
LovelyMapControl.prototype.lookupMagazineHeader = function(){
var center = this.getCenterAndZoom();
var self = this;
this.manager.locationByLatLon(center.lat, center.lon, function(data){
if (center.zoom>=self.zoomLevels.street-1)
self.header.district = data.street;
else if (center.zoom>self.zoomLevels.district-1)
self.header.district = data.district;
else
self.header.district = self.cityName;
self.createMagazinHeader();
});
};
LovelyMapControl.prototype.getHeader = function() {
if(this.header.district)
return this.header.district;
else
return this.header.defaultDistrict;
};
LovelyMapControl.prototype.adjustMagazineHeader = function(){
var height = parseInt(this.mapElement.height()) - 110;
return height;
};
LovelyMapControl.prototype.attachMapEvents = function(){
var self = this;
GEvent.addListener(this.map, 'load', function(){
log("map initialized");
self.ready = true;
});
GEvent.addListener(this.map, 'moveend', function(){
self.syncPois();
self.lookupMagazineHeader();
// Tell the Pagemanager, that there is a new zoomlevel
LPM.mag.refresh("street");
});
GEvent.addListener(this.map, 'dragend', function(){
log("someone dragged the map");
});
GEvent.addListener(this.map, 'zoomend', function(){
LPM.nav.setSliderValue(self.getZoom());
LPM.history.addZoom();
LPM.tracking.track("zoomend");
});
};
/* interface for tile-based pin-loading */
LovelyMapControl.prototype.loadPinsForArea = function(ltlat, ltlon, rblat, rblon, zoom, filter, callback){
this.pinsForAreaCallBack = callback;
this.tiles.getPins(ltlat, ltlon, rblat, rblon, zoom, filter);
};
LovelyMapControl.prototype.onResize = function(){
this.updateMapSize();
this.checkResize();
};
LovelyMapControl.prototype.checkResize = function(){
this.map.checkResize();
this.lookupMagazineHeader();
};
LovelyMapControl.prototype.onPinsForAreaLoaded = function(json){
this.pinsForAreaCallBack.call(this, json);
};
LovelyMapControl.prototype.getBounds = function(){
var bounds = [this.map.getBounds().getNorthEast().lat(), this.map.getBounds().getSouthWest().lng(), this.map.getBounds().getSouthWest().lat(), this.map.getBounds().getNorthEast().lng()];
return bounds;
};
LovelyMapControl.prototype.captureBorders = function(){
var b = mbGetBounds();
this.borders = {
lt: {
lat: b[0],
lon: b[1]
},
rb: {
lat: b[2],
lon: b[3]
}
};
};
LovelyMapControl.prototype.getAreaConsumerString = function(tile, zoom){
tile = tile || this.getBorders();
zoom = zoom || this.getZoom();
var cons = "area/" +
tile.lt.lat.toFixed(6) +
"," +
tile.lt.lon.toFixed(6) +
"/" +
tile.rb.lat.toFixed(6) +
"," +
tile.rb.lon.toFixed(6) +
"/" +
zoom +
"/" +
this.manager.getFilter();
return cons;
};
LovelyMapControl.prototype.getMagazineAreaConsumerString = function(){
var center = this.getCenterAndZoom();
var magTile = this.grid.getMagazineTile(center, this.getZoom());
var ret = this.getAreaConsumerString(magTile);
return ret;
};
LovelyMapControl.prototype.getCoordConsumerString = function(center, zoom){
var center = center || this.getCenterAndZoom();
var zoom = zoom || this.getZoom();
var normalized = this.grid.normalizeToCenter(center, zoom);
return this.generateCoordConsumer(normalized, zoom);
};
LovelyMapControl.prototype.getMagazineCoordConsumerString = function(center, zoom){
var center = center || this.getCenterAndZoom();
var zoom = zoom || this.getZoom();
var center = this.grid.getMagazineTile(center, zoom).center;
return this.generateCoordConsumer(center, zoom);
};
LovelyMapControl.prototype.generateCoordConsumer = function(coord, zoom){
var cons = "coord/" +
coord.lat.toFixed(6) +
"/" +
coord.lon.toFixed(6) +
"/" +
zoom;
return cons;
};
LovelyMapControl.prototype.getBorders = function(){
return this.borders;
};
LovelyMapControl.prototype.updateMapSize = function(){
var height = LPM.modeSwitch.getMaxHeight();
LPM.modeSwitch.container.css({
height: height + "px"
});
LPM.modeSwitch.map.css({
height: height + "px"
});
};
LovelyMapControl.prototype.syncPois = function(){
if (LPM.mode == "map") {
var self = this;
var bounds = this.getBounds();
//tile-based pinloading
this.loadPinsForArea(bounds[0], bounds[1], bounds[2], bounds[3], this.getZoom(), LPM.getFilter(), function(json){
self.drawPins(json);
});
}
};
LovelyMapControl.prototype.drawPins = function(json){
this.clearMap();
this.pincheck = []; // Clear variable
for (i = 0; i < json.length; i++) // the cycle himself
{
this.createPin(json[i]);
}
this.map.checkResize(); // for compatibility-issues
this.preloadFlags();
if($.browser.msie)
this.moveNeedles();
else
window.setTimeout("LPM.map.moveNeedles()",500);
};
LovelyMapControl.prototype.clearMap = function(){
for (i = 0; i < this.pinRepos.length; i++)
this.map.removeOverlay(this.pinRepos[i]);
this.flags = [];
this.closeBubble();
};
LovelyMapControl.prototype.createPin = function(pinDataArray){
var pda = pinDataArray; // To shorten the variable a bit
var pinLat = mbRound(pda['lat'], 5);
var pinLon = mbRound(pda['lon'], 5);
var point = new GLatLng(pinLat, pinLon);
if (this.getZoom() < 17)
var Icon = this.createNeedles(pda);
else
var Icon = this.createFlags(pda);
var options = {
icon: Icon,
draggable: false,
dragCrossMove: false
// id: "pin_"+pinID // ID for hover-effect on stacks
};
var pinmarker = new GMarker(point, options);
// marked for deletion
pinmarker.id = pda['id']; // Giving an Unique ID to the image-map, so we can use JQuery to attach a ID to the image (needle) itself
pinmarker.pintype = pda['type'];
this.map.addOverlay(pinmarker);
// Adding our marker to the repository. Needed for array-based "clearOverlays()" Function
this.pinRepos.push(pinmarker);
// Pinmarker 2.0 for bubble 2.0 START
var self = this;
GEvent.addListener(pinmarker, "mouseover", function(){
self.openBubble(this, pda);
});
// Pinmarker 2.0 for bubble 2.0 END
};
LovelyMapControl.prototype.createNeedles = function(pda){
var Icon = new GIcon();
if (pda['subType'] == null)
pda['subType'] = "";
Icon.image = LPM.getGlobals().portalUrl + '/@@/img/needles/' + pda['type'].toLowerCase() + pda['subType'] + '.png';
if (!($.browser.msie && $.browser.version < 7))
Icon.transparent = LPM.getGlobals().portalUrl + '/@@/img/needles/transparent-s.png';
if ($.browser.msie && $.browser.version > 6)
Icon.transparent = LPM.getGlobals().portalUrl + '/@@/img/needles/transparent-s-ie.png';
Icon.imageMap = [14, 3, 25, 3, 32, 8, 36, 14, 36, 22, 34, 28, 24, 35, 15, 35, 9, 32, 3, 25, 3, 13, 8, 7];
Icon.iconSize = new GSize(40, 57);
Icon.iconAnchor = new GPoint(20, 56);
Icon.infoWindowAnchor = new GPoint(-20, -70);
Icon.shadowSize = new GSize(41, 28);
Icon.shadow = LPM.getGlobals().portalUrl + '/@@/img/needles/shadow.png';
this.flags.push(pda['baseUrl'] + '/' + pda['flagUrl']);
return Icon;
};
LovelyMapControl.prototype.createFlags = function(pda){
var Icon = new GIcon();
Icon.image = pda['baseUrl'] + '/' + pda['flagUrl'];
if (!($.browser.msie && $.browser.version < 7))
Icon.transparent = LPM.getGlobals().portalUrl + '/@@/img/needles/transparent-long-needle.png';
if ($.browser.msie && $.browser.version > 6)
Icon.transparent = LPM.getGlobals().portalUrl + '/@@/img/needles/transparent-long-needle-ie.png';
Icon.imageMap = [54, 23, 58, 6, 64, 0, 226, 0, 229, 3, 230, 40, 225, 44, 218, 47, 203, 48, 69, 46, 60, 38, 54, 29, 54, 18];
Icon.iconSize = new GSize(185, 56);
Icon.shadowSize = new GSize(180, 28);
Icon.shadow = LPM.getGlobals().portalUrl + '/@@/img/needles/flags/shadow.png';
Icon.infoWindowAnchor = new GPoint(0, -70);
Icon.iconAnchor = new GPoint(20, 55);
return Icon;
};
LovelyMapControl.prototype.openItempage = function(pda){
var url = (pda['baseUrl'] + "/" + pda['itemUrl']).replace(".html", ".ajax");
var page = new LovelyAjaxPage();
page.url = url;
page.itemId = pda['id'];
page.target = $('#hover-container');
var id = LPM.registerAjaxPage(page);
LPM.showItemPage(id);
log(page);
};
LovelyMapControl.prototype.moveNeedles = function(){
if (this.getZoom() < 17) {
$("img[src$='needles/shadow.png']").each(function(){
if (!$(this).hasClass("moved")) {
$(this).css({
top: parseInt($(this).css("top")) + 28 + "px",
left: parseInt($(this).css("left")) - 13 + "px"
}).addClass("moved");
}
});
}
else {
$("img[src$='flags/shadow.png']").each(function(){
if (!$(this).hasClass("moved")) {
$(this).css({
top: parseInt($(this).css("top")) + 28 + "px",
left: parseInt($(this).css("left")) - 13 + "px"
}).addClass("moved");
}
});
}
};
LovelyMapControl.prototype.openBubble = function(pindingens, pda){
// pda is the complete pinDataArray from the JSON Call. Use it like pda['title'] etc...
var bubblehtml = this.getBubble(pda);
if ($.browser.msie)
var offsetX = 230;
else
var offsetX = -20;
var shadow = true;
var offsetY = -9;
// var offsetX = offsetX;
var paddingY = 0;
var paddingX = 0;
var bubble = pindingens.openExtInfoWindow(this.map, "mbBigBubble", bubblehtml, {
offsetY: offsetY,
offsetX: offsetX,
paddingX: paddingX,
paddingY: paddingY,
paddingXR: 0,
paddingXL: 0,
shadow: shadow
});
pindingens.hide();
var self = this;
$('#hb' + pda['id']).bind("click", function(){ // Bind the onclick-Event
self.openItempage(pda);
$('#hb' + pda['id']).unbind("click");
$('#hb' + pda['id']).unbind("mouseout");
self.closeBubble();
pindingens.show();
});
$('#hb' + pda['id']).bind("mouseout", function(){
$('#hb' + pda['id']).unbind("click");
$('#hb' + pda['id']).unbind("mouseout");
self.closeBubble();
pindingens.show();
});
};
LovelyMapControl.prototype.getBubble = function(pda){
var flag = "
";
if($.browser.msie && $.browser.version<7)
flag = "";
var bubbleHtml = "" +
"
![]()
" +
mbShorten(pda['teaser'], 10) +
"
" +
"
erstellt: " + pda['date'] +
"
" + flag + "
";
return bubbleHtml;
};
LovelyMapControl.prototype.closeBubble = function(){
if (this.map.getInfoWindow())
this.map.closeInfoWindow();
if (this.map.getExtInfoWindow())
this.map.closeExtInfoWindow();
};
LovelyMapControl.prototype.setZoom = function(zoom){
this.map.setZoom(zoom);
};
LovelyMapControl.prototype.setZoomType = function(type, lat, lon){
this.setZoom(this.zoomLevels[type])
if (lat && lon)
this.setCenter(lat, lon);
else
this.syncPois();
var cz = this.getCenterAndZoom();
if (this.manager.focus.isSet)
this.manager.focus.releaseFocus();
//else this.manager.breadcrumbs.refreshOnCoord(cz.lat, cz.lon, this.());
//close all bubbles
if (this.manager.mode == "map")
mbCloseBubble();
//or switch to the titlepage if on a focussed item in magazine
return this.zoomLevels[type];
};
LovelyMapControl.prototype.getLevelForZoom = function(zoom){ // marked for deletion
for (var p in this.zoomRanges) {
error("somebody called map.getLevelForZoom");
if (this.zoomRanges[p].contains(zoom))
return p;
}
};
LovelyMapControl.prototype.getCurrentZoomLevel = function(){ // marked for deletion
error("somebody called getCurrentZoomLevel");
return this.getZoom();
};
LovelyMapControl.prototype.getCenterAndZoom = function(){
var cz = {
lat: this.map.getCenter().lat(),
lon: this.map.getCenter().lng(),
zoom: this.getZoom()
}
return cz;
};
LovelyMapControl.prototype.setCenterAndZoom = function(lat, lon, zoom){
this.map.setCenter(new GLatLng(lat, lon), Math.round(zoom));
};
LovelyMapControl.prototype.setCenter = function(lat, lon, nomove){ // marked for deletion
error("somebody called map.setCenter");
if (!nomove)
this.getZoom(lat, lon, this.getZoom())
};
LovelyMapControl.prototype.onFocusSet = function(data){ // marked for deletion
if (data.privacy)
this.showPrivacyMessage();
else
this.hidePrivacyMessage();
info("map.onFocusSet", data);
error("somebody called map.onFocusSet");
};
LovelyMapControl.prototype.showDistrict = function(lat, lon, name){ // marked for deletion
if (this.cityName == name)
var zoom = this.zoomLevels['city'];
else
var zoom = this.zoomLevels['district'];
this.setCenterAndZoom(lat, lon, zoom);
this.syncPois();
error("somebody called map.showDistrict");
return zoom;
};
LovelyMapControl.prototype.showItemOnMap = function(uid, privacy){ // marked for deletion
this.manager.resolveByUid(uid, function(data){
mbShowBubble(data.uid, data.lat, data.lon, data.type, data.subtype, data.title, true);
});
this.manager.setMode("map");
error("somebody called map.showDistrict");
};
LovelyMapControl.prototype.showPrivacyMessage = function(){ // marked for deletion
$('div#privatelocationinfo').show();
error("somebody called map.showPrivacyMessage");
};
LovelyMapControl.prototype.hidePrivacyMessage = function(force){ // marked for deletion
if ((!this.stillOnPrivate()) || force)
$('div#privatelocationinfo').hide();
error("somebody called map.hidePrivacyMessage");
};
LovelyMapControl.prototype.stillOnFocus = function(){ // marked for deletion
error("somebody called map.stillOnFocus");
//FIXME timing problems. aarghh
if (this.manager.focusedItem) {
if (this.manager.focusedItem.lat == this.getCenterAndZoom().lat &&
this.manager.focusedItem.lat == this.getCenterAndZoom().lon) {
return true;
}
else {
return false;
}
}
else {
return false;
}
};
LovelyMapControl.prototype.stillOnPrivate = function(){ // marked for deletion
error("somebody called map.stillOnPrivate");
if (this.privateLat == this.getCenterAndZoom().lat &&
this.privateLon == this.getCenterAndZoom().lon) {
return true;
}
else {
return false;
}
};
LovelyMapControl.prototype.showAddressOnMap = function(lat, lon, zoom){
set_pos_and_zoom(lat, lon, zoom);
show_adress();
if (this.manager.currentPage.id != "map") {
this.manager.showPage("map")
}
LPM.onMapUpdate();
//LPM.breadcrumbs.refreshOnCoord(lat, lon, zoom);
};
LovelyMapControl.prototype.getZoom = function(){
return this.map.getZoom();
};
LovelyMapControl.prototype.resolvePointDistance = function(p1, p2, cb){
var callback = cb;
var p1s = [p1.lat, p1.lon].join(",");
var p2s = [p2.lat, p2.lon].join(",");
var param = [p1s, p2s].join(";");
var url = "/coords/" + param + "/distance";
$.getJSON(url, {}, function(response){
if (response)
callback.call(this, response.distance);
else
callback.call(this, false);
});
};
/* MapGrid */
MapGrid = function(){
this.tileSizeByZoom = tileSizeConfig;
this.MAGTILEFACTOR = MAGTILEFACTOR;
}
MapGrid.prototype.init = function(map){
this.map = map;
this.manager = map.manager;
}
MapGrid.prototype.tileSize = function(zoom){
ts = this.tileSizeByZoom[zoom];
if (ts)
return ts;
else
error("No Tilesize for Zoom found: ", zoom, this.tileSizeByZoom)
}
MapGrid.prototype.normalize = function(coord, zoom){
w = this.tileSize(zoom).w;
h = this.tileSize(zoom).h;
//only northern hemisphere compatible
var left = Math.floor(coord.lon / w) * w;
var top = Math.ceil(coord.lat / h) * h;
var right = left + w;
var bottom = top - h;
var clat = (top + bottom) / 2;
var clon = (left + right) / 2;
var glon = (coord.lon % w >= w / 2) && right || left;
var glat = (coord.lat % h >= h / 2) && top || bottom;
var ret = {
tile: {
lt: {
lat: top,
lon: left
},
rb: {
lat: bottom,
lon: right
}
},
center: {
lat: clat,
lon: clon
},
grid: {
lat: glat,
lon: glon
},
original: coord
}
return ret;
}
MapGrid.prototype.normalizeToCenter = function(coord, zoom){
return this.normalize(coord, zoom).center;
}
MapGrid.prototype.normalizeToGrid = function(coord, zoom){
return this.normalize(coord, zoom).grid;
}
MapGrid.prototype.getMapTile = function(coord, zoom){
return this.normalize(coord, zoom).tile;
}
MapGrid.prototype.test = function(lat, lon){
for (var zoom = 12; zoom < 20; zoom++) {
var tile = this.getMapTile({
lat: lat,
lon: lon
}, zoom);
log(lat, lon, " - ", tile.lt.lat.toFixed(6), tile.lt.lon.toFixed(6), ' - ', tile.rb.lat.toFixed(6), tile.rb.lon.toFixed(6));
}
};
MapGrid.prototype.getMagazineTile = function(coord, zoom){
var factor = this.MAGTILEFACTOR;
var size = this.tileSize(zoom);
if (factor % 2) {
//odd magtilefactors are calculated based on a surrounding tile
start = this.getMapTile(coord, zoom).lt;
}
else {
//even magtilefactors are calculated from a gridpoint
start = this.normalizeToGrid(coord, zoom);
}
var leftTop = {
lat: start.lat + ((factor - 1) * size.h),
lon: start.lon - ((factor - 1) * size.w)
}
var rightBottom = {
lat: leftTop.lat - (factor * size.h),
lon: leftTop.lon + (factor * size.w)
}
var center = {
lat: (leftTop.lat + rightBottom.lat) / 2,
lon: (leftTop.lon + rightBottom.lon) / 2
}
return {
lt: leftTop,
rb: rightBottom,
center: center
}
}
MapGrid.prototype.getEnclosingMapTiles = function(lt, rb, zoom){
var nlt = this.getMapTile(lt, zoom);
var nrb = this.getMapTile(rb, zoom);
var tileSize = this.tileSize(zoom);
var left = nlt.lt.lon;
var top = nlt.lt.lat;
var right = nrb.rb.lon;
var bottom = nrb.rb.lat;
var tiles = [];
for (var x = left; x < right; x += tileSize.w) {
for (var y = top; y > bottom; y -= tileSize.h) {
var len = tiles.push({
lt: {
lat: y,
lon: x
},
rb: {
lat: y - tileSize.h,
lon: x + tileSize.w
}
})
//abort if more than 20 tiles. this must be an error in arguments
if (len > 20) {
error("Calculated more than 20 Tiles. Check your arguments:", lt, rb, zoom)
return tiles;
}
}
}
return tiles;
};
MapGrid.prototype.draw = function(corners, zoom){
corners = corners || this.map.getBorders();
zoom = zoom || this.map.getZoom();
tiles = this.getEnclosingMapTiles(corners.lt, corners.rb, zoom);
for (var i = 0; i < tiles.length; i++) {
var lt = tiles[i].lt;
var rb = tiles[i].rb;
mbMakeLine([lt.lat, lt.lon, lt.lat, rb.lon, rb.lat, rb.lon, rb.lat, lt.lon], 'line');
}
var cz = this.map.getCenterAndZoom();
magtile = this.getMagazineTile(cz, zoom);
};
MapGrid.prototype.drawNormalization = function(o, n, color){
//show both points and draw a line between
mbMakeLine([o.lat, o.lon, n.lat, n.lon], 'line', color)
var pt = new GLatLng(o.lat, o.lon);
var ma = new GMarker(pt)
map.addOverlay(ma);
var pt = new GLatLng(n.lat, n.lon);
var ma = new GMarker(pt)
map.addOverlay(ma);
};
//tile-based pin handler -------------------------------------------------------
TileBasedPinHandler = function(){
this.map;
this.manager;
this.currentRequest;
this.loadedTilesAmount = 1;
this.loadedTilesData = [];
// Changed from 20 to 100 - As we´re only displaying 5 Pins per Tile
// and this ammount doesn´t matter anymore. :-)
this.MAX_PIN_AMOUNT = 100;
// We get the tile sizes from the created table to make sure Zope and JS are
// using exacly the same values because they are used to calculate the cache
// values.
this.tileSizeByZoom = tileSizeConfig;
}
TileBasedPinHandler.prototype.init = function(map){
this.map = map;
this.grid = map.grid;
this.manager = map.manager;
}
TileBasedPinHandler.prototype.getPins = function(ltlat, ltlon, rblat, rblon, zoom, filter){
//abort if same as last request
if (this.currentRequest) {
if (ltlat == this.currentRequest.lt.lat &&
ltlon == this.currentRequest.lt.lon &&
rblat == this.currentRequest.rb.lat &&
rblon == this.currentRequest.rb.lon &&
zoom == this.currentRequest.zoom &&
filter == this.currentRequest.filter) {
warn("requesting pins for the second time. ", this.currentRequest)
}
}
var lt = {
lat: ltlat,
lon: ltlon
};
var rb = {
lat: rblat,
lon: rblon
};
this.currentRequest = {
lt: lt,
rb: rb,
zoom: zoom,
filter: filter,
timestamp: new Date().getTime() //include a timestamp to identifiy the last request
}
var tiles = this.grid.getEnclosingMapTiles(lt, rb, zoom);
log("amount of tiles to load: ", tiles.length)
this.loadedTilesAmount = tiles.length;
this.loadedTilesData = [];
for (var i = 0; i < tiles.length; i++) {
var tile = tiles[i];
this.loadTile(tile.lt, tile.rb, zoom, filter, this.currentRequest.timestamp);
}
}
TileBasedPinHandler.prototype.loadTile = function(lt, rb, zoom, filter, timestamp){
var self = this;
url = this.manager.getGlobals().portalUrl
req = url +
'/area/' +
lt.lat.toFixed(6) +
',' +
lt.lon.toFixed(6) +
'/' +
rb.lat.toFixed(6) +
',' +
rb.lon.toFixed(6) +
'/' +
zoom +
'/' +
filter +
'/pois'
info('req: ',req);
$.getJSON(req, function(json){
self.onTileLoaded(json, timestamp);
});
};
TileBasedPinHandler.prototype.onTileLoaded = function(pins, timestamp){
//check the timestamp and abort if not matching
//and therefor ignore "old" requests
if (timestamp != this.currentRequest.timestamp)
return;
// Aber hier modifiziert für verteilte Ausgabe auf Kacheln - Nur die ersten 5
var MaxPinsPerTile = 10;
if (pins.length > MaxPinsPerTile && zoom < 17)
var newpins = pins.slice(0, MaxPinsPerTile);
else
var newpins = pins;
this.loadedTilesData.push(newpins);
if (this.loadedTilesData.length == this.loadedTilesAmount)
this.compileTiles();
}
TileBasedPinHandler.prototype.compileTiles = function(){
var all = []
for (var i = 0; i < this.loadedTilesData.length; i++) {
all = all.concat(this.loadedTilesData[i]);
}
all = this.filterByBounds(all);
all.sort(function(a, b){
if (a.sort < b.sort) {
return -1;
}
else {
return 1;
}
});
this.onTilesCompiled(all.slice(0, this.MAX_PIN_AMOUNT));
}
TileBasedPinHandler.prototype.filterByBounds = function(pins){
//use the googlemaps api
//google uses left-bottom and right-top corners
var rq = this.currentRequest;
var bounds = new GLatLngBounds(new GLatLng(rq.rb.lat, rq.lt.lon), new GLatLng(rq.lt.lat, rq.rb.lon))
var filtered = [];
for (var i = 0; i < pins.length; i++) {
var pin = pins[i];
var coord = new GLatLng(pin.lat, pin.lon);
if (bounds.contains(coord)) {
filtered.push(pin);
}
}
return filtered;
}
TileBasedPinHandler.prototype.onTilesCompiled = function(pins){
info('on tiles compiled:', pins);
this.map.onPinsForAreaLoaded(pins);
}
TileBasedPinHandler.prototype.toString = function(){
return "[TileBasedPinHandler Object]";
}