Friday, 10 August 2018

skyscanner api



<div data-skyscanner-widget="SearchWidget" data-locale="en-US" data-params="colour:solar;fontColour:#000;buttonColour:dawn;buttonFontColour:#fff;"></div>

<script src="https://widgets.skyscanner.net/widget-server/js/loader.js" async></script>

reference:
http://chuanshuoge2.blogspot.com/2018/08/integrate-travel-search-engine-on-your.html

integrate travel search engine on your website

Free APIs
Most of the leading metasearch engines have their affiliate programs whereby they give you free access to their APIs. You can easily join them to get API access which can be used to feed your travel aggregator site. This solves two of your challenges in one shot – data aggregation and revenue generation. Some popular affiliate programs with API access are:

reference:
 https://www.promptcloud.com/blog/how-to-create-online-travel-website
https://partners.skyscanner.net/affiliates/widgets-quick-start
http://graphemica.com/%C2%B1

Thursday, 9 August 2018

web credit card process


reference:
https://www.itworld.com/article/2832817/consumerization/how-to-process-and-accept-credit-cards-on-your-website.html
https://stackoverflow.com/questions/51094/payment-processors-what-do-i-need-to-know-if-i-want-to-accept-credit-cards-on
https://hackernoon.com/how-to-integrate-stripe-payments-in-web-application-2c72d5c67454
https://stripe.com/docs
https://stripe.com/docs/recipes/elements-react

react google map 2

project site: http://chuanshuoge1-react-map.surge.sh/

traffic layer

panorama view 

drawing manager

traffic layer

import React, { Component } from 'react';
import '../App.css';
import googleUrl from './key';

import { compose, withProps } from "recompose";
import {
    withScriptjs,
    withGoogleMap,
    GoogleMap,
    TrafficLayer,
} from "react-google-maps";

class Traffic extends Component {
    constructor(props) {
        super(props);

        this.state = {

        };
    }

    render() {
        const MyMap = compose(
            withProps({
                googleMapURL: googleUrl.url1,
                loadingElement: <div style={{ height: `100%` }} />,
                containerElement: <div style={{ height: `400px` }} />,
                mapElement: <div style={{ height: `100%` }} />,
            }),
            withScriptjs,
            withGoogleMap
        )(props =>
            <GoogleMap
                defaultZoom={8}
                defaultCenter={{ lat: 41.9, lng: -87.624 }}
            >
                <TrafficLayer autoUpdate />
            </GoogleMap>
            );

        return (
            <MyMap />
        );
    }
}

export default Traffic;

-----------------------------------------

street view

import React, { Component } from 'react';
import '../App.css';
import googleUrl from './key';

import { compose, withProps} from "recompose";
import {
    withScriptjs,
    withGoogleMap,
    GoogleMap,
    StreetViewPanorama,
    OverlayView,
} from "react-google-maps";
import FaAnchor from "react-icons/lib/fa/anchor";

const getPixelPositionOffset = (width, height) => ({
    x: -(width / 2),
    y: -(height / 2),
})

class StreetView extends Component {
    constructor(props) {
        super(props);

        this.state = {

        };
    }

    render() {
        const MyMap = compose(
            withProps({
                googleMapURL: googleUrl.url1,
                loadingElement: <div style={{ height: `100%` }} />,
                containerElement: <div style={{ height: `400px` }} />,
                mapElement: <div style={{ height: `100%` }} />,
                center: { lat: 49.2853171, lng: -123.1119202 },
            }),
            withScriptjs,
            withGoogleMap
        )(props =>
            <GoogleMap defaultZoom={8} defaultCenter={props.center}>
                <StreetViewPanorama defaultPosition={props.center} visible>
                    <OverlayView
                        position={{ lat: 49.28590291211115, lng: -123.11248166065218 }}
                        mapPaneName={OverlayView.OVERLAY_LAYER}
                        getPixelPositionOffset={getPixelPositionOffset}
                    >
                        <div style={{ background: `red`, color: `white`, padding: 5, borderRadius: `50%` }}>
                            OverlayView
        </div>
                    </OverlayView>
                </StreetViewPanorama>
            </GoogleMap>
            );

        return (
            <MyMap />
        );
    }
}

export default StreetView;

------------------------------------------

kml layer

import React, { Component } from 'react';
import '../App.css';
import googleUrl from './key';

import { compose, withProps } from "recompose";
import {
    withScriptjs,
    withGoogleMap,
    GoogleMap,
    KmlLayer,
} from "react-google-maps";

class Kml extends Component {
    constructor(props) {
        super(props);

        this.state = {

        };
    }

    render() {
        const MyMap = compose(
            withProps({
                googleMapURL: googleUrl.url1,
                loadingElement: <div style={{ height: `100%` }} />,
                containerElement: <div style={{ height: `400px` }} />,
                mapElement: <div style={{ height: `100%` }} />,
                center: { lat: -34.397, lng: 150.644 },
            }),
            withScriptjs,
            withGoogleMap
        )(props =>
            <GoogleMap
                defaultZoom={9}
                defaultCenter={{ lat: 41.9, lng: -87.624 }}
            >
                <KmlLayer
                    url="http://googlemaps.github.io/js-v2-samples/ggeoxml/cta.kml"
                    options={{ preserveViewport: true }}
                />
            </GoogleMap>
            );

        return (
            <MyMap />
        );
    }
}

export default Kml;

-------------------------------------------

ground overlay

import React, { Component } from 'react';
import '../App.css';
import googleUrl from './key';

import { compose, withProps} from "recompose";
import {
    withScriptjs,
    withGoogleMap,
    GoogleMap,
    GroundOverlay,
} from "react-google-maps";

const google = window.google;

class MapWithGroundOverlay extends Component {
    constructor(props) {
        super(props);

        this.state = {

        };
    }

    render() {
        const MyMap = compose(
            withProps({
                googleMapURL: googleUrl.url1,
                loadingElement: <div style={{ height: `100%` }} />,
                containerElement: <div style={{ height: `400px` }} />,
                mapElement: <div style={{ height: `100%` }} />,
                center: { lat: -34.397, lng: 150.644 },
            }),
            withScriptjs,
            withGoogleMap
        )(props =>
            <GoogleMap
                defaultZoom={12}
                defaultCenter={{ lat: 40.740, lng: -74.18 }}
            >

                <GroundOverlay
                    defaultUrl="https://www.lib.utexas.edu/maps/historical/newark_nj_1922.jpg"
                    defaultBounds={new google.maps.LatLngBounds(
                        new google.maps.LatLng(40.712216, -74.22655),
                        new google.maps.LatLng(40.773941, -74.12544)
                    )}
                    defaultOpacity={.5}
                />
            </GoogleMap>
            );

        return (
            <MyMap />
        );
    }
}

export default MapWithGroundOverlay;

----------------------------------------

drawing manager

import React, { Component } from 'react';
import '../App.css';
import googleUrl from './key';

import { compose, withProps } from "recompose";
import {
    withScriptjs,
    withGoogleMap,
    GoogleMap,
} from "react-google-maps";
import { DrawingManager } from "react-google-maps/lib/components/drawing/DrawingManager";

const google = window.google;

class MapWithADrawingManager extends Component {
    constructor(props) {
        super(props);

        this.state = {

        };
    }

