Revision: 4133 Author: hans URL: http://bknr.net/trac/changeset/4133
Display sponsors in map.
U trunk/projects/bos/payment-website/static/poi-ms/poi-ms.js U trunk/projects/bos/web/contract-tree.lisp U trunk/projects/bos/web/sponsor-handlers.lisp
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-13 21:04:38 UTC (rev 4132) +++ trunk/projects/bos/payment-website/static/poi-ms/poi-ms.js 2008-12-14 09:09:05 UTC (rev 4133) @@ -276,8 +276,17 @@ log('map clicked, overlay: ' + overlay + ' latlng: ' + latlng + ' overlaylatlng: ' + overlaylatlng); }
+ function latLngToPoint(latLng) { + return projection.fromLatLngToPixel(latLng, 6); + } + this.moveEnd = function () { - log('map has moved'); + 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); + + this.sponsorQuery = sw.x + ',' + ne.y + ',' + ne.x + ',' + sw.y; }
GEvent.addListener(this.map, "click", bind(this.mapClicked, this)); @@ -340,15 +349,51 @@ this.map.addOverlay(marker); }
+ this.sponsorMarkers = []; + this.setSponsorMarker = function (sponsor) { var position = pointToLatLng(sponsor.contracts[0].centerX, sponsor.contracts[0].centerY); - if (this.sponsorMarker) { - this.sponsorMarker.setLatLng(position); + var sponsorMarker = new GMarker(position); + this.map.addOverlay(sponsorMarker); + this.sponsorMarkers.push(sponsorMarker); + } + + this.removeSponsorMarkers = function () { + try { + map(bind(this.map.removeOverlay, this.map), this.sponsorMarkers); + this.sponsorMarkers = []; + } + catch (e) { + log('error removing sponsor markers: ' + e); + } + } + + this.startMapMovedChecker = function () { + } + + this.putSponsorPlacemarks = function(data) { + log('got ' + data.sponsors.length + ' sponsors to display'); + this.removeSponsorMarkers(); + try { + map(bind(this.setSponsorMarker, this), data.sponsors); + this.checkMapMoved(); + } + catch (e) { + log('error removing sponsor markers: ' + e); + } + } + + this.checkMapMoved = function() { + if (this.sponsorQuery) { + loadJSONDoc('/sponsors-json?at=' + this.sponsorQuery) + .addCallback(bind(this.putSponsorPlacemarks, this)); + this.sponsorQuery = null; } else { - this.sponsorMarker = new GMarker(position); - this.map.addOverlay(this.sponsorMarker); + callLater(0.5, bind(this.checkMapMoved, this)); } } + + this.checkMapMoved(); }
var pages = {
Modified: trunk/projects/bos/web/contract-tree.lisp =================================================================== --- trunk/projects/bos/web/contract-tree.lisp 2008-12-13 21:04:38 UTC (rev 4132) +++ trunk/projects/bos/web/contract-tree.lisp 2008-12-14 09:09:05 UTC (rev 4133) @@ -443,18 +443,23 @@ #'contract-tree-changed))
(defun contract-size (contract) - (length (contract-m2s contract))) + (apply #'max (cddr (contract-bounding-box contract))))
+(defun geo-box-size (geo-box) + (apply #'max (multiple-value-list (width-height (geo-box-rectangle geo-box))))) + (defun contracts-in-geo-box (geo-box &key limit) "Return all contracts that intersect the given GEO-BOX. If LIMIT is specified, the LIMIT largest contracts are returned." (let ((return-count 0) - (contracts (list nil))) + (contracts (list nil)) + (min-size (floor (/ (geo-box-size geo-box) 10)))) (ensure-intersecting-children *contract-tree* geo-box (lambda (node) (dolist (contract (placemark-contracts node)) - (when (geo-box-encloses-p geo-box (contract-geo-box contract)) + (when (and (geo-box-encloses-p geo-box (contract-geo-box contract)) + (>= (geo-box-size (contract-geo-box contract)) min-size)) (when (and limit (>= return-count limit)) (if (<= (contract-size contract) @@ -468,11 +473,11 @@ (contract-size (cadr point)))) (setf (cdr point) (cons contract (cdr point)))))))) (lambda (node) - (or (and limit + (or (and nil limit (>= return-count limit)) (leaf-node-p node)))) (cdr contracts)))
-y(register-transient-init-function 'make-contract-tree-from-m2 +(register-transient-init-function 'make-contract-tree-from-m2 'make-quad-tree 'geometry:make-rect-publisher)
Modified: trunk/projects/bos/web/sponsor-handlers.lisp =================================================================== --- trunk/projects/bos/web/sponsor-handlers.lisp 2008-12-13 21:04:38 UTC (rev 4132) +++ trunk/projects/bos/web/sponsor-handlers.lisp 2008-12-14 09:09:05 UTC (rev 4133) @@ -361,14 +361,16 @@ (defun sponsors-at (query) (when (cl-ppcre:scan "^[0-9,]+$" query) (destructuring-bind (east north west south) (mapcar #'parse-integer (cl-ppcre:split "," query)) - (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))) - (mapcar #'contract-sponsor - (contracts-in-geo-box (coerce (append (x-y-to-lon-lat east north) - (x-y-to-lon-lat west south)) - '(vector double-float)) - :limit 10)))))) + (when (and (< (- west east) 1000) + (< (- south north) 1000)) + (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))) + (mapcar #'contract-sponsor + (contracts-in-geo-box (coerce (append (x-y-to-lon-lat east north) + (x-y-to-lon-lat west south)) + '(vector double-float)) + :limit 20)))))))
(defun largest-sponsors () (mapcar #'contract-sponsor