Mark Mara

Mark Mara

1598479200

React wrapper for mapbox-gl-geocoder for use with react-map-gl

react-map-gl-geocoder

React wrapper for mapbox-gl-geocoder for use with react-map-gl.

Installation

npm

$ npm install react-map-gl-geocoder

or

Yarn

$ yarn add react-map-gl-geocoder

Styling

Import:

import 'react-map-gl-geocoder/dist/mapbox-gl-geocoder.css'

or

Link tag in header:

<link href='https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-geocoder/v4.2.0/mapbox-gl-geocoder.css' rel='stylesheet' />

Props

Only mapRef and mapboxApiAccessToken are required.

Name Type Default Description
mapRef Object Ref for react-map-gl map component.
containerRef Object This can be used to place the geocoder outside of the map. The position prop is ignored if this is passed in. Example: https://codesandbox.io/s/v0m14q5rly
onViewportChange Function () => {} Is passed updated viewport values after executing a query.
mapboxApiAccessToken String https://www.mapbox.com/
inputValue String Sets the search input value
origin String https://api.mapbox.com Use to set a custom API origin.
zoom Number 16 On geocoded result what zoom level should the map animate to when a bbox isn’t found in the response. If a bbox is found the map will fit to the bbox.
placeholder String “Search” Override the default placeholder attribute value.
proximity Object A proximity argument: this is a geographical point given as an object with latitude and longitude properties. Search results closer to this point will be given higher priority.
trackProximity Boolean false If true, the geocoder proximity will automatically update based on the map view.
collapsed Boolean false If true, the geocoder control will collapse until hovered or in focus.
clearAndBlurOnEsc Boolean false If true, the geocoder control will clear it’s contents and blur when user presses the escape key.
clearOnBlur Boolean false If true, the geocoder control will clear its value when the input blurs.
bbox Array A bounding box argument: this is a bounding box given as an array in the format [minX, minY, maxX, maxY]. Search results will be limited to the bounding box.
types String A comma seperated list of types that filter results to match those specified. See https://www.mapbox.com/developers/api/geocoding/#filter-type for available types.
countries String A comma separated list of country codes to limit results to specified country or countries.
minLength Number 2 Minimum number of characters to enter before results are shown.
limit Number 5 Maximum number of results to show.
language String Specify the language to use for response text and query result weighting. Options are IETF language tags comprised of a mandatory ISO 639-1 language code and optionally one or more IETF subtags for country or script. More than one value can also be specified, separated by commas.
filter Function A function which accepts a Feature in the Carmen GeoJSON format to filter out results from the Geocoding API response before they are included in the suggestions list. Return true to keep the item, false otherwise.
localGeocoder Function A function accepting the query string which performs local geocoding to supplement results from the Mapbox Geocoding API. Expected to return an Array of GeoJSON Features in the Carmen GeoJSON format.
reverseGeocode Boolean false Enable reverse geocoding. Defaults to false. Expects coordinates to be lat, lon.
enableEventLogging Boolean true Allow Mapbox to collect anonymous usage statistics from the plugin.
render Function A function that specifies how the results should be rendered in the dropdown menu. Accepts a single Carmen GeoJSON object as input and return a string. Any html in the returned string will be rendered. Uses mapbox-gl-geocoder’s default rendering if no function provided.
position String “top-right” Position on the map to which the geocoder control will be added. Valid values are "top-left", "top-right", "bottom-left", and "bottom-right".
onInit Function () => {} Is passed Mapbox geocoder instance as param and is executed after Mapbox geocoder is initialized.
onClear Function () => {} Executed when the input is cleared.
onLoading Function () => {} Is passed { query } as a param and is executed when the geocoder is looking up a query.
onResults Function () => {} Is passed { results } as a param and is executed when the geocoder returns a response.
onResult Function () => {} Is passed { result } as a param and is executed when the geocoder input is set.
onError Function () => {} Is passed { error } as a param and is executed when an error occurs with the geocoder.

Example

import 'mapbox-gl/dist/mapbox-gl.css'
import 'react-map-gl-geocoder/dist/mapbox-gl-geocoder.css'
import React, { useState, useRef, useCallback } from 'react'
import MapGL from 'react-map-gl'
import Geocoder from 'react-map-gl-geocoder'

// Ways to set Mapbox token: https://uber.github.io/react-map-gl/#/Documentation/getting-started/about-mapbox-tokens
const MAPBOX_TOKEN = 'REPLACE_WITH_YOUR_MAPBOX_TOKEN'

const Example = () => {
  const [viewport, setViewport] = useState({
    latitude: 37.7577,
    longitude: -122.4376,
    zoom: 8
  });
  const mapRef = useRef();
  const handleViewportChange = useCallback(
    (newViewport) => setViewport(newViewport),
    []
  );

  // if you are happy with Geocoder default settings, you can just use handleViewportChange directly
  const handleGeocoderViewportChange = useCallback(
    (newViewport) => {
      const geocoderDefaultOverrides = { transitionDuration: 1000 };

      return handleViewportChange({
        ...newViewport,
        ...geocoderDefaultOverrides
      });
    },
    [handleViewportChange]
  );

  return (
    <div style={{ height: "100vh" }}>
      <MapGL
        ref={mapRef}
        {...viewport}
        width="100%"
        height="100%"
        onViewportChange={handleViewportChange}
        mapboxApiAccessToken={MAPBOX_TOKEN}
      >
        <Geocoder
          mapRef={mapRef}
          onViewportChange={handleGeocoderViewportChange}
          mapboxApiAccessToken={MAPBOX_TOKEN}
          position="top-left"
        />
      </MapGL>
    </div>
  );
};

export default Example

react-map-gl-geocoder example screenshot

Download Details:

Author: SamSamskies

Demo: https://codesandbox.io/s/l7p179qr6m

Source Code: https://github.com/SamSamskies/react-map-gl-geocoder

#react #reactjs #javascript

What is GEEK

Buddha Community

React wrapper for mapbox-gl-geocoder for use with react-map-gl
Autumn  Blick

Autumn Blick

1598839687

How native is React Native? | React Native vs Native App Development

If you are undertaking a mobile app development for your start-up or enterprise, you are likely wondering whether to use React Native. As a popular development framework, React Native helps you to develop near-native mobile apps. However, you are probably also wondering how close you can get to a native app by using React Native. How native is React Native?

In the article, we discuss the similarities between native mobile development and development using React Native. We also touch upon where they differ and how to bridge the gaps. Read on.

A brief introduction to React Native

Let’s briefly set the context first. We will briefly touch upon what React Native is and how it differs from earlier hybrid frameworks.

React Native is a popular JavaScript framework that Facebook has created. You can use this open-source framework to code natively rendering Android and iOS mobile apps. You can use it to develop web apps too.

Facebook has developed React Native based on React, its JavaScript library. The first release of React Native came in March 2015. At the time of writing this article, the latest stable release of React Native is 0.62.0, and it was released in March 2020.

Although relatively new, React Native has acquired a high degree of popularity. The “Stack Overflow Developer Survey 2019” report identifies it as the 8th most loved framework. Facebook, Walmart, and Bloomberg are some of the top companies that use React Native.

The popularity of React Native comes from its advantages. Some of its advantages are as follows:

  • Performance: It delivers optimal performance.
  • Cross-platform development: You can develop both Android and iOS apps with it. The reuse of code expedites development and reduces costs.
  • UI design: React Native enables you to design simple and responsive UI for your mobile app.
  • 3rd party plugins: This framework supports 3rd party plugins.
  • Developer community: A vibrant community of developers support React Native.

Why React Native is fundamentally different from earlier hybrid frameworks

Are you wondering whether React Native is just another of those hybrid frameworks like Ionic or Cordova? It’s not! React Native is fundamentally different from these earlier hybrid frameworks.

React Native is very close to native. Consider the following aspects as described on the React Native website:

  • Access to many native platforms features: The primitives of React Native render to native platform UI. This means that your React Native app will use many native platform APIs as native apps would do.
  • Near-native user experience: React Native provides several native components, and these are platform agnostic.
  • The ease of accessing native APIs: React Native uses a declarative UI paradigm. This enables React Native to interact easily with native platform APIs since React Native wraps existing native code.

Due to these factors, React Native offers many more advantages compared to those earlier hybrid frameworks. We now review them.

#android app #frontend #ios app #mobile app development #benefits of react native #is react native good for mobile app development #native vs #pros and cons of react native #react mobile development #react native development #react native experience #react native framework #react native ios vs android #react native pros and cons #react native vs android #react native vs native #react native vs native performance #react vs native #why react native #why use react native

Trinity  Kub