    render() {
        const MyMap = compose(
            withProps({
                googleMapURL: googleUrl.url3,
                loadingElement: <div style={{ height: `100%` }} />,
                containerElement: <div style={{ height: `400px` }} />,
                mapElement: <div style={{ height: `100%` }} />,
            }),
            withScriptjs,
            withGoogleMap
        )(props =>
            <GoogleMap
                defaultZoom={8}
                defaultCenter={new google.maps.LatLng(-34.397, 150.644)}
            >

                <DrawingManager
                    defaultDrawingMode={google.maps.drawing.OverlayType.CIRCLE}
                    defaultOptions={{
                        drawingControl: true,
                        drawingControlOptions: {
                            position: google.maps.ControlPosition.TOP_CENTER,
                            drawingModes: [
                                google.maps.drawing.OverlayType.CIRCLE,
                                google.maps.drawing.OverlayType.POLYGON,
                                google.maps.drawing.OverlayType.POLYLINE,
                                google.maps.drawing.OverlayType.RECTANGLE,
                            ],
                        },
                        circleOptions: {
                            fillColor: `#ffff00`,
                            fillOpacity: 1,
                            strokeWeight: 5,
                            clickable: false,
                            editable: true,
                            zIndex: 1,
                        },
                    }}
                />
            </GoogleMap>
            );

        return (
            <MyMap />
        );
    }
}

export default MapWithADrawingManager;

reference:

Saturday, 4 August 2018

react google map

project site: http://chuanshuoge1-react-map.surge.sh/


marker cluster, menu opened


direction api, menu collapse


fusion layer, toggle sub menu
--src
  --app.js
  --app.css
  --index.js
  --category
    --bicyclingLayer.js
    --directionsRenderer.js
    --key.js
    --markerCluster.js
    --singleMarker.js
--package.json

package.json

{
  "name": "react-map",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "antd": "^3.7.3",
    "react": "^16.4.1",
    "react-dom": "^16.4.1",
    "react-google-maps": "^9.4.5",
    "react-router-dom": "^4.3.1",
    "react-scripts": "1.1.4"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  }
}

------------------------------------------------

public/index.html 

add  <script src="https://maps.googleapis.com/maps/api/js"></script>

------------------------------------------------

src/index.js

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import registerServiceWorker from './registerServiceWorker';
import { BrowserRouter } from 'react-router-dom'

ReactDOM.render(<BrowserRouter><App /></BrowserRouter>, document.getElementById('root'));
registerServiceWorker();

---------------------------------------------------------

app.js

import React, { Component } from 'react';
import './App.css';
import { Switch, Route, Link } from 'react-router-dom';

import SingleMarker from './category/singleMarker';
import MarkerCluster from './category/markerCluster';
import BicyclingLayer from './category/bicyclingLayer';
import DirectionRenderer from './category/directionsRenderer';
import MapWithAFusionTablesLayer from './category/fusionLayer';
import MapWithADrawingManager from './category/drawingManager';
import ControlledZoom from './category/controlledZoom';
import MapWithGroundOverlay from './category/groundOverlay';
import Kml from './category/kmlLayer';
import MapWithASearchBox from './category/searchBox';

import 'antd/dist/antd.css';
import { Row, Col, Menu, Icon, Button } from 'antd';

const SubMenu = Menu.SubMenu;

class App extends Component {
    constructor(props) {
        super(props);

        this.state = {
            menuCollapse: false,
            menuGrid: 6,
            mapGrid: 18,
        };
    }

    handleClickCollapse() {
        this.state.menuCollapse ?
            this.setState({
                menuCollapse: false,
                menuGrid: 6,
                mapGrid: 18,
            }) :
            this.setState({
                menuCollapse: true,
                menuGrid: 2,
                mapGrid: 22,
            })
    }

