[bknr-cvs] hans changed trunk/projects/bos/

BKNR Commits bknr at bknr.net
Sun Dec 14 23:17:22 UTC 2008


Revision: 4135
Author: hans
URL: http://bknr.net/trac/changeset/4135

Better sponsor placemark loading, add "Sponsors" pseudo POI.

U   trunk/projects/bos/payment-website/static/poi-ms/poi-ms.html
U   trunk/projects/bos/payment-website/static/poi-ms/poi-ms.js
U   trunk/projects/bos/web/sponsor-handlers.lisp

Modified: trunk/projects/bos/payment-website/static/poi-ms/poi-ms.html
===================================================================
--- trunk/projects/bos/payment-website/static/poi-ms/poi-ms.html	2008-12-14 13:58:07 UTC (rev 4134)
+++ trunk/projects/bos/payment-website/static/poi-ms/poi-ms.html	2008-12-14 23:17:22 UTC (rev 4135)
@@ -24,7 +24,7 @@
       </div>
       <div id="content">
         <h1 id="title"></h1>
-        <div id="map"><img src="fake-map.jpg" width="505" height="505"/></div>
+        <div id="map" class="large"><img src="fake-map.jpg" width="505" height="505"/></div>
    	<div id="content-body">
         </div>
       </div>

Modified: trunk/projects/bos/payment-website/static/poi-ms/poi-ms.js
===================================================================
--- trunk/projects/bos/payment-website/static/poi-ms/poi-ms.js	2008-12-14 13:58:07 UTC (rev 4134)
+++ trunk/projects/bos/payment-website/static/poi-ms/poi-ms.js	2008-12-14 23:17:22 UTC (rev 4135)
@@ -178,6 +178,7 @@
 }
 
 function showOverview() {
+    log('showOverview');
     $('#back').css('visibility', 'hidden');
 
     $('#title').text(NLS('Ãœbersicht'));
@@ -189,6 +190,13 @@
     .empty()
     .append(UL({ id: 'poi-list' }));
 
+    $('#poi-list')
+    .append($(LI(null,
+                 A({ href: '#' },
+                   IMG({ src: "http://www.google.com/mapfiles/marker.png" }),
+                   B(NLS("Sponsoren")))))
+            .bind('click', showSponsors));
+
     for (var i in pois) {
         var poi = pois[i];
         $('#poi-list')
@@ -269,8 +277,8 @@
         }
     }
 
-//    this.map.enableContinuousZoom();
-//    this.map.enableScrollWheelZoom();
+    this.map.enableContinuousZoom();
+    this.map.enableScrollWheelZoom();
 
     this.mapClicked = function (overlay, latlng, overlaylatlng) {
         log('map clicked, overlay: ' + overlay + ' latlng: ' + latlng + ' overlaylatlng: ' + overlaylatlng);
@@ -284,7 +292,7 @@
         var bounds = this.map.getBounds();
         var sw = latLngToPoint(bounds.getSouthWest());
         var ne = latLngToPoint(bounds.getNorthEast());
-        log('map has moved: ' + sw.x + ',' + ne.y + ',' + ne.x + ',' + sw.y);
+//        log('map has moved: ' + sw.x + ',' + ne.y + ',' + ne.x + ',' + sw.y);
 
         this.sponsorQuery = sw.x + ',' + ne.y + ',' + ne.x + ',' + sw.y;
     }
@@ -292,10 +300,28 @@
     GEvent.addListener(this.map, "click", bind(this.mapClicked, this));
     GEvent.addListener(this.map, "moveend", bind(this.moveEnd, this));
 
