Created
November 14, 2008 10:52
-
-
Save tlrobinson/24862 to your computer and use it in GitHub Desktop.
This file contains 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
import <AppKit/CPView.j> | |
// <script src="http://maps.google.com/maps?file=api&v=2&key=GOOGLE_API_KEY" type="text/javascript"></script> | |
// <script type="text/javascript" src="http://www.google.com/jsapi?key=GOOGLE_API_KEY"></script> | |
var GoogleMapsApiKey = "ABQIAAAAf9q-jlyCcenUn-UCanx7ARRbkI1owMIkAJXouQXE6Jt8hWcDOxQBFf2cmFHBXOuqCJRRClFqsVvs9Q", | |
GoogleMapsLoading = NO; | |
@implementation GMapView : CPView | |
{ | |
GMap2 _map; | |
DOMElement _mapDiv; | |
} | |
+ (void)setGoogleMapsAPIKey:(CPString)apiKey | |
{ | |
GOOGLE_API_KEY = apiKey; | |
} | |
+ (void)loadGoogleMapsAPI:(Function)callback | |
{ | |
if (!GoogleMapsLoading && typeof GMap2 == "undefined") | |
{ | |
GoogleMapsLoading = YES; | |
var script = document.createElement("script"); | |
script.setAttribute("type", "text/javascript"); | |
script.setAttribute("src", "http://maps.google.com/maps?file=api&v=2&key="+GoogleMapsApiKey); | |
document.body.appendChild(script); | |
var timerId = window.setInterval(function() | |
{ | |
if (typeof GMap2 == "undefined") | |
{ | |
CPLog.info("not loaded"); | |
} | |
else | |
{ | |
CPLog.info("loaded!"); | |
window.clearInterval(timerId); | |
if (callback) | |
callback(); | |
} | |
}, 100); | |
} | |
else if (typeof GMap2 != "undefined") | |
{ | |
CPLog.info("alread loaded!"); | |
if (callback) | |
callback(); | |
} | |
} | |
- (id)initWithFrame:(CPRect)aFrame | |
{ | |
self = [super initWithFrame:aFrame]; | |
if (self) | |
{ | |
_mapDiv = document.createElement("div"); | |
_mapDiv.style.width = "100%"; | |
_mapDiv.style.height = "100%"; | |
window.setTimeout(function() { | |
//alert("going"); | |
_map = new GMap2(_mapDiv); | |
_map.setCenter(new GLatLng(37.4419, -122.1419), 13); | |
//alert("done"); | |
},0); | |
_DOMElement.appendChild(_mapDiv); | |
} | |
return self; | |
} | |
- (void)mouseDown:(CPEvent)anEvent | |
{ | |
_mapDiv.dispatchEvent(anEvent._DOMEvent); | |
} | |
- (void)mouseDragged:(CPEvent)anEvent | |
{ | |
_mapDiv.dispatchEvent(anEvent._DOMEvent); | |
} | |
- (void)mouseUp:(CPEvent)anEvent | |
{ | |
_mapDiv.dispatchEvent(anEvent._DOMEvent); | |
} | |
- (void)mouseMoved:(CPEvent)anEvent | |
{ | |
_mapDiv.dispatchEvent(anEvent._DOMEvent); | |
} | |
- (void)mouseEntered:(CPEvent)anEvent | |
{ | |
_mapDiv.dispatchEvent(anEvent._DOMEvent); | |
} | |
- (void)mouseExited:(CPEvent)anEvent | |
{ | |
_mapDiv.dispatchEvent(anEvent._DOMEvent); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment