GithubHelp home page GithubHelp logo

danielarturoalejoalvarez / react-map-leaflet-geolocation Goto Github PK

View Code? Open in Web Editor NEW
15.0 5.0 3.0 3.66 MB

Software of Application with React, NodeJS and Leaflet.

HTML 28.22% CSS 9.36% JavaScript 62.42%
nodejs react leaflet react-leaflet

react-map-leaflet-geolocation's Introduction

REACT-MAP-LEAFLET (GEO-Location)

Description

This repository is a Software of Application with React,NodeJS,Leaflet,etc

Installation

Using NodeJS, React preferably.

Plugins

React Leaflet

Usage

$ git clone https://github.com/DanielArturoAlejoAlvarez/react-map-leaflet-geolocation[NAME APP]

$ npm install

$ yarn install

Follow the following steps and you're good to go! Important:

alt text

Coding

Components

...
export const IconLocation = L.icon({
  iconUrl: require('../assets/img/icon.svg'),
  iconRetinaUrl: require('../assets/img/icon.svg'),
  iconAnchor: null,
  shadowUrl: null,
  shadowSize: null,
  shadowAnchor: null,
  iconSize: [35,35],
  className: 'leaflet-venue-icon'
});

const MarkerPopup = (props)=>{
  const { name } = props.data 
  
  return (
    <Popup>
      <div>{name}</div>
    </Popup>
  )

}

const Markers = (props) => {


  const { places } = props

  const markers = places.map((place,index)=>(
    <Marker 
      key={index}
      position={place.geometry} 
      icon={IconLocation}
    >
      <MarkerPopup data={place}/>
    </Marker>
  ))


  return (
    <div>
      {markers}
    </div>
  )
}

const MapView = (props) => {   

  const [state,setState] = useState({
    currentLocation: {
      lat: 52.500772,
      lng: 13.472764
    },
    zoom: 13,
    data
  })

  const location = useLocation()
  const history = useHistory()

  useEffect(() => {
    if (location.state.latitude && location.state.longitude) {
      const currentLocation = {
        lat: location.state.latitude,
        lng: location.state.longitude
      }
      setState({
        ...state,
        currentLocation
      })

      history.replace({
        pathname: '/map-view',
        state: {}
      })
    }
    
  }, [location])

  return (
    <div>
      <Map center={state.currentLocation} zoom={state.zoom}>
        <TileLayer
          url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
          attribution="&copy; <a href=&quot;http://osm.org/copyright&quot;>OpenStreetMap</a> contributors"
        />
        <Markers places={state.data.places}/>
      </Map>
    </div>
  )
}

function App() {
  return (
   
    <Router>
      <Switch>
      <Route path="/map-view">
          <MapView />;
        </Route>
        <Route path="/">
          <Home />
        </Route>
      </Switch>
    </Router>
    
  );
}
...

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/DanielArturoAlejoAlvarez/react-map-leaflet-geolocation. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.


react-map-leaflet-geolocation's People

Contributors

danielarturoalejoalvarez avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.