@@ -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+
69export class LocationMessage extends Component {
710 constructor ( props ) {
811 super ( props ) ;
912
10- const {
11- latitude,
12- longitude,
13- } = this . props . data || { } ;
13+ this . className = this . className . bind ( this ) ;
14+ }
15+
16+ buildURL ( url ) {
17+ var center = this . props . data || { } ;
18+
19+ return url . replace ( 'LATITUDE' , center . latitude )
20+ . replace ( 'LONGITUDE' , center . longitude )
21+ . replace ( 'MARKER_COLOR' , this . props . markerColor )
22+ . replace ( 'ZOOM' , this . props . zoom )
23+ . replace ( 'KEY' , this . props . apiKey ) ;
24+ }
25+
26+ className ( ) {
27+ var className = classNames ( 'rce-mbox-location' , this . props . className ) ;
28+
29+ if ( this . props . text ) {
30+ className = classNames ( className , 'rce-mbox-location-has-text' ) ;
31+ }
1432
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- } ;
33+ return className ;
1934 }
2035
2136 render ( ) {
2237 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 >
38+ < div className = 'rce-container-lmsg' >
39+ < a
40+ onClick = { this . props . onOpen }
41+ target = { this . props . target }
42+ href = { this . props . href || this . props . src || this . buildURL ( MAP_URL ) }
43+ className = { this . className ( ) } >
44+ < img className = 'rce-mbox-location-img'
45+ src = {
46+ this . props . src ||
47+ this . buildURL ( STATIC_URL )
48+ } />
49+ </ a >
50+ {
51+ this . props . text &&
52+ < div className = "rce-mbox-text rce-mbox-location-text" >
53+ { this . props . text }
54+ </ div >
55+ }
56+ </ div >
3557 ) ;
3658 }
3759}
3860
3961LocationMessage . defaultProps = {
4062 target : '_blank' ,
41- apiKey : null ,
63+ apiKey : '' ,
64+ zoom : 14 ,
65+ markerColor : 'red' ,
4266}
4367
4468export default LocationMessage ;
0 commit comments