1

actually here is url of geoserver on which my map is published: http://localhost:8081/geoserver/test/wms?service=WMS&version=1.1.0&request=GetMap&layers=test:city_limit&styles=&bbox=-114.315796136219,50.842822033593,-113.859905274451,51.2124253170889&width=768&height=622&srs=EPSG:4326&format=application/openlayers

And i have written a html code using leaflet api to connect to geoserver:

<!DOCTYPE html>
<html>
<head>

    <title>WMS example - Leaflet</title>

    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <link rel="shortcut icon" type="image/x-icon" href="docs/images/favicon.ico" />

    <link rel="stylesheet" href="https://npmcdn.com/leaflet@1.0.0-rc.3/dist/leaflet.css" />
    <script src="https://npmcdn.com/leaflet@1.0.0-rc.3/dist/leaflet.js"></script>

    <style>
        #map {
            width:600px;
            height: 400px;
        }
    </style>

</head>
<body>

<div id='map'></div>

<script type="text/javascript">

    var map = L.map('map', {
        center: [-17, -67],
        zoom: 3
    });

    var wmsLayer = L.tileLayer.wms('http://localhost:8081/geoserver/web', {
        layers: 'test:city_limit'
    }).addTo(map);

</script>



</body>
</html>

Output screenshot

0

The URL of the WMS request you included in your example has EPSG:4326 on it, but Leaflet uses EPSG:3857 by default (which might not be enabled on your GeoServer).

You will find insights on how to use EPSG:4326 with Leaflet in the WMS tutorial

  • thanks sir .....now the map is visible but now to i have to zoom atleast 10 times to view the map.So sir what could be a problem?? – Vikas Shah Aug 9 '16 at 14:44
  • I guess the data of your WMS service is local, and doesn't include some global dataset such as countries or coastlines. In Leaflet, you should fitBounds to the extents of your data. – IvanSanchez Aug 9 '16 at 15:07
  • sir as i am new to leaflet api so i dont know much about it .......could you please explain how to use fitbound or use global dataset – Vikas Shah Aug 9 '16 at 15:23
  • i want that if i run my code .....map should be automatically displayed and i dont have to zoomm again and again – Vikas Shah Aug 9 '16 at 15:31
  • Make a new question for that. – IvanSanchez Aug 10 '16 at 8:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.