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

problem using in React applicaton #63

Open
rowheat02 opened this issue Aug 24, 2019 · 2 comments
Open

problem using in React applicaton #63

rowheat02 opened this issue Aug 24, 2019 · 2 comments

Comments

@rowheat02
Copy link

rowheat02 commented Aug 24, 2019

Don't know how to import L.WMS in React. I am new to this React and leaflet.
Capture

Here is the code:

import 'leaflet/dist/leaflet.css';
import L from 'leaflet.wms/lib/leaflet';
import 'leaflet.wms/dist/leaflet.wms';
import 'leaflet.wms/lib/require';

class App extends Component {
  componentDidMount() {   
   var map1 = L.map("map").setView([27.664198, 85.361624], 5);
    var BaseOsm = L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png',
      {
        attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
      }).addTo(map1);
    map1.setView([-29.764377375163114, 147.3486328125
    ]);

    // var stComerciaisLayer= L.tileLayer.wms("http://localhost:8080/geoserver/nyc/wms", {
    //     layers: 'nyc:wind_direction',
    //     format: 'image/png',
    //     transparent: true,
    //     attribution: "Algum texto de teste"
    //   }).addTo(map1);

    var source = L.WMS.source("http://localhost:8080/geoserver/nyc/wms", {
      'transparent': true
    });


    source.getLayer('nyc:wind_direction').addTo(map1);

  }

  render() {
    return (
      <div style={{ width: 600, height: 600 }} id="map">

      </div>
    );
  }
}
export default App; ```

@rowheat02 rowheat02 changed the title problem using React applicaton problem using in React applicaton Aug 24, 2019
@ghost
Copy link

ghost commented Sep 17, 2019

The way we did this in our react application is by doing npm install of the library and importing it as such:

import LeafletWms from "leaflet.wms";

Now we can use it by doing

const layerSource = LeafletWms.source(
    "URL",
    {}
  );

layerSource.getLayer("LAYER_NAME").addTo(map)

@saedrna
Copy link

saedrna commented Mar 7, 2021

The way we did this in our react application is by doing npm install of the library and importing it as such:

import LeafletWms from "leaflet.wms";

Now we can use it by doing

const layerSource = LeafletWms.source(
    "URL",
    {}
  );

layerSource.getLayer("LAYER_NAME").addTo(map)

The above also works for vue.

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

2 participants