Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing support for Non-Geographical Maps #311

Closed
awjreynolds opened this issue Apr 10, 2017 · 7 comments
Closed

Missing support for Non-Geographical Maps #311

awjreynolds opened this issue Apr 10, 2017 · 7 comments

Comments

@awjreynolds
Copy link

Leaflet supports non-geographical maps

	var map = L.map('map', {
		crs: L.CRS.Simple
	});

	var bounds = [[0,0], [1000,1000]];
	var image = L.imageOverlay('uqm_map_full.png', bounds).addTo(map);

	map.fitBounds(bounds);

http://leafletjs.com/examples/crs-simple/crs-simple.html

I've been able to get this working in react-leaflet but had to import Leaflet to get at the L.CRS.Simple to handle map manipulation.

import React, { Component } from 'react';
import {
  ImageOverlay,
  Map
} from 'react-leaflet';
var Leaflet = require('leaflet');

export default class InterfaceDevicesMap extends Component {
  render () {
    const bounds = [[0, 0], [1000, 1000]];
    return (
      <div>
        <Map crs={ Leaflet.CRS.Simple } bounds={ bounds }>
          <ImageOverlay url='http://leafletjs.com/examples/crs-simple/uqm_map_full.png' bounds={ bounds } />
        </Map>
      </div>
    );
  }
}

Not sure if this is just a case of a missing example and this is the way it is supposed to work.

@PaulLeCam
Copy link
Owner

Sorry I don't get what is your issue?
If it is having to import Leaflet, it is the expected behavior, this library is a wrapper around Leaflet, not a replacement for it.

@awjreynolds
Copy link
Author

The Map component properties does not include csr. Happy to put together a pull request once I've got this working in my project.

export default class Map extends MapComponent {
  static propTypes = {
    animate: PropTypes.bool,
    bounds: boundsType,
    boundsOptions: PropTypes.object,
    center: latlngType,
    children: childrenType,
    className: PropTypes.string,
    id: PropTypes.string,
    maxBounds: boundsType,
    maxZoom: PropTypes.number,
    minZoom: PropTypes.number,
    style: PropTypes.object,
    useFlyTo: PropTypes.bool,
    zoom: PropTypes.number,
  }```

@PaulLeCam
Copy link
Owner

These are the props handled by React-Leaflet itself, as there can be additional logic related to them, but any other prop is passed to the Leaflet.map() factory, as you can see here.

@awjreynolds
Copy link
Author

In that case that makes a lot of sense. Thank you for your feedback. I'll close this.

@dragGH102
Copy link

@awjreynolds how did you got that working?

If I try:

import { Map } from 'react-leaflet';
import L from 'leaflet';

<Map 
   ... other props (zoom, center) // works without crs
   crs = {L.CRS.Earth}
/>

the map is shown as gray and I get a lot of errors in console:

Uncaught TypeError: Cannot read property 'x' of undefined
    at Point._add (reactBoilerplateDeps.dll.js:88974)
    at Point.add (reactBoilerplateDeps.dll.js:88969)
    at NewClass.layerPointToLatLng (reactBoilerplateDeps.dll.js:92083)
    at NewClass._fireDOMEvent (reactBoilerplateDeps.dll.js:92503)
    at NewClass._handleDOMEvent (reactBoilerplateDeps.dll.js:92464)
    at HTMLDivElement.handler (reactBoilerplateDeps.dll.js:90467)

@LukyVj
Copy link

LukyVj commented Feb 26, 2020

#311 (comment)

I used the latest example, and it worked like a charm:

import React, { Component } from 'react';
import {
  ImageOverlay,
  Map
} from 'react-leaflet';
var Leaflet = require('leaflet');

export default class InterfaceDevicesMap extends Component {
  render () {
    const bounds = [[0, 0], [1000, 1000]];
    return (
      <div>
        <Map crs={ Leaflet.CRS.Simple } bounds={ bounds }>
          <ImageOverlay url='http://leafletjs.com/examples/crs-simple/uqm_map_full.png' bounds={ bounds } />
        </Map>
      </div>
    );
  }
}

Thanks !

@fahshed
Copy link

fahshed commented Apr 10, 2020

@dragGH102 I am having a very similar problem as you mentioned. Did you mange to resolve the issue? If you did, please kindly help me a bit here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants