GithubHelp home page GithubHelp logo

mkholodnyak / react-yandex-maps Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gribnoysup/react-yandex-maps

0.0 1.0 0.0 2.86 MB

Yandex Maps API bindings for React

Home Page: https://gribnoysup.github.io/react-yandex-maps/

License: MIT License

JavaScript 100.00%

react-yandex-maps's Introduction

react-yandex-maps

Yandex Maps API bindings for React

Install

npm install --save react-yandex-maps

Components

Basic components

  • <YMaps /> - provides child components with yandex maps api via context
  • <Map /> - Map instance
  • <Clusterer /> - Clusterer instance
  • <ObjectManager /> - ObjectManager instance
  • <GeoObject /> - generic GeoObject instance
  • <Control /> - generic Control instance

GeoObject shorthands

  • <Placemark />
  • <Polyline />
  • <Rectangle />
  • <Polygon />
  • <Circle />

Control shorthands

  • <Button />
  • <FullscreenControl />
  • <GeolocationControl />
  • <RouteEditor />
  • <RulerControl />
  • <SearchControl />
  • <TrafficControl />
  • <TypeSelector />
  • <ZoomControl />
  • <ListBox />
  • <ListBoxItem />

Basic Usage (compared to yandex maps quick start guide)

With Yandex Maps API

window.ymaps.ready(function () {
  const myMap = new window.ymaps.Map('map', {
    center: [55.751574, 37.573856],
    zoom: 9
  }, {
    searchControlProvider: 'yandex#search'
  })

  const myPlacemark = new window.ymaps.Placemark([55.751574, 37.573856], {
    hintContent: 'Собственный значок метки',
    balloonContent: 'Это красивая метка'
  }, {
    iconLayout: 'default#image',
    iconImageHref: 'images/myIcon.gif',
    iconImageSize: [30, 42],
    iconImageOffset: [-3, -42]
  })

  myMap.geoObjects.add(myPlacemark)
})

With react-yandex-maps

import { YMaps, Map, Placemark } from 'react-yandex-maps';

const mapState = { center: [55.76, 37.64], zoom: 10 };

const MyPlacemark = () => (
  <YMaps>
    <Map state={mapState}>

      <Placemark
        geometry={{
          coordinates: [55.751574, 37.573856]
        }}
        properties={{
          hintContent: 'Собственный значок метки',
          balloonContent: 'Это красивая метка'
        }}
        options={{
          iconLayout: 'default#image',
          iconImageHref: 'images/myIcon.gif',
          iconImageSize: [30, 42],
          iconImageOffset: [-3, -42]
        }}
      />

    </Map>
  </YMaps>
);

Enterprise

react-yandex-maps library also supports enterprise version of Yandex.Maps API:

  <YMaps
    enterprise
    query={{
      apikey: '// your api key here',
    }}
  />

Events

All Objects events are available, just use camelCase event names instead of default ones (for example geometrychange -> onGeometryChange):

With Yandex Maps API

function onGeometryChange() {/* more code */}

const circle = new window.ymaps.GeoObject({
  geometry: {
    type: "Circle",
    coordinates: [55.76, 37.64],
    radius: 10000
  }
})

circle.events.add('geometrychange', handleEventSomehow)

With react-yandex-maps

import { Circle } from 'react-yandex-maps'

const CircleWithEvents = ({onGeometryChange}) => (
  <Circle
    geometry={{
      coordinates: [55.76, 37.64],
      radius: 10000
    }}
    onGeometryChange={onGeometryChange}
  />
)

The instanceRef Callback Attribute

react-yandex-maps supports a special attribute, that [works similar] (https://facebook.github.io/react/docs/refs-and-the-dom.html) to React ref attribute. react-yandex-maps will call the instanceRef callback with the YandexMap Object instance when the component mounts, and call it with null when it unmounts.

More Examples

You can go to https://gribnoysup.github.io/react-yandex-maps/ to look at examples, or clone this repo, cd to repo folder and run npm start

git clone https://github.com/gribnoysup/react-yandex-maps.git
cd ./react-yandex-maps
npm install && npm run examples

TODO

  • Add tests
  • Add more propTypes
  • Add more examples

Acknowledgements

Thanks to @effrenus and his yandex-map-react for inspiration

react-yandex-maps's People

Contributors

deylak avatar frux avatar gribnoysup avatar koekaverna avatar nimmimarco avatar

Watchers

 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.