0

So, the problem is how to show a map in browser using JavaScript.

I have a map file with 2 layers in it: "peta" is a shp data from PostGIS and "korban" is a numeric data from PostgreSQL, and then I have a HTML file, in that file I use JavaScript to show a toolbar but I don't know how to show the map from map files.

I have tried to call map file with "http://my.site/cgi-bin/mapserv.exe?MAP=C:/ms4w/Apache/htdocs/webgis.map&LAYERS=all&MODE=MAP" and the map shows but it cannot be zoomed, so I need to know how to show map with a query?

The query I mean is something like this

var query = 'select ' + 'admin_90_des(edit_pande,jawa)_2010."gid", ' + 'data_korban."2009", ' + 'admin_90_des(edit_pande,jawa)_2010."kel_desa", ' +
'admin_90_des(edit_pande,jawa)_2010."kecamatan", ' + 'admin_90_des(edit_pande,jawa)_2010."geom"' +
'FROM "admin_90_des(edit_pande,jawa)_2010" ' + '"data_korban"' +
'where "admin_90_des(edit_pande,jawa)_2010".gid="data_korban".gid ';

new_dbd = new OpenLayers.Layer.WMS("Peta", "http://my.site/cgi-bin/mapserv.exe?MAP=C:/ms4w/Apache/htdocs/webgis/webgis02.map&LAYERS=ALL&MODE=MAP&korbanDBD=geom FROM (" +
query +
") AS foo USING UNIQUE gid and USING SRID=-1", {
    layers: ['korban', 'peta'],
    format: 'image/png',
    transparent: true
}, {
    isBaseLayer: false
});

map.addLayers([new_dbd]);

But I don't understand how it works so please anyone can explain to me or at least give me some clue how can I show my map in browser?

  • One problem you have is the mode=map parameter. When you use this you don't get a WMS response and you have the problem you describe, ie a non zoomable map. Just remove the parameter. – nmtoken Feb 24 '17 at 4:38
1

The short answer is that you can't do what you're trying to do. OpenLayers requires that you pass in a URL to a WMS endpoint e.g.

http://my.host.com/cgi-bin/mapserv?map=mywms.map&

In your example above you are pointing to a MapServer map, not a WMS endpoint. The next problem is that I don't think MapServer allows you to filter or query WMS requests.

GeoServer has CQL support that does exactly this:

http://docs.geoserver.org/stable/en/user/services/wms/vendor.html#cql-filter

If there isn't a requirement to self host the map I would just use CartoDB, it can do exactly what you want out of the box. Who says that I only ever plug Mango on here? ;-)

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.