[mapguide-users] Automatic zoom to selected features

soudemans soudemans at ruekert-mielke.com
Wed Nov 30 10:47:27 EST 2011


Hi,

I have a selection and the ability to highlight the features in the map.  To
get this to work I inject the following Javascript:

    Public Sub HighlightFeatures(ByVal selectionSet As MgSelectionBase)
        ' Escape any single quotes 
        Dim xml As String = selectionSet.ToXml().Replace("'", "\'")
        ' Build the JavaScript code to set the active selection
        Dim s As String = "<script
type=&quot;&quot;text/javascript&quot;&quot; &quot;
        s += &quot;language=&quot;&quot;javascript&quot;&quot; &quot;
        s += &quot;for=&quot;&quot;window&quot;&quot;
event=&quot;&quot;onload&quot;&quot;>" & vbLf
        s += "  var main = window.opener.window.opener;" & vbLf
        s += "  var map = main.GetMapFrame();" & vbLf
        s += "  map.SetSelectionXML('" & xml & "');" & vbLf
        's += "OnResultChange();" & vbLf
        s += "</script>" & vbLf
        ' Use the HttpResponse object to send this code to the client
        Response.Write(s)
    End Sub

I also have a Javascript function to zoom to the selected features but it is
based on a hard coded scale as follows:

        function ZoomToFeature()
        {
            var resultSelect = document.getElementById("resultSelect");
            var scaleInput = document.getElementById("scaleInput");
            scale = scaleInput.value;
            scale = ((scale == 0)? 10000 : scale);
            scale = parseFloat(scale + String(".0"));

            feature = results[resultSelect.value];
            parent.parent.mapFrame.ZoomToView(feature.centerX,
feature.centerY, scale, true);
        }

Unfortunately the selection set varies greatly in size and geographic scope
so I would like to be able to calculate or get the extends and zoom scale of
the selected features so I can zoom to all of the selected features.  I have
searched and found a variety of answers, most of them 2 or more years old,
describing complicated work arounds.  Have recent releases in MapGuide OS
made this easier?  And if so can someone provide me with a code sample on
how to do this?

Thanks 

--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/Automatic-zoom-to-selected-features-tp7047230p7047230.html
Sent from the MapGuide Users mailing list archive at Nabble.com.


More information about the mapguide-users mailing list