GithubHelp home page GithubHelp logo

mhasbie / react-leaflet-vectorgrid Goto Github PK

View Code? Open in Web Editor NEW
19.0 19.0 10.0 570 KB

React wrapper of Leaflet.VectorGrid. Display gridded vector data (sliced GeoJSON or protobuf vector tiles) in Leaflet.

License: MIT License

JavaScript 71.64% HTML 28.36%

react-leaflet-vectorgrid's People

Contributors

afrith avatar gendronb avatar mhasbie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

react-leaflet-vectorgrid's Issues

Having trouble using the component in typescript

Im developing integration in our app using storybook. Im doing this in order to test usage and performance.

but I get this error in storybook

Failed to execute 'postMessage' on 'Worker': Symbol(react.element) could not be cloned.

I think we need the v2 syntax since we use the later versions of the react leaflet. I believe we've got the deps correct

package.json versions

"lodash": "4.17.11",
"react": "16.8.3",
"react-leaflet": "2.2.0",
"react-leaflet-vectorgrid": "2.2.1",

i've created a simple definition file for the library
definition file

src\types\react-leaflet-vectorgrid.d.ts

declare module 'react-leaflet-vectorgrid' {
  import VectorGrid = require('react-leaflet-vectorgrid');
  export = VectorGrid;
}

I just created a simple interface and component wrapper from the docs

import { withLeaflet } from 'react-leaflet';
import VectorGridDefault from 'react-leaflet-vectorgrid';

const VectorGridComponent: any = withLeaflet(VectorGridDefault);

export interface VectorGridProps {
  data: Object;
  type?: 'slicer' | 'protobuf';
  idField?: string;
  tooltip?: string;
  popup?: Function;
  style?: Object;
  hoverStyle?: Object;
  activeStyle?: Object;
  zIndex?: number;
  interactive?: boolean;
  onClick?: Function;
  onMouseover?: Function;
  onMouseout?: Function;
  onDblclick?: Function;
}

class VectorGrid extends React.Component<VectorGridProps, {}> {
  render() {
    return <VectorGridComponent {...this.props} />;
  }
}

export default VectorGrid;

but i get the error at the top of the post. I've inspected the value of VectorGridComponent , and it seems to be off. Am I missing something or not using the correct syntax perhaps? any advice would be immensely helpful

thanks

I've tried the v1 syntax of just importing and using as a component, but I get:
Cannot read property 'map' of undefined

TypeError: Cannot read property 'map' of undefined

screen shot 2018-12-04 at 1 08 56 pm

I'm importing a geojson file into react app. Here's my dependencies-

"dependencies": { "axios": "^0.18.0", "leaflet": "^1.3.4", "lodash": "^4.17.11", "react": "^16.6.3", "react-dom": "^16.6.3", "react-leaflet": "^2.1.2", "react-leaflet-vectorgrid": "^2.1.3", "react-redux": "^5.1.1", "react-scripts": "2.1.1", "redux": "^4.0.1", "redux-thunk": "^2.3.0" },
Is it because something wrong with the data? When I tried with a small snippet of the data on jsfiddle example it works.

Vector Tile Layer redraw on click event

Hello there!

After several attempts, I was able to display the desired data (in .pbf), but every time I click on a polygon to see its associated data, the tile layer reloads or redraws (disappears and reappears later).

Also, getting data takes some time. My .pbf set weighs something like 11mb.

Here is my code

import React, { useContext } from 'react';
import { Map, TileLayer, LayersControl, LayerGroup, WMSTileLayer, withLeaflet} from 'react-leaflet';
import { BingLayer } from 'react-leaflet-bing-v2';
import L, { CRS } from 'leaflet';
import { FeatureContext } from './FeatureContext';
import VectorGridDefault from "react-leaflet-vectorgrid";


export default function MapComponent({ data }) {
    const [feature, setFeature] = useContext(FeatureContext);

    function getFeatureData(featureData) {
        setFeature(featureData);
        console.log(feature)
    }

    const vectorStyles = {
        ING_FINAL: {
          fill: true,
          weight: 1,
          fillColor: "#ff00ff",
          color: "#ff00ff",
          fillOpacity: 0.9,
          opacity: 0.9,
          maxNativeZoom: 14,
          minNativeZoom: 1
        }
      };
      const VectorGrid = withLeaflet(VectorGridDefault);
      const options = {
        tolerance: 30, 
        extent: 4096, 
        buffer: 128, 
        rendererFactory: L.svg.tile ,
        type: "protobuf",
        url: "http://{server_ip}/ING_VT/{z}/{x}/{y}.pbf",
        vectorTileLayerStyles: vectorStyles,
        subdomains: "abcd",
        key: "abcdefghi01234567890",
        interactive: true,
        zIndex: 401
      };

    return (
        <Map center={[-34.238347, -70.250921]} zoom={8} minZoom={6} maxZoom={12} maxBounds={[[-35.494268, -70.735148], [-32.963408, -69.766694]]} crs={CRS.EPSG3857} >
            {/* Control de Capas */}
            <LayersControl position="topright">
                {/* GRUPO DE CAPAS WORLD IMAGERY+ SHADERELIEF */}
                <LayersControl.BaseLayer checked name="HillShade" >
                    <LayerGroup>
                        {/* ESRI WORLD IMAGERY */}
                        <TileLayer
                            attribution='Tiles &copy; Esri &mdash; Source: Esri, i-cubed, USDA, USGS, AEX, GeoEye, Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the GIS User Community'
                            url="https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}"
                        />
                        {/* OPEN MAP SURFER HILLSHADE */}
                        <TileLayer
                            attribution='Imagery from <a href="http://giscience.uni-hd.de/">GIScience Research Group @ University of Heidelberg</a> | Map data  <a href="https://lpdaac.usgs.gov/products/aster_policies">ASTER GDEM</a>, <a href="http://srtm.csi.cgiar.org/">SRTM</a>'
                            url="https://maps.heigit.org/openmapsurfer/tiles/asterh/webmercator/{z}/{x}/{y}.png"
                        />
                    </LayerGroup>
                </LayersControl.BaseLayer>

                {/* ESRI Shaded Relief */}
                <LayersControl.BaseLayer name="ESRI Shaded Relief">
                    <TileLayer
                        attribution='Tiles &copy; Esri &mdash; Source: Esri'
                        url="https://server.arcgisonline.com/ArcGIS/rest/services/World_Shaded_Relief/MapServer/tile/{z}/{y}/{x}" 
                    />
                </LayersControl.BaseLayer>

                {/* BING Maps Satellital */}
                <LayersControl.BaseLayer name="BING Maps Satellital">
                    <BingLayer bingkey={bing_key} />
                </LayersControl.BaseLayer>

                <VectorGrid {...options}  onClick={ (e) => (getFeatureData(e.layer.properties))  } />
                
            </LayersControl>
        </Map>
    )
}

