[OpenLayers-Dev] Get resulting bounding box from TouchNavigation

Tim-Hinnerk Heuer th.heuer at gmail.com
Wed Oct 10 13:20:23 PDT 2012


Hi,

Since you are using GWT it would make sense to use GWT-OpenLayers:
http://sourceforge.net/projects/gwt-openlayers

You can then do the same thing with Java code instead of inlining "native"
code:

        map.addMapZoomListener(new MapZoomListener() {
            public void onMapZoom(MapZoomEvent eventObject) {
                Bounds bounds = eventObject.getSource().getExtent();
                // Your code here
            }
        });

That way you can debug in the Java code instead of having to debug
JavaScript. Maybe that will make it easier for you to find out what is
going on.

Regards,
Tim

Tim-Hinnerk Heuer

Twitter: @geekdenz
Blog: http://www.thheuer.com



On 11 October 2012 04:58, Bessette-Halsema, Dominique E <
Dominique.Bessette at gdit.com> wrote:

> Hi
>
> Sorry I'm new to openlayers and javascript
>
> I'm still having trouble getting the correct lat/lon bounding box when I
> zoom in.  I'm registering the map but I cant seem to get the correct bounds.
>
> I'm using
> $wnd.boxControl = new $wnd.OpenLayers.Control.TouchNavigation();
>
>
>
> Javascript:
>     /**
>      * Creates the OpenLayers map.
>      * @param mapDiv the {@code div} element to put the map in
>      */
>     private static native void createMap(Element mapDiv,MapView scope) /*-{
>         var options = {
>             'restrictedExtent': new $wnd.OpenLayers.Bounds(-360.0, -90.0,
> 360.0, 90.0),
>             'projection': 'EPSG:4326',
>             'displayProjection': 'EPSG:4326',
>             'maxResolution': 'auto',
>             'maxExtent': new $wnd.OpenLayers.Bounds(-180.0, -90.0, 180.0,
> 90.0),
>             'maxZoomLevel': 16,
>             'numZoomLevels': 16,
>             'units': 'degrees',
>             'fractionalZoom': false,
>             'controls': [],
>             'theme': null
>         };
>         $wnd.map = new $wnd.OpenLayers.Map(mapDiv, options);
>         $wnd.map.addLayers([$wnd.worldLayer, $wnd.aoiBoxes]);
>
>          function notice() {
>                         var EPSG4326 = new
> $wnd.OpenLayers.Projection("EPSG:4326");
>                                 var EPSG900913 = new
> $wnd.OpenLayers.Projection("EPSG:900913");
>                                 var bounds = $wnd.map.getExtent().clone();
>                                 bounds = bounds.transform(EPSG900913,
> EPSG4326);
> //              var bounds =
> $wnd.map.getExtent().transform($wnd.map.projection,
> $wnd.map.displayProjection);
>                 var leftBottomPx = new $wnd.OpenLayers.Pixel(bounds.left,
> bounds.bottom);
>                 var rightTopPx = new $wnd.OpenLayers.Pixel(bounds.right,
> bounds.top);
>                 var leftBottomLonLat =
> $wnd.map.getLonLatFromViewPortPx(leftBottomPx);
>                 var rightTopLonLat =
> $wnd.map.getLonLatFromViewPortPx(rightTopPx);
>                 scope. at mil.navy.fnmoc.gis.mapss.selection.client.MapView
> ::updateCorners(DDDD)(
>                     leftBottomLonLat.lon, leftBottomLonLat.lat,
> rightTopLonLat.lon, rightTopLonLat.lat);
>             }
>         $wnd.map.events.register("zoomend", $wnd.map, notice);
>
>
>     }-*/;
>
>
>
> Java:
>
> /**
>      * Updates the corners of the AOI bounding box in the corner text
> boxes.
>      * @param minLon the new minimum longitude
>      * @param minLat the new minimum latitude
>      * @param maxLon the new maximum longitude
>      * @param maxLat the new maximum latitude
>      */
>     private void updateCornerBoxes(double minLon, double minLat, double
> maxLon, double maxLat) {
>          LOGGER.log(Level.FINE, "Update Corners "+minLon + " "+minLat + "
> " + maxLon + " "+ maxLat);
>         this.southNumberField.setValue(clampLatitude(minLat));
>         this.northNumberField.setValue(clampLatitude(maxLat));
>         wrapLongitudes(minLon, maxLon);
>     }
>
>
> -----Original Message-----
> From: andreas.hocevar at gmail.com [mailto:andreas.hocevar at gmail.com] On
> Behalf Of Andreas Hocevar
> Sent: Tuesday, October 09, 2012 8:55 AM
> To: Bessette-Halsema, Dominique E
> Cc: openlayers-dev at lists.osgeo.org
> Subject: Re: [OpenLayers-Dev] Get resulting bounding box from
> TouchNavigation
>
> The easiest to achieve this is to register for the map's zoomend event:
>
>     function notice() {
>         var bounds = map.getExtent();
>         /* your existing notice code here */
>     }
>     map.events.register("zoomend", this, notice);
>
> Andreas.
>
> On Tue, Oct 9, 2012 at 12:25 AM, Bessette-Halsema, Dominique E <
> Dominique.Bessette at gdit.com> wrote:
> > Hi
> >
> > I'm having issues creating handlers for my mobile touch map.  Using
> TouchNavigation I'm able to Pan and PinchZoom but I need the resulting
> bounding box from the map.  If you look at the old Non-mobile code below I
> need to be able to call the notice function when the user is done panning
> and zooming.  Is there a way I can do this?
> >
> > TouchNavigation code
> >
> > private static native void createBoxControl(MapView scope, boolean
> activateBoxCtrl) /*-{
> >     $wnd.boxControl = new $wnd.OpenLayers.Control.TouchNavigation({
> >             dragPanOptions: {
> >                 interval: 0, // non-zero kills performance on some
> mobile phones
> >                 enableKinetic: true
> >             }
> >         })
> >
> >
> > }-*/;
> >
> >
> >
> > Old Non-Mobile code
> >
> > private static native void createBoxControl(MapView scope, boolean
> activateBoxCtrl) /*-{
> >         $wnd.boxControl = new $wnd.OpenLayers.Control();
> >         $wnd.OpenLayers.Util.extend($wnd.boxControl, {
> >             draw: function() {
> >                 this.handler = new
> $wnd.OpenLayers.Handler.Box($wnd.boxControl,
> >                     {"done": this.notice},
> >                     {keyMask: $wnd.OpenLayers.Handler.MOD_SHIFT});
> >                 if(activateBoxCtrl) {
> >                     this.activate();
> >                 }
> >             },
> >
> >             notice: function(bounds) {
> >                 var leftBottomPx = new
> $wnd.OpenLayers.Pixel(bounds.left, bounds.bottom);
> >                 var rightTopPx = new $wnd.OpenLayers.Pixel(bounds.right,
> bounds.top);
> >                 var leftBottomLonLat =
> $wnd.map.getLonLatFromViewPortPx(leftBottomPx);
> >                 var rightTopLonLat =
> $wnd.map.getLonLatFromViewPortPx(rightTopPx);
> >                 scope. at mil.navy.fnmoc.gis.mapss.selection.client.MapView
> ::updateCorners(DDDD)(
> >                     leftBottomLonLat.lon, leftBottomLonLat.lat,
> rightTopLonLat.lon, rightTopLonLat.lat);
> >             }
> >         });
> >     }-*/;
> > _______________________________________________
> > Dev mailing list
> > Dev at lists.osgeo.org
> > http://lists.osgeo.org/mailman/listinfo/openlayers-dev
>
>
>
> --
> Andreas Hocevar
> OpenGeo - http://opengeo.org/
> Expert service straight from the developers.
>
> _______________________________________________
> Dev mailing list
> Dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/openlayers-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/openlayers-dev/attachments/20121011/565b81fe/attachment.html>


More information about the Dev mailing list