/*global google*/ import React, { Component } from 'react'; import { GMap } from '../../components/gmap/GMap'; import { Dialog } from '../../components/dialog/Dialog'; import { InputText } from '../../components/inputtext/InputText'; import { Button } from '../../components/button/Button'; import { Checkbox } from '../../components/checkbox/Checkbox'; import { Toast } from '../../components/toast/Toast'; import { loadGoogleMaps, removeGoogleMaps } from '../load/GoogleMaps'; import { AppInlineHeader } from '../../AppInlineHeader'; import { GMapDoc } from './GMapDoc'; export class GMapDemo extends Component { constructor(props) { super(props); this.state = { googleMapsReady: false, dialogVisible: false, markerTitle: '', draggableMarker: false, overlays: null, selectedPosition: null }; this.onMapClick = this.onMapClick.bind(this); this.onOverlayClick = this.onOverlayClick.bind(this); this.handleDragEnd = this.handleDragEnd.bind(this); this.onMapReady = this.onMapReady.bind(this); this.onHide = this.onHide.bind(this); this.addMarker = this.addMarker.bind(this); } componentDidMount() { loadGoogleMaps(() => { this.setState({ googleMapsReady: true }); }); } componentWillUnmount() { removeGoogleMaps(); } onMapClick(event) { this.setState({ dialogVisible: true, selectedPosition: event.latLng }); } onOverlayClick(event) { let isMarker = event.overlay.getTitle !== undefined; if(isMarker) { let title = event.overlay.getTitle(); this.infoWindow = this.infoWindow||new google.maps.InfoWindow(); this.infoWindow.setContent('
' + title + '
'); this.infoWindow.open(event.map, event.overlay); event.map.setCenter(event.overlay.getPosition()); this.toast.show({severity:'info', summary:'Marker Selected', detail: title}); } else { this.toast.show({severity:'info', summary:'Shape Selected', detail: ''}); } } handleDragEnd(event) { this.toast.show({severity:'info', summary:'Marker Dragged', detail: event.overlay.getTitle()}); } addMarker() { let newMarker = new google.maps.Marker({ position: { lat: this.state.selectedPosition.lat(), lng: this.state.selectedPosition.lng() }, title: this.state.markerTitle, draggable: this.state.draggableMarker }); this.setState({ overlays: [...this.state.overlays, newMarker], dialogVisible: false, draggableMarker: false, markerTitle: '' }); } onMapReady(event) { this.setState({ overlays: [ new google.maps.Marker({position: {lat: 36.879466, lng: 30.667648}, title:"Konyaalti"}), new google.maps.Marker({position: {lat: 36.883707, lng: 30.689216}, title:"Ataturk Park"}), new google.maps.Marker({position: {lat: 36.885233, lng: 30.702323}, title:"Oldtown"}), new google.maps.Polygon({paths: [ {lat: 36.9177, lng: 30.7854},{lat: 36.8851, lng: 30.7802},{lat: 36.8829, lng: 30.8111},{lat: 36.9177, lng: 30.8159} ], strokeOpacity: 0.5, strokeWeight: 1, fillColor: '#1976D2', fillOpacity: 0.35 }), new google.maps.Circle({center: {lat: 36.90707, lng: 30.56533}, fillColor: '#1976D2', fillOpacity: 0.35, strokeWeight: 1, radius: 1500}), new google.maps.Polyline({path: [{lat: 36.86149, lng: 30.63743},{lat: 36.86341, lng: 30.72463}], geodesic: true, strokeColor: '#FF0000', strokeOpacity: 0.5, strokeWeight: 2}) ] }) } onHide(event) { this.setState({dialogVisible: false}); } render() { const options = { center: {lat: 36.890257, lng: 30.707417}, zoom: 12 }; const footer =
; return (

GMap

GMap component provides integration with Google Maps API. This sample demontrates various uses cases like binding, overlays and events. Click the map to add a new item.

{ this.toast = el; }}> { this.state.googleMapsReady && (
) }
this.setState({markerTitle: e.target.value})} />
Lat
Lng
this.setState({draggableMarker: event.checked})}/>
); } }