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

Feature request: add support for VectorGrid #313

Closed
stereobooster opened this issue Apr 16, 2017 · 5 comments
Closed

Feature request: add support for VectorGrid #313

stereobooster opened this issue Apr 16, 2017 · 5 comments

Comments

@stereobooster
Copy link

stereobooster commented Apr 16, 2017

Trying to get Leaflet.VectorGrid support. Not successful so far.

Maybe you can give me some advices and I will do PR.

Related: Leaflet/Leaflet.VectorGrid#37

@stereobooster
Copy link
Author

stereobooster commented Apr 16, 2017

Found solution

// @flow

import L from 'leaflet';
import {} from 'leaflet.vectorgrid/dist/Leaflet.VectorGrid.bundled.js'
import PropTypes from 'prop-types';
import { childrenType, GridLayer } from 'react-leaflet';

export default class VectorgridLayer extends GridLayer {
  static propTypes = {
    children: childrenType,
    opacity: PropTypes.number,
    url: PropTypes.string.isRequired,
    zIndex: PropTypes.number,
  };

  createLeafletElement(props: Object): Object {
    const { url, ...options } = props;

    return L.vectorGrid.protobuf(url, options);
  }

  updateLeafletElement(fromProps: Object, toProps: Object) {
    super.updateLeafletElement(fromProps, toProps);
    if (toProps.url !== fromProps.url) {
      this.leafletElement.vectorGrid.protobuf(toProps.url);
    }
  }
}

Example:

<Map>
  <VectorgridLayer
    url= "https://{s}.tiles.mapbox.com/v4/mapbox.mapbox-streets-v6/{z}/{x}/{y}.vector.pbf?access_token={token}"
    attribution='© <a href="https://www.mapbox.com/about/maps/" target="_blank">Mapbox</a> © <a href="http://www.openstreetmap.org/copyright" target="_blank">OpenStreetMap</a>'
  />
</Map>

@stereobooster
Copy link
Author

Also if anybody needs MapBoxGL integration:

// @flow

import L from 'leaflet'
import {} from 'mapbox-gl-leaflet'
import PropTypes from 'prop-types'
import { childrenType, GridLayer } from 'react-leaflet'

export default class MapBoxGLLayer extends GridLayer {
  static propTypes = {
    children: childrenType,
    opacity: PropTypes.number,
    accessToken: PropTypes.string.isRequired,
    style: PropTypes.string,
    zIndex: PropTypes.number,
  }

  createLeafletElement(props: Object): Object {
    return L.mapboxGL(props)
  }
}

depends on:

<script src='https://api.mapbox.com/mapbox-gl-js/v0.35.1/mapbox-gl.js'></script>
<link href='https://api.mapbox.com/mapbox-gl-js/v0.35.1/mapbox-gl.css' rel='stylesheet' />
yarn add mapbox-gl-leaflet

Compared Leaflet.VectorGrid, OpenLayers and MapBoxGL. Only MapBoxGL feels fast.

@bardiaombre
Copy link

@stereobooster on your mapbox-gl, i cannot access childrenType as of react-leaflet 1.1. any solution to how to fix it.

screen shot 2018-11-14 at 1 35 05 pm

@JensC
Copy link

JensC commented Apr 25, 2019

@bardiaombre yes, I have the same problem. I can not update to react-leaflet v2 since it depends on React 16.x. Any solution would be great.

@Naseer-Ahmad
Copy link

Getting error in V3.1.0 "Attempted import error: 'GridLayer' is not exported from 'react-leaflet'."

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

4 participants