I am trying to use display shapefile data on top of raster images using Leaflet. I render the shapefile data using leaflet L.tileLayer.wms function.
The size of shapefile is 300mb. The problem is that the rendering is crazy slow when I use MapServer. It takes almost a minute to render it on raster images.
I did the same thing using GeoServer with Leaflet and it rendered the same shapefile almost instantly.
This is the Leaflet viewer I Used for both MapServer and GeoServer.
<html>
<head>
<title>Leaflet WMS and XYZ</title>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />
<style>
#map {
width: 100%;
height: 500px;
}
</style>
</head>
<body>
<div id="map"></div>
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
<script>
var map = L.map("map").setView([30.479506155652967, 71.2240726004029], 5);
//This is the raster images stored locally on my disk.
var xyz = L.tileLayer(
"http:/localhost:3000/{z}/{x}/{y}",
{
attribution:
'This renders raster images as basemap which was downloaded from open street map'
}
);
//This is the mapserver link which uses wms to render shapefile
//Notes: This is using mapserver In case of Geoserver I simply replace it
// with geoserver link.
var wms_layer = L.tileLayer.wms(
"http://localhost/cgi-bin/mapserv.exe?map=C:/ms4w/apps/msolp/mymap.map",
{
layers: "road",
format: "image/png",
transparent: true,
version: "1.1.0",
attribution: "ROADS"
}
);
var baseLayers = {
XYZ: xyz
};
var overlays = {
WMS: wms_layer
};
var control = L.control.layers(baseLayers, overlays).addTo(map);
xyz.addTo(map);
wms_layer.addTo(map);
</script>
</body>
</html>
As for Mapfile This is is how my mapfile look likes
MAP
NAME "MyMap"
STATUS ON
SIZE 400 300
EXTENT 60.817362 24.043970 77.126716 37.143147
UNITS DD
SHAPEPATH "data"
PROJECTION
"init=epsg:4326"
END
WEB
IMAGEPATH "/ms4w/tmp/ms_tmp/"
IMAGEURL "/ms_tmp/"
METADATA
"tile_map_edge_buffer" "10"
"tile_metatile_level" "0"
"wms_title" "My Global Map WMS Server"
"wms_onlineresource" "http://localhost/cgi-bin/mapserv.exe?map=C:/ms4w/apps/msolp/mymap.map" #must change mapfile path
"wms_srs" "EPSG:4326 EPSG:3857 EPSG:4269"
"wms_enable_request" "*"
END
END
LAYER
NAME road
TYPE LINE
DATA "gis_osm_roads_free_1.shp"
STATUS DEFAULT
CLASS
STYLE
COLOR 255 0 0
OUTLINECOLOR 0 0 255
END
END
END
END