Trinity Kub

1594739112

How to display a Mapbox Map and Geocoder — Mapbox/React Tutorial Part 1

This multi-part React tutorial will be covering how to use Mapbox to:

  • display a map
  • search an address
  • add markers
  • display a popup when clicking on a marker

and even removing a marker.

We will be using create-react-app for our base React app and using the react-map-gl and react-mapbox-gl-geocoder libraries for our map and geocoder respectively. As an option, I will be using reactstrap for styling (in case you are unfamiliar, reactstrap is Bootstrap for React).


1. Create project and install dependencies

First, we will start by setting up our project.

npx create-react-app mapbox-project
cd mapbox-project
npm i react-map-gl react-mapbox-gl-geocoder bootstrap reactstrap
npm start

2. Mapbox key

In order to use Mapbox, you will need an API key. Go to https://www.mapbox.com/ and click on Sign In.

Under the signin form, click on Sign Up for Mapbox. Once you are done signing up, you should be taken to your dashboard. If you weren’t automatically given a token, you can create one by clicking Create a token.

Image for post

#react #programming #tutorial #mapping #mapbox

What are hooks in React JS? - INFO AT ONE

In this article, you will learn what are hooks in React JS? and when to use react hooks? React JS is developed by Facebook in the year 2013. There are many students and the new developers who have confusion between react and hooks in react. Well, it is not different, react is a programming language and hooks is a function which is used in react programming language.
Read More:- https://infoatone.com/what-are-hooks-in-react-js/

#react #hooks in react #react hooks example #react js projects for beginners #what are hooks in react js? #when to use react hooks

Mark Mara

Mark Mara

1598479200

React wrapper for mapbox-gl-geocoder for use with react-map-gl

react-map-gl-geocoder

React wrapper for mapbox-gl-geocoder for use with react-map-gl.

Installation

npm

$ npm install react-map-gl-geocoder

or

Yarn

$ yarn add react-map-gl-geocoder

Styling

Import:

import 'react-map-gl-geocoder/dist/mapbox-gl-geocoder.css'

or

Link tag in header:

<link href='https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-geocoder/v4.2.0/mapbox-gl-geocoder.css' rel='stylesheet' />

Props

Only mapRef and mapboxApiAccessToken are required.

Name Type Default Description
mapRef Object Ref for react-map-gl map component.
containerRef Object This can be used to place the geocoder outside of the map. The position prop is ignored if this is passed in. Example: https://codesandbox.io/s/v0m14q5rly
onViewportChange Function () => {} Is passed updated viewport values after executing a query.
mapboxApiAccessToken String https://www.mapbox.com/
inputValue String Sets the search input value
origin String https://api.mapbox.com Use to set a custom API origin.
zoom Number 16 On geocoded result what zoom level should the map animate to when a bbox isn’t found in the response. If a bbox is found the map will fit to the bbox.
placeholder String “Search” Override the default placeholder attribute value.
proximity Object A proximity argument: this is a geographical point given as an object with latitude and longitude properties. Search results closer to this point will be given higher priority.
trackProximity Boolean false If true, the geocoder proximity will automatically update based on the map view.
collapsed Boolean false If true, the geocoder control will collapse until hovered or in focus.
clearAndBlurOnEsc Boolean false If true, the geocoder control will clear it’s contents and blur when user presses the escape key.
clearOnBlur Boolean false If true, the geocoder control will clear its value when the input blurs.
bbox Array A bounding box argument: this is a bounding box given as an array in the format [minX, minY, maxX, maxY]. Search results will be limited to the bounding box.
types String A comma seperated list of types that filter results to match those specified. See https://www.mapbox.com/developers/api/geocoding/#filter-type for available types.
countries String A comma separated list of country codes to limit results to specified country or countries.
minLength Number 2 Minimum number of characters to enter before results are shown.
limit Number 5 Maximum number of results to show.
language String Specify the language to use for response text and query result weighting. Options are IETF language tags comprised of a mandatory ISO 639-1 language code and optionally one or more IETF subtags for country or script. More than one value can also be specified, separated by commas.
filter Function A function which accepts a Feature in the Carmen GeoJSON format to filter out results from the Geocoding API response before they are included in the suggestions list. Return true to keep the item, false otherwise.
localGeocoder Function A function accepting the query string which performs local geocoding to supplement results from the Mapbox Geocoding API. Expected to return an Array of GeoJSON Features in the Carmen GeoJSON format.
reverseGeocode Boolean false Enable reverse geocoding. Defaults to false. Expects coordinates to be lat, lon.
enableEventLogging Boolean true Allow Mapbox to collect anonymous usage statistics from the plugin.
render Function A function that specifies how the results should be rendered in the dropdown menu. Accepts a single Carmen GeoJSON object as input and return a string. Any html in the returned string will be rendered. Uses mapbox-gl-geocoder’s default rendering if no function provided.
position String “top-right” Position on the map to which the geocoder control will be added. Valid values are "top-left", "top-right", "bottom-left", and "bottom-right".
onInit Function () => {} Is passed Mapbox geocoder instance as param and is executed after Mapbox geocoder is initialized.
onClear Function () => {} Executed when the input is cleared.
onLoading Function () => {} Is passed { query } as a param and is executed when the geocoder is looking up a query.
onResults Function () => {} Is passed { results } as a param and is executed when the geocoder returns a response.
onResult Function () => {} Is passed { result } as a param and is executed when the geocoder input is set.
onError Function () => {} Is passed { error } as a param and is executed when an error occurs with the geocoder.

