1

I'm trying to add custom button for zoom to leaflet map in reactjs this is my code

import React, {Component} from 'react';
import { Map, TileLayer, Marker, Popup, ZoomControl } from 'react-leaflet';
import Control from 'react-leaflet-control';
import Button from '@material-ui/core/Button';

class LeafletMapComponent extends Component {
    constructor(props) {
        super(props);
        this.state = {
            lat: 51.505,
            lng: -0.09,
            zoom: 13
        }
    }

    render() {
        const position = [this.state.lat, this.state.lng];
        return (
            <Map ref={m => { this.leafletMap = m; }} zoomControl={false} center={position} zoom={this.state.zoom}>
                <TileLayer
                    attribution='&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
                    url='http://{s}.tile.osm.org/{z}/{x}/{y}.png'
                />

                <Control position="topleft" >

                </Control>  

            </Map>
        );
    }
}

I'm using react-leaflet-control to create the custom control but it's giving me an error 'Error: createLeafletElement() must be implemented'

1
  • I guess you need to have some child element to Control Commented Jun 12, 2018 at 7:23

1 Answer 1

1

Since the update of Leaflet to v 1.1 a component must contain a createLeafletElement function otherwise MapLayer.js will throw an error.

// eslint-disable-next-line no-unused-vars

MapLayer.prototype.createLeafletElement = function createLeafletElement(props) { throw new Error('createLeafletElement() must be implemented'); };

Implement a createLeafletElement function in the ClusterLayer.js to fix this error.

ClusterLayer.prototype.createLeafletElement = function createLeafletElement() {};

Sign up to request clarification or add additional context in comments.

1 Comment

where can i find the ClusterLayer.js

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.