[Users] Fit GeoExt PrintPage to extent of a feature
Andreas Hocevar
ahocevar at opengeo.org
Sun Feb 17 11:24:03 CET 2013
Hey,
the code needs the map, and it gets the map through the
feature.layer.map reference. If you don't add the feature to a layer,
you may want to do something like the following instead of using the
fit() method:
printMapPanel.map.zoomToExtent(feature.getBounds());
Andreas.
On Sun, Feb 17, 2013 at 11:02 AM, Thomas Colley
<it087 at neath-porttalbot.gov.uk> wrote:
> Thanks for your reply Andreas
>
> There are 2 WMS layers on my map, walks (linestrings) and start points
> (points). When a user clicks on a start point a WMSGetFeatureInfo
> request is made across both layers to bring back the start point feature
> that contains all of the attribute information to be displayed in the
> popup and sent through to mapfish for the printed map and the feature
> for the walk itself just for the geometry. The GML response is then read
> and the individual features are extracted.
>
> These features are then passed into the PrintWalk procedure. I guess it
> makes sense that the features returned by the GetFeatureInfo don't
> actually belong to any layer. I will create a Vector Layer to add the
> walk feature to and hopefully that will solve the problem.
>
> Just out of interest is there a reason the code looks for a feature to
> belong to a layer as all it needs is the geometry of the feature itself?
>
> Thanks very much for your advice
>
> Tom
>
> map.events.register('click',this,function(e){
> var lonLat = map.getLonLatFromPixel(new
> OpenLayers.Pixel(e.xy.x, e.xy.y));
> var params={
> REQUEST: "GetFeatureInfo",
> EXCEPTIONS: "application/vnd.ogc.se_xml",
> BBOX: map.getExtent().toBBOX(),
> X: parseInt(e.xy.x),
> Y: parseInt(e.xy.y),
> INFO_FORMAT: 'application/vnd.ogc.gml',
> QUERY_LAYERS:
> ['web_walks_start_points','web_walks'],
> FEATURE_COUNT: 2,
> Srs: 'EPSG:27700',
> Layers: ['web_walks_start_points','web_walks'],
> Styles: '',
> WIDTH: map.size.w,
> HEIGHT: map.size.h
> };
>
> var
> request=OpenLayers.loadURL(GeoServerURL,params,this,function(_response){
>
> var gmlLayer=new OpenLayers.Format.GML({
> featureNS: 'http://www.npt.gov.uk/',
> featurePrefix: 'npt',
> geometryName: 'geom',
> extractAttributes: true
> });
>
> var
> features=gmlLayer.read(_response.responseText);
>
> if (features.length!=2){
> return;
> }
>
> startFeat = features[0]
> walkFeat = features[1]
>
> blurb = OpenLayers.Request.GET({
> url: "1.html", //test
> web page, will dynamically point to formatted feature page for popup
> callback: function Pop(){
> var popup = new
> OpenLayers.Popup.FramedCloud(
> 'infopop',
> lonLat,
> new OpenLayers.Size(10,
> 10),
> blurb.responseText +
> '<input type="button" value="Print..."
> onclick="PrintWalk(walkFeat,startFeat);">',
> { offset: { x: 0, y: 0
> }, size: new OpenLayers.Size(0, 0) },
> true
> );
> map.addPopup(popup, true);
> }
> });
> });
>
> OpenLayers.Event.stop(e);
> })
>
>
> -----Original Message-----
> From: andreas.hocevar at gmail.com [mailto:andreas.hocevar at gmail.com] On
> Behalf Of Andreas Hocevar
> Sent: 15 February 2013 17:02
> To: Thomas Colley
> Cc: Users at geoext.org
> Subject: Re: [Users] Fit GeoExt PrintPage to extent of a feature
>
> This looks like the feature you pass to PrintWalk does not belong to a
> layer. You will need to provide more context so we can see what is
> wrong.
>
> Andreas.
>
> On Fri, Feb 15, 2013 at 10:01 AM, Thomas Colley
> <it087 at neath-porttalbot.gov.uk> wrote:
>> Hi Everyone
>>
>>
>>
>> I am trying to add a print function to a map using GeoExt and the
>> Geoserver print module.
>>
>>
>>
>> Users click on a feature to bring up an information popup with a print
>
>> button in it. When the print button is clicked I would like the
>> PrintPage extent to fit to the feature. I am not having much luck so
>> far. Below is the print function.
>>
>>
>>
>> PrintWalk = function(feature) {
>>
>> var featGeom = feature.geometry
>>
>> printPage.fit(feature, true);
>>
>> }
>>
>>
>>
>> The error I get is:
>>
>> TypeError: fitTo.layer is null GeoExt.js
> (line
>> 166)
>>
>>
>>
>> I have also tried printPage.fit(featGeom, true); instead it is looking
>
>> for the geometry rather than the feature itself but then I get
>>
>> TypeError: map.getExtent is not a function GeoExt.js
> (line
>> 167)
>>
>>
>>
>> The feature geometry being passed through is a multilinestring.
>>
>>
>>
>> Using printPage.fit(map, true) prints fine.
>>
>>
>>
>> I would be very grateful if anyone has any ideas what I'm doing wrong.
>>
>>
>>
>> Thanks
>>
>>
>>
>> Tom
>>
>>
>>
>>
>>
>>
>> _______________________________________________
>> Users mailing list
>> Users at geoext.org
>> http://www.geoext.org/cgi-bin/mailman/listinfo/users
>>
>
>
>
> --
> Andreas Hocevar
> OpenGeo - http://opengeo.org/
> Expert service straight from the developers.
>
>
--
Andreas Hocevar
OpenGeo - http://opengeo.org/
Expert service straight from the developers.
More information about the Users
mailing list