gribnoysup / react-yandex-maps

Yandex Maps API bindings for React
MIT License
327 stars 114 forks source link

RulerControl #326

Closed YummyTi closed 2 years ago

YummyTi commented 2 years ago

How can I get RulerControl selected locations latatiude and longitude after selections?

mmarkelov commented 2 years ago

@YummyTi hey. Sorry, I just don't know if the Ruler or map can handle this action. If you have working example with yandex maps api, could you send it? I tried something like this, but it's not quite right:

import React, { useRef } from "react";
import ReactDOM from "react-dom";
import { YMaps, Map, RulerControl } from "react-yandex-maps";

import "./styles.css";

function App() {
  const map = useRef(null);

  return (
    <div className="App">
      <YMaps>
        <Map
          onMouseUp={(e) =>
            console.log(
              map.current.behaviors.get("ruler").geometry.getCoordinates()
            )
          }
          defaultState={{
            center: [55.751574, 37.573856],
            zoom: 9
          }}
          instanceRef={map}
        >
          <RulerControl options={{ float: "right" }} />
        </Map>
      </YMaps>
    </div>
  );
}

const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);