Skip to content

problem using in React applicaton  #63

Description

@rowheat02

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; ```

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions