[OpenLayers-Dev] re turning a value to openlayers via a web service.

kalisilvermist kalisilvermist at gmail.com
Wed Oct 1 10:02:27 EDT 2008


Hi all,

I am having a problem integrating my openlayers implementation into my
site..
I have created a map page that needs to display cached WMS tiles(served by
tilecache), this it seems to do fine mostly. What i then need to do is click
on the map, return the Lat/Lon to an Asynch Web Service written in C# which
then launches the manifoldgis interop component to allow me to perform a
search within the geometry on the database. Now the query works,the
webservice works,the page works for most things however i cannot see what i
am doing wrong that my web service is not returning a result object or
rather it is but it's empty !

Here is the openlayers code.
=====================================
<script type="text/javascript">
	<!--
	    var map, layer, x, y, markersLayer;
	    OpenLayers.IMAGE_RELOAD_ATTEMPTS = 3;
	    OpenLayers.Util.onImageLoadErrorColor = "transparent";

	    //Control Click Handler
	    OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, {
	        defaultHandlerOptions: {
	            'single': true,
	            'double': false,
	            'pixelTolerance': 0,
	            'stopSingle': false,
	            'stopDouble': false
	        },

	        initialize: function(options) {
	            this.handlerOptions = OpenLayers.Util.extend(
                        {}, this.defaultHandlerOptions
                    );
	            OpenLayers.Control.prototype.initialize.apply(
                        this, arguments
                    );
	            this.handler = new OpenLayers.Handler.Click(
                        this, {
                            'click': this.trigger
                        }, this.handlerOptions
                    );
	        },

	        trigger: function(e) {

	            markerlayer.removeFeatures(markerlayer.features);
	            //map.removePopup(popup);

	            var lonlat = map.getLonLatFromViewPortPx(e.xy);

	            //var proxy =
Service.select_id_centrePoint_Geom_byLatLon(lonlat.lat,lonlat.lon,
onWebServiceCallBack);
	            var proxy =
Service.select_id_centrePoint_Geom_byLatLon(lonlat.lat,lonlat.lon,onWebServiceCallBack);
	            //var proxy = Service._Echo(lonlat.toString(),
onWebServiceCallBack);
	        }

	    });

	    function onWebServiceCallBack(result, userContext, methodName) 
	    {

	        var temp = new Array();
	        var s = result.toString();
	        temp = s.split(',');
	        var cmaID = temp[0];
	        Lat = temp[1];
	        Lon = temp[2];
	                   
	        var marker = new OpenLayers.Feature.Vector(
                        new OpenLayers.Geometry.Point(Lon, Lat), {
                            externalGraphic:
"http://localhost/TileCache/Images/marker-gold.png",
                            backgroundGraphic: "../Images/marker-gold.png",
                            backgroundXOffset: 0,
                            backgroundYOffset: -7,
                            graphicZIndex: 1100,
                            backgroundGraphicZIndex: 1000,
                            pointRadius: 10
                        });
	        //markerlayer.addMarker(marker);
	        markerlayer.addFeatures(marker);
	        map.addLayer(markerlayer);
	        var popup = new OpenLayers.Popup("Erf Info", "chickenlicken",
                                          new OpenLayers.Size(200, 600),
                                          "Clicked at:= Longitude :" + Lon +
" \n Latitude :" + Lat , true);

	        popup.setOpacity(0.7);
	        map.addPopup(popup);
	        alert(cmaID);
	    }

	    function init() {
	        var street_OverLay, erven_OverLay
	        x = 18.43678;
	        y = -33.9068;

	        //specify Resolution array - zooms			
	        var options = { resolutions: new Array(0.00001867185,
0.0000093359375, 0.00000466796875, 0.000002333984375, 0.0000011669921875),
'maxExtent': new OpenLayers.Bounds(bbox = 18.13232, -34.39155, 19.01818,
-33.39165), restrictedExtent: new OpenLayers.Bounds(bbox = 18.13232,
-34.39155, 19.01818, -33.39165) };

	        // set theme:null to enable style editing on the rows
	        //create a new map object
	        map = new OpenLayers.Map($('map'), options);
	        //set overlay
	        street_OverLay = new OpenLayers.Layer.WMS("Cape Metropolitan
Council",
                "tilecache.py?TRANSPARENT=true",
                { layers: "Municipal_Overlay", transparent: "true",
'maxExtent': new OpenLayers.Bounds(18.52, -34.62, 19.28, -33.77), format:
"image/png" }, { alpha: true });
	        street_OverLay.setZIndex(0);
	        street_OverLay.setVisibility(true);
	        street_OverLay.setIsBaseLayer(true);
	        map.addLayer(street_OverLay);

	        //create the erven overlay and set it to be invisible
	        //erven_OverLay = new OpenLayers.Layer.WMS( "Erven Overlay",
	        //    "tilecache.py?TRANSPARENT=true",
	        //    {layers: "Erven_Overlay",transparent: "true", format:
"image/png",minZoomLevel: 0, maxZoomLevel: 1 },{alpha:true});
	        //	erven_OverLay.setZIndex(100);
	        //   erven_OverLay.setVisibility(false);
	        //	/erven_OverLay.setIsBaseLayer(true);
	        //    map.addLayer(erven_OverLay);


	        //code to add marker layer

	        markerlayer = new OpenLayers.Layer.Vector(
                "Marker Drop Shadows",
                {
                    styleMap: new OpenLayers.StyleMap({
                        // Set the external graphic and background graphic
images.
                    externalGraphic:
"http://localhost/TileCache/Images/marker-gold.png",
                        backgroundGraphic: "../Images/marker-gold.png",
                        backgroundXOffset: 0,
                        backgroundYOffset: -7,
                        graphicZIndex: 11,
                        backgroundGraphicZIndex: 10,
                        pointRadius: 10
                    }),
                    isBaseLayer: false,
                    displayInLayerSwitcher: false,
                    rendererOptions: { yOrdering: true }
                }
            );
	        map.addLayers(markerlayer);
	        // Add The Control Box(es) to the page
	        map.addControl(new OpenLayers.Control.LayerSwitcher()); //layer
