Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set react-leaflet map CRS atribute

In native Leaflet map, lib CRS attribute should be set as below

var mymap = L.map('mapid', {
    center: [-1800, 1000],
    zoom: 13,
    crs: L.CRS.Simple,
    minZoom: 0,
    maxZoom: 13,
});

How to do that in react-leaflet, I had tried some things but nothing successful :/

    <Map crs={CRS.useSimple()} center={[-1800, 1000]} zoom={13} doubleClickZoom={false} >

    </Map>

But there is an error that CRS is not imported. How to import CRS?

Where do I wrong?

like image 635
Stevan Tosic Avatar asked Dec 11 '22 08:12

Stevan Tosic


1 Answers

I need to import CRS from native leaflet.

import React, { Component } from 'react';
import {Map} from 'react-leaflet'
import {CRS} from 'leaflet';

and then in MAP component

 <Map center={[0, 0]} zoom={2}  doubleClickZoom={false} crs={CRS.Simple}>
    ...
 </Map
like image 163
Stevan Tosic Avatar answered Jan 21 '23 10:01

Stevan Tosic