3

I have a <Map> component with <Geojson> component with in it. I want to bind a popup in onEachFeature method.

I have successfully done layer.bindpopup(); but don't know how to bind it to the centre of the geoJson layer.

adding a <Popup ref="popup"> in <Map> and doing this.refs.popup.getLeafletElement() throws an error, so I am not being able to use popup.setLatlang()

1 Answer 1

1

Are you simply trying to have a popup show upon clicking a geojson feature? If so you can follow the basic example of react-leaflet.

import React from 'react';
import { render } from 'react-dom';
import { Map, Marker, Popup, TileLayer } from 'react-leaflet';

const position = [51.505, -0.09];
const map = (
  <Map center={position} zoom={13}>
    <TileLayer
      url='http://{s}.tile.osm.org/{z}/{x}/{y}.png'
      attribution='&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
    />
    <Marker position={position}>
      <Popup>
        <span>A pretty CSS3 popup.<br/>Easily customizable.</span>
      </Popup>
    </Marker>
  </Map>
);

render(map, document.getElementById('map-container'));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.