Raruto/leaflet-rotate

Can you offer any advice how to get this working with React-Leaflet?

laurencefass opened this issue · 2 comments

Ive installed the module via npm and im not sure how to use it with React-leaflet.

I have installed the module with yarn and I was kind of hoping that would do all the necessary modifications to the leaflet object automatically.

Ive created a sandbox which renders your demo code (HTML, Leaflet, no React) in the index.html file alongside a failed attempt at rendering a rotating map in React-Leaflet.

The problem is your properties and methods aren't exposed on the Leaflet object exposed by React-Leaflet. Im not sure if this is a React, Leaflet, React-leaflet problem or a problem trying to use ES6 imports so grateful for any insightes and advice.

Hi laurence,

I don't use react, so maybe there are smarter ways than the following: how-to-add-method-to-class-without-creating-new-class-that-extends-it, which is basically the same method I used to alter almost all the leaflet classes (although leaflet doesn't actually use classes):

const mapProto = L.extend({}, L.Map.prototype);

const canvasProto = L.extend({}, L.Canvas.prototype);

const gridLayerProto = L.extend({}, L.GridLayer.prototype);

I haven't checked the names, but to understand yours it might be something like that:

MapContainer.prototype.options.rotate = true

where MapContainer is the name of the class you want to alter.

Have a nice day,
Raruto

I close here due to inactivity, for those interested you can find related topic here in detail: PaulLeCam/react-leaflet#976