    render() {

        return (
            <div>
                <Row>
                    <Col span={this.state.menuGrid}>
                        <Button type="primary" size='large' type="dashed"
                            className='collapseButton'
                            onClick={() => this.handleClickCollapse()}>
                            <h2>
                                {this.state.menuCollapse ? null : 'Gooogle Map'}
                                <Icon type={this.state.menuCollapse ? 'double-right' : 'double-left'} />
                            </h2>
                        </Button>

                        <Menu
                            defaultSelectedKeys={['2']}
                            defaultOpenKeys={['sub1']}
                            mode="inline"
                            inlineCollapsed={this.state.menuCollapse}
                        >
                            <SubMenu key="sub1" title={<span><Icon type="pushpin-o" /><span>Marker</span></span>}>

                                <Menu.Item key="1"><Link to='/singleMarker' className="my-link-color">Single Marker</Link></Menu.Item>
                                <Menu.Item key="2"><Link to='/markerCluster' className="my-link-color">Marker Cluster</Link></Menu.Item>                             
                            </SubMenu>

                            <SubMenu key="sub2" title={<span><Icon type="switcher" /><span>Layer</span></span>}>

                                <Menu.Item key="3"><Link to='/bicycleLayer' className="my-link-color">Bicycling Layer</Link></Menu.Item>                             
                                <Menu.Item key="5"><Link to='/fusionLayer' className="my-link-color">Fusion Layer</Link></Menu.Item>                               
                                <Menu.Item key="8"><Link to='/groundOverlay' className="my-link-color">Ground Overlay</Link></Menu.Item>
                                <Menu.Item key="9"><Link to='/kmlLayer' className="my-link-color">Kml Layer</Link></Menu.Item>                             
                            </SubMenu>

                            <SubMenu key="sub3" title={<span><Icon type="tool" /><span>Control</span></span>}>

                                <Menu.Item key="4"><Link to='/directionRenderer' className="my-link-color">Direction renderer</Link></Menu.Item>
                                <Menu.Item key="6"><Link to='/drawingManager' className="my-link-color">Drawing Manager</Link></Menu.Item>
                                <Menu.Item key="7"><Link to='/controlledZoom' className="my-link-color">Controlled Zoom</Link></Menu.Item>
                                <Menu.Item key="10"><Link to='/searchBox' className="my-link-color">Search Box</Link></Menu.Item>
                            </SubMenu>
                        </Menu>
                    </Col>
                    <Col span={this.state.mapGrid}>
                        <Switch>
                            <Route exact path='/' component={MarkerCluster} />
                            <Route path='/singleMarker' component={SingleMarker} />
                            <Route path='/markerCluster' component={MarkerCluster} />
                            <Route path='/bicycleLayer' component={BicyclingLayer} />
                            <Route path='/directionRenderer' component={DirectionRenderer} />
                            <Route path='/fusionLayer' component={MapWithAFusionTablesLayer} />
                            <Route path='/drawingManager' component={MapWithADrawingManager} />
                            <Route path='/controlledZoom' component={ControlledZoom} />
                            <Route path='/groundOverlay' component={MapWithGroundOverlay} />
                            <Route path='/kmlLayer' component={Kml} />
                            <Route path='/searchBox' component={MapWithASearchBox} />
                        </Switch>
                    </Col>
                </Row>


            </div>
        );
    }
}

export default App;

-------------------------------------------------

app.css

.my-link-color {
    color: white;
    text-decoration: none;
}

    .my-link-color:hover {
        color: cyan;
        text-decoration: none;
    }

.my-link-color:focus {
    color: gold;
    text-decoration: none;
}

.my-infoBox{
    background-color:gold;
    width:50px;
}

.collapseButton{
    width:100%;
}
---------------------------------------------

category/key.js

const apiKey1 = 'AIzaSyCBNpYVkcXG8TYxFwI4oymTaSFaHrsLULc';
const apiKey2 = 'AIzaSyBfWxcbSfG6xZE4J7adQwjbskYgl64-Cvc';
const apiKey3 = 'AIzaSyBrKRs5NQL0dBEb1oJNK_K96jkN71N0GT4';
const apiKey4 = 'AIzaSyDRrz98hmiLfSoCXNNm2jcVc1e1wTENAhA';