+    this.sponsorMarkers = [];
+
+    this.removeSponsorMarkers = function (all) {
+        log('remove sponsor markers');
+        var markers = [];
+        var gmap = this.map;
+        map(function(marker) {
+            if (!all && marker.opened) {
+                markers.push(marker);
+            } else {
+                gmap.removeOverlay(marker);
+            }
+        }, this.sponsorMarkers);
+        this.sponsorMarkers = markers;
+        log('done');
+    }
+
     this.overview = function () {
         this.show();
         $('#map').removeClass('small');
         $('#map').addClass('large');
+        this.removeSponsorMarkers(true);
         this.addControls();
         this.map.checkResize();
         this.map.setCenter(projection.fromPixelToLatLng(new GPoint(6500, 6350), 6), 2, customMap);
@@ -304,6 +330,7 @@
     this.poiDetail = function (x, y) {
         $('#map').removeClass('large');
         $('#map').addClass('small');
+        this.removeSponsorMarkers(true);
         this.removeControls();
         this.map.checkResize();
         this.map.setCenter(projection.fromPixelToLatLng(new GPoint(x, y), 6), 6);
@@ -349,8 +376,6 @@
         this.map.addOverlay(marker);
     }
 
-    this.sponsorMarkers = [];
-
     function makeTable(rows) {
         return TABLE({ 'class': 'sponsor-info-popup' },
                      TBODY(null,
@@ -364,7 +389,6 @@
     this.setSponsorMarker = function (sponsor) {
         var position = pointToLatLng(sponsor.contracts[0].centerX, sponsor.contracts[0].centerY);
         var sponsorMarker = new GMarker(position);
-        log('sponsor: ' + serializeJSON(sponsor));
         var info = [
             [ "Name", sponsor.name || NLS("[anonym]") ],
             [ "Country", sponsor.country ],
@@ -374,20 +398,28 @@
             info.push([ "Info", sponsor.infoText ]);
         }
         sponsorMarker.bindInfoWindow(makeTable(info));
+
+        function setMarkerOpened(marker, state) {
+            marker.opened = state;
+        }
+        
+        GEvent.addListener(this.map, "infowindowopen", partial(setMarkerOpened, sponsorMarker, true));
+        GEvent.addListener(this.map, "infowindowclose", partial(setMarkerOpened, sponsorMarker, false));
+
         this.map.addOverlay(sponsorMarker);
         this.sponsorMarkers.push(sponsorMarker);
     }
 
-    this.removeSponsorMarkers = function () {
-        map(bind(this.map.removeOverlay, this.map), this.sponsorMarkers);
-        this.sponsorMarkers = [];
-    }
-
     this.putSponsorPlacemarks = function(data) {
-        log('got ' + data.sponsors.length + ' sponsors to display');
-        this.removeSponsorMarkers();
-        map(bind(this.setSponsorMarker, this), data.sponsors);
-        this.checkMapMoved();
+        try {
+            log('got ' + data.sponsors.length + ' sponsors to display');
+            this.removeSponsorMarkers();
+            map(bind(this.setSponsorMarker, this), data.sponsors);
+            this.checkMapMoved();
+        }
+        catch (e) {
+            log('error ' + e + ' putting sponsor placemarks');
+        }
     }
 
     this.checkMapMoved = function() {
@@ -399,8 +431,6 @@
             callLater(0.5, bind(this.checkMapMoved, this));
         }
     }
-
-    this.checkMapMoved();
 }
 
 var pages = {
@@ -427,17 +457,17 @@
 
     mainMap.zoomTo(contract.left, contract.top, 8);
     mainMap.setSponsorMarker(sponsor);
-    
-    // Math.max(contract.width, contract.height)
 }
 
 function showSponsors() {
 
     $('#left-bar')
     .empty()
-    .append(H3(NLS("Letzte Sponsoren")),
-            UL({ id: 'sponsor-list' }));
+//    .append(H3(NLS("Letzte Sponsoren")),
+//            UL({ id: 'sponsor-list' }))
+    ;
 
+    $('#title').text(NLS('Sponsoren'));
     map(function (sponsor) {
         $('#sponsor-list')
         .append($(LI(null,
@@ -451,15 +481,19 @@
     }, sponsors.slice(0, 10));
 
     mainMap.overview();
+    mainMap.zoomTo(7100, 5400, 5);
+    mainMap.checkMapMoved();
 }
 
-function loadSponsors(data) {
+function loadPOIs(data) {
     try {
-        for (var i in data.sponsors) {
-            var sponsor = data.sponsors[i];
-            sponsors.push(sponsor);
+        for (var i in data.pois) {
+            var poi = data.pois[i];
+            pois[poi.id] = poi;
         }
 
+        mainMap = new Map();
+
         var poi_id = document.location.hash.replace(/#/, "");
         if (poi_id) {
             showPOI(pois[poi_id]);
@@ -472,22 +506,6 @@
     }
 }
 
-function loadPOIs(data) {
-    try {
-        for (var i in data.pois) {
-            var poi = data.pois[i];
-            pois[poi.id] = poi;
-        }
-
-        mainMap = new Map();
-
-        loadJSONDoc('/sponsors-json').addCallback(loadSponsors);
-    }
-    catch (e) {
-        alert(e);
-    }
-}
-
 function init() {
     $('#small-map a').bind('click', showOverview);
 

Modified: trunk/projects/bos/web/sponsor-handlers.lisp
===================================================================
--- trunk/projects/bos/web/sponsor-handlers.lisp	2008-12-14 13:58:07 UTC (rev 4134)
+++ trunk/projects/bos/web/sponsor-handlers.lisp	2008-12-14 23:17:22 UTC (rev 4135)
@@ -361,8 +361,8 @@
 (defun sponsors-at (query)
   (when (cl-ppcre:scan "^[0-9,]+$" query)
     (destructuring-bind (east north west south) (mapcar #'parse-integer (cl-ppcre:split "," query))
-      (when (and (< (- west east) 1000)
-                 (< (- south north) 1000))
+      (when (and (< (- west east) 1500)
+                 (< (- south north) 1500))
         (labels
             ((x-y-to-lon-lat (x y)
                (geo-utm:utm-x-y-to-lon-lat (+ +nw-utm-x+ x) (- +nw-utm-y+ y) +utm-zone+ t)))





More information about the Bknr-cvs mailing list