@@ -3,42 +3,66 @@ import './LocationMessage.css';
33
44const classNames = require ( 'classnames' ) ;
55
6+ const STATIC_URL = 'https://maps.googleapis.com/maps/api/staticmap?markers=color:MARKER_COLOR|LATITUDE,LONGITUDE&zoom=ZOOM&size=270x200&scale=2&key=KEY' ;
7+ const MAP_URL = 'https://www.google.com/maps/search/?api=1&query=LATITUDE,LONGITUDE&zoom=ZOOM' ;
8+ const DEFAULT_MARKER_COLOR = 'red' ;
9+ const DEFAULT_ZOOM_LEVEL = 14 ;
10+
611export class LocationMessage extends Component {
712 constructor ( props ) {
813 super ( props ) ;
914
10- const {
11- latitude,
12- longitude,
13- } = this . props . data || { } ;
15+ this . className = this . className . bind ( this ) ;
16+ }
17+
18+ buildURL ( url ) {
19+ var center = this . props . data ;
20+
21+ return url . replace ( 'LATITUDE' , center . latitude )
22+ . replace ( 'LONGITUDE' , center . longitude )
23+ . replace ( 'MARKER_COLOR' , this . props . markerColor || DEFAULT_MARKER_COLOR )
24+ . replace ( 'ZOOM' , this . props . zoom || DEFAULT_ZOOM_LEVEL )
25+ . replace ( 'KEY' , this . props . apiKey ) ;
26+ }
27+
28+ className ( ) {
29+ var className = classNames ( 'rce-mbox-location' , this . props . className ) ;
30+
31+ if ( this . props . text && this . props . text . length > 0 ) {
32+ className = classNames ( className , 'rce-mbox-location-has-text' ) ;
33+ }
1434
15- var key = this . props . apiKey ? ( '&key=' + this . props . apiKey ) : '' ;
16- this . state = {
17- url : 'https://maps.googleapis.com/maps/api/staticmap?markers=color:red|' + latitude + ',' + longitude + '&zoom=14&size=270x200&scale=2' + key ,
18- } ;
35+ return className ;
1936 }
2037
2138 render ( ) {
2239 return (
23- < a
24- onClick = { this . props . onOpen }
25- target = { this . props . target }
26- href = { this . props . href || this . props . src || this . state . url }
27- className = { classNames ( 'rce-mbox-location' , this . props . className ) } >
28- < img
29- className = 'rce-mbox-location-img'
30- src = {
31- this . props . src ||
32- this . state . url
33- } />
34- </ a >
40+ < div >
41+ < a
42+ onClick = { this . props . onOpen }
43+ target = { this . props . target }
44+ href = { this . props . href || this . props . src || this . buildURL ( MAP_URL ) }
45+ className = { this . className ( ) } >
46+ < img className = 'rce-mbox-location-img'
47+ src = {
48+ this . props . src ||
49+ this . buildURL ( STATIC_URL )
50+ } />
51+ </ a >
52+ {
53+ this . props . text &&
54+ < div className = "rce-mbox-text rce-mbox-location-text" >
55+ { this . props . text }
56+ </ div >
57+ }
58+ </ div >
3559 ) ;
3660 }
3761}
3862
3963LocationMessage . defaultProps = {
4064 target : '_blank' ,
41- apiKey : null ,
65+ apiKey : '' ,
4266}
4367
4468export default LocationMessage ;
0 commit comments