Thanks to Luis Avila and Cameron Shorter for the help,
I finally did it. I was success creating my first widget, (and almost my
first JavaScript program). It must be revised and probably corrected but I
think its useful and it makes its work fast and well.
You can use it to make your map zoom to the interesting area resulting from,
for example, a search form or other GML sources.
The widget changes the extent of the targetModel using the boundingbox from
the model. It has an optional parameter <zoomFactor> which affects the scale
of the boundinbBox. a value of 1 to this parameter makes an extent to the
returned bounding box from the model, a value greater than 1 makes a zoom out
with that factor. The changes I made are the following:
First I added the getBoundingBox method to the FeatureCollection model: (this
is the model I use with my search form)
Here is that segment of code in FeatureCollection.js:
this.getBoundingBox = function () {
var boundingBox =
this.doc.selectSingleNode("/wfs:FeatureCollection/gml:boundedBy/gml:Box/gml:coordinates");
if (boundingBox) {
var bboxArray= boundingBox.firstChild.nodeValue.replace("
",",").split(",");
var bbox= new Array( parseFloat(bboxArray[0])
,parseFloat(bboxArray[1]), parseFloat(bboxArray[2]), parseFloat(bboxArray[3]));
return bbox;
}
};
I added an optional parameter zoomFactor to the zoomToBox method of the
Extent object in the tools folder, this allow us to change the scale of the
bounding box.
this.zoomToBox=function(ul,lr,zoomFactor){var center=new
Array((ul[0]+lr[0])/2,(ul[1]+lr[1])/2);
if(!zoomFactor){zoomFactor=1;}
newres=zoomFactor*Math.max((lr[0]-ul[0])/this.size[0],(ul[1]-lr[1])/this.size[1]);
this.centerAt(center,newres);
}
This is the code of the new widget ZoomToBoundingBox.js
mapbuilder.loadScript(baseDir + "/widget/WidgetBase.js");
function ZoomToBoundingBox(widgetNode, model) {
WidgetBase.apply(this, new Array(widgetNode, model));
this.zoomFactor = 10;
var zoomFactorNode = widgetNode.selectSingleNode("mb:zoomFactor");
if (zoomFactorNode) {this.zoomFactor =
parseFloat(zoomFactorNode.firstChild.nodeValue);}
this.paint = function (objRef) {
var bbox = objRef.model.getBoundingBox();
if (bbox) {
objRef.targetModel.extent.zoomToBox(new Array(bbox[0],
bbox[1]), new Array(bbox[2], bbox[3]), objRef.zoomFactor);
}
};
model.addListener("refresh", this.paint, this);
}
Here is the segment of the map_config.xml allowing the searching.
<models>
. . .
<FeatureCollection id="featureCollectionBusqueda">
<scriptFile>FeatureCollectionAdrian.js</scriptFile>
<widgets>
<ZoomToBoundingBox id="zoomToGML">
<scriptFile>ZoomToBoundingBox.js</scriptFile>
<zoomFactor>5</zoomFactor>
<htmlTagId>mainMapPane</htmlTagId>
<targetModel>mainMap</targetModel>
</ZoomToBoundingBox>
<GmlRendererWZ id="testGmlRenderer">
<htmlTagId>mainMapPane</htmlTagId>
<targetModel>mainMap</targetModel>
<mapContainerId>mainMapContainer</mapContainerId>
<lineColor>#55FF55</lineColor>
<lineWidth>3</lineWidth>
<pointDiameter>10</pointDiameter>
<fill>transparent</fill>
</GmlRendererWZ>
</widgets>
<namespace>xmlns:gml='http://www.opengis.net/gml'
xmlns:wfs='http://www.opengis.net/wfs'
xmlns:topp='http://www.openplans.org/topp'</namespace>
</FeatureCollection>
</models>
<widgets>
<WebServiceForm id="BuscaNomenclaForm">
<!-- I changed the WebServiceForm.js to send the WFSs FILTER parameter
in the request containing a XML which codes the filter condition from the form
data-->
<scriptFile>WebServiceFormAdrian.js</scriptFile>
<targetModel>featureCollectionBusqueda</targetModel>
<ntsTitle>Busqueda de partido partida</ntsTitle>
<stylesheet>NomenclaturaFormu.xsl</stylesheet>
<webServiceUrl>/geoserver/wfs/?request=GetFeature&typeName=topp:parcelas&propertyName=new_geom&outputFormat=GML2</webServiceUrl>
</WebServiceForm>
. . .
</widgets>
I also added support to the EPSG:22195 projection in the Proj.js on the model
folder, here is the snippet of the change:
case "EPSG:22195":case new
String("HTTP://WWW.OPENGIS.NET/GML/SRS/EPSG.XML#22195").toUpperCase():
this.title = "Campo Inchauspe / Argentina 5";
this.Init = tminit;
this.Forward = ll2tm;
this.Inverse = tm2ll;
this.Init(new Array(6378388, 6356911.94612795, 1, -60, -90,
5500000, 0));
this.units = "meters";
break;
I send all the files I changed including a map_config.xml sample
Thanks and good luck
Adrián Demaestri
ps:(Sorry for my English)
__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
Regístrate ya - http://correo.espanol.yahoo.com/
ZoomToBoundingBox.rar
Description: 1989148304-ZoomToBoundingBox.rar
------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/
_______________________________________________ Mapbuilder-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mapbuilder-users