Example

import 'mapbox-gl/dist/mapbox-gl.css'
import 'react-map-gl-geocoder/dist/mapbox-gl-geocoder.css'
import React, { useState, useRef, useCallback } from 'react'
import MapGL from 'react-map-gl'
import Geocoder from 'react-map-gl-geocoder'

// Ways to set Mapbox token: https://uber.github.io/react-map-gl/#/Documentation/getting-started/about-mapbox-tokens
const MAPBOX_TOKEN = 'REPLACE_WITH_YOUR_MAPBOX_TOKEN'

const Example = () => {
  const [viewport, setViewport] = useState({
    latitude: 37.7577,
    longitude: -122.4376,
    zoom: 8
  });
  const mapRef = useRef();
  const handleViewportChange = useCallback(
    (newViewport) => setViewport(newViewport),
    []
  );

  // if you are happy with Geocoder default settings, you can just use handleViewportChange directly
  const handleGeocoderViewportChange = useCallback(
    (newViewport) => {
      const geocoderDefaultOverrides = { transitionDuration: 1000 };

      return handleViewportChange({
        ...newViewport,
        ...geocoderDefaultOverrides
      });
    },
    [handleViewportChange]
  );

  return (
    <div style={{ height: "100vh" }}>
      <MapGL
        ref={mapRef}
        {...viewport}
        width="100%"
        height="100%"
        onViewportChange={handleViewportChange}
        mapboxApiAccessToken={MAPBOX_TOKEN}
      >
        <Geocoder
          mapRef={mapRef}
          onViewportChange={handleGeocoderViewportChange}
          mapboxApiAccessToken={MAPBOX_TOKEN}
          position="top-left"
        />
      </MapGL>
    </div>
  );
};

export default Example

react-map-gl-geocoder example screenshot

Download Details:

Author: SamSamskies

Demo: https://codesandbox.io/s/l7p179qr6m

Source Code: https://github.com/SamSamskies/react-map-gl-geocoder

#react #reactjs #javascript

Josef Baukes

1619149471

How to Create React Node Travel Map App using Mapbox and Google Maps

React.js - Node.js Full-stack map pinning travel app using React hooks, Mapbox, Express, and MongoDB. How to create an app using Google Maps?
In this application, you can pin your location and share your reviews with other users.

Source code: https://github.com/safak/youtube/tree/mern-travel-app

  • 0:00 Introduction
  • 1:19 Creating Node.js Express App
  • 06:27 Connecting MongoDB with Mongoose
  • 10:20 Creating Node.js Rest API
  • 25:28 Node.js Login and Register System
  • 37:15 Creating a React App
  • 40:14 Using React Mapbox
  • 45:36 Creating Mapbox Marker
  • 51:24 Creating Mapbox Popup
  • 58:02 React Fetching data from Node.js using Axios
  • 01:08:27 React Mapbox adding new Location
  • 01:19:05 React Post request using Axios
  • 01:28:05 React Login and Register Page
  • 01:37:28 Mern Stack Login and Register System
  • 01:50:13 Using React Local Storage
  • 01:53:30 React Logout System using Local Storage
  • 01:57:27 Outro

#react #node #mapbox #google-maps #express