const googleUrl = {
    url1: "https://maps.googleapis.com/maps/api/js?key=" + apiKey1 + "&v=3.exp&libraries=geometry,drawing,places",
    url2: "https://maps.googleapis.com/maps/api/js?key=" + apiKey2 + "&v=3.exp&libraries=geometry,drawing,places",
    url3: "https://maps.googleapis.com/maps/api/js?key=" + apiKey3 + "&v=3.exp&libraries=geometry,drawing,places",
    url4: "https://maps.googleapis.com/maps/api/js?key=" + apiKey4 + "&v=3.exp&libraries=geometry,drawing,places",
}

export default googleUrl;

-------------------------------------------

category/singleMarker.js


import React, { Component } from 'react';
import '../App.css';
import googleUrl from './key';

import { Icon } from 'antd';

import { compose, withProps, withStateHandlers } from "recompose";
import {
    withScriptjs,
    withGoogleMap,
    GoogleMap,
    Marker,
} from "react-google-maps";
import { InfoBox } from "react-google-maps/lib/components/addons/InfoBox";

class SingleMarker extends Component {
    constructor(props) {
        super(props);

        this.state = {
            infoBoxOpen: true,
        };
    }


    handleMarkerClick = () => {
        this.setState(prevState => { return { infoBoxOpen: !prevState.infoBoxOpen } })
    }

    render() {
        const MyMap = compose(
            withProps({
                googleMapURL: googleUrl.url1,
                loadingElement: <div style={{ height: `100%` }} />,
                containerElement: <div style={{ height: `400px` }} />,
                mapElement: <div style={{ height: `100%` }} />,
                center: { lat: -34.397, lng: 150.644 },
            }),
            withScriptjs,
            withGoogleMap
        )(props =>
            <GoogleMap
                defaultZoom={5}
                defaultCenter={props.center}
            >

                <Marker position={props.center}
                    draggable={true}
                    onClick={() => this.handleMarkerClick()} >

                    {this.state.infoBoxOpen &&
                        <InfoBox>
                        <h1 className='my-infoBox'> <Icon type="info-circle-o"/>abc</h1>                     
                        </InfoBox>
                    }
                </Marker>}
            </GoogleMap>
            );

        return (
            <MyMap />
        );
    }
}

export default SingleMarker;

---------------------------------------------------------

markerCluster.js

import React, { Component } from 'react';
import '../App.css';
import googleUrl from './key';

import { withScriptjs, withGoogleMap, GoogleMap, Marker } from "react-google-maps";
import { compose, withProps, withHandlers } from "recompose";
import { MarkerClusterer } from "react-google-maps/lib/components/addons/MarkerClusterer";
import fetch from "isomorphic-fetch";

class MarkerCluster extends Component {
    constructor(props) {
        super(props);

        this.state = {
            markers: [],
        };
    }

    componentDidMount() {
        const url = [
            // Length issue
            `https://gist.githubusercontent.com`,
            `/farrrr/dfda7dd7fccfec5474d3`,
            `/raw/758852bbc1979f6c4522ab4e92d1c92cba8fb0dc/data.json`
        ].join("")

        fetch(url)
            .then(res => res.json())
            .then(data => {
                this.setState({ markers: data.photos });
            });
    }

    render() {

        const MyMapComponent = compose(
            withProps({
                googleMapURL: googleUrl.url1,
                loadingElement: <div style={{ height: `100%` }} />,
                containerElement: <div style={{ height: `400px` }} />,
                mapElement: <div style={{ height: `100%` }} />,
            }),
            withHandlers({
                onMarkerClustererClick: () => (markerClusterer) => {
                    const clickedMarkers = markerClusterer.getMarkers()
                    console.log(`Current clicked markers length: ${clickedMarkers.length}`)
                    console.log(clickedMarkers)
                }
            }),
            withScriptjs,
            withGoogleMap
        )((props) =>
            <GoogleMap
                defaultZoom={1}
                defaultCenter={{ lat: 25.0391667, lng: 121.525 }}
            >

                {/***cluster****/}

                <MarkerClusterer
                    onClick={props.onMarkerClustererClick}
                    averageCenter
                    enableRetinaIcons
                    gridSize={60}
                >
                    {this.state.markers.map(marker => (
                        <Marker
                            key={marker.photo_id}
                            position={{ lat: marker.latitude, lng: marker.longitude }}
                        />
                    ))}
                </MarkerClusterer>
            </GoogleMap>
            )

        return (
            <MyMapComponent />
        );
    }
}