switching tool
	        //var options = {div:$('mouseco')};
	        map.addControl(new OpenLayers.Control.MousePosition()); // mouse x
and y co-ordinates
	        //map.removeControl(OpenLayers.Control.PanZoom());
	        map.removeControl(map.controls[1])
	        map.addControl(new OpenLayers.Control.PanZoomBar()); //Zoom Slider
I think
	        options = { div: $('labs') };
	        //map.addControl(new OpenLayers.Control.ScaleLine(options)); // to
give an idea of sacale
	        map.addControl(new OpenLayers.Control.ScaleLine(options));
	        //set the base layer this is the primary visible layer
	        //options = {div: $('powered')};
	        var click = new OpenLayers.Control.Click();
	        map.addControl(click);
	        click.activate();
	        map.setBaseLayer("Cape Metropolitan Council");
	        //add the overview map
	        //map.addControl(new OpenLayers.Control.OverviewMap({layers:
"Municipal_Overlay",isSuitableOverview: function() {return true;}})); 
	        //set the zoom and longlat of startup
	        map.setCenter(new OpenLayers.LonLat(x, y), 0);
	        if (!map.getCenter()) map.zoomToMaxExtent();

	    }
		
      // -->
    </script>
=================================
Here is the C# Web Method
=================================

  [WebMethod]
            public string select_id_centrePoint_Geom_byLatLon(double
Latitude, double Longitude)
            {
                StringBuilder sb = new StringBuilder();
                string s;
                MapServer mapServer = new MapServer();
                string State = "";
                mapServer.Create(Server.MapPath("config.txt"), State, "");
                Manifold.Interop.Query q =
(Manifold.Interop.Query)mapServer.Document.ComponentSet["Select_Erf_CentrePoint_and_Cma_ID"];
                q.ParameterSet["Lat"].Value = Latitude.ToString();
                q.ParameterSet["Lon"].Value = Longitude.ToString();
                q.Run();
                Manifold.Interop.Table T = q.Table;
                foreach (Manifold.Interop.Record r in T.RecordSet)
                {
                    foreach (Manifold.Interop.Column c in T.ColumnSet)
                    {
                        sb.Append(r.get_Data(c.Name) + "|");
                    }
                }
                s = sb.ToString();
                return s;
            }
            [WebMethod]
            public string _Echo(string input)
            {
                return input;
            }
            [WebMethod]
            public string _WS_Test()
            {
                return "Hello World";
            }


        }


and here is the aspx page
=================================

 </head>
  <body onload="init()">
  <form runat="server">
  <asp:ScriptManager runat="server" ID="ScriptManager1"
EnablePageMethods="True">
        <Services>
            <asp:ServiceReference
Path="http://localhost/MapService_Site/Service.asmx" />
        </Services>
        </asp:ScriptManager>
    </form>
	<div id="map">
	<div id="chickenlicken" style="position:relative;background-color: red;
color: white; font-size: 120%;left:110px;top:150px"></div>
    <div id="labs"><div id="outPutDiv"></div></div>
	<div id="powered">Powered By CMAInfo</div>
	</div>
	
   </body>
</html>

=========================================================

Really hope that someone will be able to assist me or perhaps provide a
better way. Web services are important in our project though because we need
to be able to offer various online services including mapservices.

Greetings from Cape Town(South Africa)

Sandro 

-- 
View this message in context: http://www.nabble.com/returning-a-value-to-openlayers-via-a-web-service.-tp19761190p19761190.html
Sent from the OpenLayers Dev mailing list archive at Nabble.com.




More information about the Dev mailing list