[ka-Map-users] specifying mapfile on the fly
Eddy
tlessh at gmail.com
Tue Apr 10 13:45:33 EDT 2007
Hi,
I have succeeded loading map file on the fly (in my case).
Even the backend is java, but the process is roughly similar if u are using php.
The key is in mapscript(server) and the _layer js (client) object.
First part: (javascript)
i made _objectLayer js that extend the _layer object
function _objectLayer( szName, bVisible, opacity, imageformat,
bQueryable, zIndex, server, url, map, vf, vs, vt, cf, co, lg) {
log4js.debug("groupLayer :"+szName);
_layer.apply(this,[szName,bVisible,opacity,imageformat,bQueryable]);
this.visible = bVisible;
this.bWidthHeight = false;
this.name= szName;
this.baseURL = server+url; // this part is where the servlet is linked
this.map = map;
this.vectorFile = vf;
this.vectorShape = vs;
this.vectorType = vt;
this.colorFill = cf;
this.colorOutline = co;
this.layersToGroup = lg;
this.zIndex = zIndex;
for (var p in _layer.prototype) {
if (!_objectLayer.prototype[p])
_objectLayer.prototype[p]= _layer.prototype[p];
}
then the loader just put this:
var l1 = new _objectLayer(vnc1, bVisible, opacity, imageformat,
bQueryable, zIndex, server, url, map, vfc1, vsPoly, vt, cf, co, lg);
myKaMap.addExtMapLayer(l1);
also to avoid a messy with original kamap.js addMapLayer, add a little
modification:
kaMap.prototype.addExtMapLayer = function( l ) {
var map = this.getCurrentMap();
map.addLayer(l);
this.setMapLayers();
this.paintLayer(l);
//to prevent legend shows up the time series name
this.triggerEvent( KAMAP_LAYERS_CHANGED, this.currentMap );
document.getElementById('group_'+l.name).style.display="none";
};
Second part (java servlet + java mapscript)// you can easily replace
it with the php/mapscript.
In this case i put another layer(map from gml file) on a base map,
String mapPath = ((MapBean) Config.aszMapBeans.get(map)).getPath();
oMapBase = new mapObj(mapPath);
//create a new map on the fly
//copy similar property from base map
mapObj oMap = new mapObj("");
oMap.setName("object_tile");
oMap.setUnits(oMapBase.getUnits());
oMap.setResolution(oMapBase.getResolution());
...
oMap.setMetaData("labelcache_map_edge_buffer", "-" + Config.metaBuffer);
double[] inchesPerUnit = {1, 12, 63360.0, 39.3701, 39370.1, 4374754};
float geoWidth = (float) (scale / (oMap.getResolution() *
inchesPerUnit[oMap.getUnits().swigValue()]));
float geoHeight = (float) (scale / (oMap.getResolution() *
inchesPerUnit[oMap.getUnits().swigValue()]));
/* draw the metatile */
float minx = metaLeft * geoWidth;
float maxx = minx + geoWidth * oMap.getWidth();
float maxy = -1 * metaTop * geoHeight;
float miny = maxy - geoHeight * oMap.getHeight();
oMap.setExtent(minx, miny, maxx, maxy);
oMap.setImageType(oMapBase.getImagetype());
oMap.getOutputformat().setTransparent(Config.MS_ON);
...
//create layer identically like mapserver map
oLayer = new layerObj(oMap);
oLayer.setName(vectorName + i);
oLayer.setGroup(vectorName);
oLayer.setConnectiontype(MS_CONNECTION_TYPE.MS_OGR);
oLayer.setConnection(vectorFilenameGML);
//create class
//create style
//add another function as you like... like store it to certain location...
Hopefully this is useful.
Cheers,
Eddy Lim
Pontianak, Indonesia
More information about the ka-Map-users
mailing list