export default MarkerCluster;

----------------------------------------------------

bicyclingLayer.js

import React, { Component } from 'react';
import '../App.css';
import googleUrl from './key';

import { compose, withProps, withStateHandlers } from "recompose";
import {
    withScriptjs,
    withGoogleMap,
    GoogleMap,
    BicyclingLayer,
} from "react-google-maps";

class BikeLayer extends Component {
    constructor(props) {
        super(props);

        this.state = {
       
        };
    }

    render() {
        const MyMap = compose(
            withProps({
                googleMapURL: googleUrl.url1,
                loadingElement: <div style={{ height: `100%` }} />,
                containerElement: <div style={{ height: `400px` }} />,
                mapElement: <div style={{ height: `100%` }} />,
            }),
            withScriptjs,
            withGoogleMap
        )(props =>
            <GoogleMap
                defaultZoom={12}
                defaultCenter={{ lat: 34.17223, lng: -118.37897 }}
            >

                <BicyclingLayer autoUpdate />
            </GoogleMap>
            );

        return (
            <MyMap />
        );
    }
}

export default BikeLayer;

---------------------------------------------------

import React, { Component } from 'react';
import '../App.css';
import googleUrl from './key';

import { compose, withProps, lifecycle } from "recompose";
import {
    withScriptjs,
    withGoogleMap,
    GoogleMap,
    DirectionsRenderer,
} from "react-google-maps";

const google = window.google

class Direction extends Component {
    constructor(props) {
        super(props);

        this.state = {
        };
    }

    render() {

        const MyMap = compose(
            withProps({
                googleMapURL: googleUrl.url3,
                loadingElement: <div style={{ height: `100%` }} />,
                containerElement: <div style={{ height: `400px` }} />,
                mapElement: <div style={{ height: `100%` }} />,
            }),
            withScriptjs,
            withGoogleMap,
            lifecycle({
                componentDidMount() {
                    const DirectionsService = new google.maps.DirectionsService();

                    DirectionsService.route({
                        origin: new google.maps.LatLng(41, -87),
                        destination: new google.maps.LatLng(42, -88),
                        travelMode: google.maps.TravelMode.DRIVING,
                    }, (result, status) => {
                        if (status === google.maps.DirectionsStatus.OK) {
                            this.setState({
                                directions: result,
                            });
                        } else {
                            console.error(`error fetching directions ${result}`);
                        }
                    });
                }
            })
        )(props =>
            <GoogleMap
                defaultZoom={7}
                defaultCenter={{ lat: 41.8507300, lng: -87.6512600 }}
            >

                {props.directions && <DirectionsRenderer directions={props.directions} />}
            </GoogleMap>
            );

        return (
            <div>
              may have exceeded daily request limits
            <MyMap />
            </div>
        );
    }
}

export default Direction;

----------------------------------------------------

reference:

deploy react on surge

Install Surge:
npm install -g surge

Run the Create React App build:
cd your-react-project

npm run build
Switch into the build directory:
cd build

Run Surge, and follow the prompts. All it needs is an email and a password, and you can optionally specify a different domain name.
surge

enter ->change the domain name to projectName.surge.sh -> enter

Go to the URL it prints out. For instance, http://lively-payment.surge.sh/.

reference:
https://daveceddia.com/deploy-create-react-app-surge/
https://medium.freecodecamp.org/surge-vs-github-pages-deploying-a-create-react-app-project-c0ecbf317089
https://surge.sh/help/adding-a-custom-domain