TypeError: Cannot read property 'protobuf' of undefined

Hello,

I'm trying to use react-leaflet-vectorgrid to render .mvt tiles from a remote server but I get the error below:

image

My code is:

import React, { Component } from "react";
import { 
  Path, 
  withLeaflet,                 
  GeoJSON,                     
  LayerGroup,                  
  LayersControl                
} from 'react-leaflet';        
  
import ReactDOM from "react-dom";
import L from "leaflet";
import VectorGridDefault from 'react-leaflet-vectorgrid';
            
import aladag from "./data/adana/aladag.json";
import ceyhan from "./data/adana/ceyhan.json";
const VectorGrid = withLeaflet(VectorGridDefault); 


class AdanaOverlays extends Component {
 
  constructor(){
    super(); 
  }

  render (){
    return (
      <LayersControl>
        <Overlay name="Aladag">
          <VectorGrid type="protobuf" url="http://localhost:8123/aladag/{z}/{x}/{y}.mvt" />
        </Overlay>

        <Overlay name="Ceyhan">
          <VectorGrid type="protobuf" url="http://localhost:8123/ceyhan/{z}/{x}/{y}.mvt" />
        </Overlay>
      </LayersControl>
    )
  }

export default AdanaOverlays;

I don't know if this is my mistake or something went wrong in installation. I deleted node_modules, cleared cache and installed everything from scratch, yet same thing happens.

How do I proceed to solve this?

Can't use VectorGrid inside LayersControl in v2?

Hello, thanks for this great project.

I'm getting Cannot read property 'undefined' of undefined when I try to include my vectorgrid inside of <LayersControl.Overlay>..., works fine outside of LayersControl

{
    "@material-ui/styles": "4.9.6",
    "leaflet": "1.6.0",
    "react": "16.13.1",
    "react-dom": "16.12.0",
    "react-leaflet": "2.6.3",
    "react-leaflet-vectorgrid": "2.2.1",
    "react-scripts": "3.0.1"
  }

Here is a sandbox demonstration:

https://codesandbox.io/s/react-leaflet-vectorgrid-in-layerscontrol-broken-vuips

Cannot render tiles with React16, Leafletjs 1.3.3 and React-Leaflet 2.0

Hi,
I cannot get this to render the vector tiles under React16, Leafletjs 1.3.3 and React-Leaflet 2.0 as context is not passed to the child object (it is just undefined).

Line 117

var _context = this.context,
map = _context.map,
pane = _context.pane,
layerContainer = _context.layerContainer;

I am working on a solution but any assistance would be appreciated.

Vectorgrid for Multipolylines

Hello :)

First of all thank you your plugin, I'm glad someone found a way to wrap it for React. It works like a charm for large GeoJSON with points.

Sadly this isnt the case for polylines, they are rendering wrong on the map as if the geojson was simplyfied. I have to zoom a lot (zoom level around 25+) to see more points.

Does anyone know a way to make it work like vanilla leaflet ? Here are two screenshots from the React and Vanilla redering. Thank you!

Vanilla Leaflet
vecgridnoreact

React Leaflet
vgridreact

onLoading not firing

Code:

import VectorGridDefault from 'react-leaflet-vectorgrid';
const VectorGrid = withLeaflet(VectorGridDefault);
<VectorGrid
                ref={mapRef}
                key={key}
                url={apiURL}
                type="protobuf"
                subdomains={['a', 'b', 'c']}
                minZoom={minZoom}
                vectorTileLayerStyles={defaultStyle}
                bounds={bounds}
                zIndex={zIndex}
                updateWhenIdle={false}
                updateWhenZooming={false}
                updateInterval={600}
                onLoading={() => console.log('loading')}
                onLoad={() => console.log('loaded')}
/>

Issue:
Tiles all load successfully and render, 'loaded' is logged. 'loading' is never logged - I cannot get this event to fire.
Same code using react-leaflet GridLayer logs both events correctly.
Any ideas? Am I doing something wrong here or is this a bug?

Use with react-leaflet 3.0

Hello there!
I am trying to use react-leaflet-vectorgrid with react-leaflet 3.0.
It doesn't work because in version 3.0 HOC 'withLeaflet' anymore doesn't exist.
Who can help?

Component not updating/re-rendering on changing redux props

I'm using this library to load a GeoJSON file but I'm changing the opacity using redux. For the first time, it is loading the proper opacity but not updating it after dispatching the actions to update props.

Currently, to make this thing work, I added this code but it is a bit laggy.

updateLeafletElement(oldProps, newProps) {
    if (oldProps != newProps) {
        this.forceUpdate();
    }
}

I think there should be a way to make this work properly.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.