Does SharpMap has the ability to select each ID separately?

Topics: SharpMap v0.9 / v1.x
Mar 20, 2014 at 12:03 PM
Hello everyone, I am able to display my data as map from my database. But as far as I have read so far, SharpMap has the ability to zoom in or out and panning. I have geometry data in my database which display polylines. Would it be possible to select each line separately when I click on a particular line using sharpmap?

Mar 20, 2014 at 12:25 PM
asplearning wrote:
Would it be possible to select each line separately when I click on a particular line using sharpmap?
You mean when you click on a DataGridView row?
Mar 20, 2014 at 12:42 PM
FObermaier, I mean when I click on the map itself. Something similar this image ( As you can see, the line 796 is selected but that is because I use the textbox. Any chance this can be done by I directly click on line 796 rather going through the textbox?

Mar 20, 2014 at 1:02 PM
Edited Mar 20, 2014 at 1:02 PM
Ah, I see you are using the AjaxWebControl. Its use is deprecated. Instead it is suggested to use OpenLayers with SharpMap's WMS Server.
There are several example's in the SharpMap.Demo.Wms project.
Mar 20, 2014 at 8:19 PM
FObermaier, do you mean this demo I looked at it and doesn't look like what I am trying to achieve. Did I miss anything?
Mar 20, 2014 at 8:33 PM
I found the project FObermaier, but this is just MVC project. Do you have any samples for web application? Sorry I am not familiar with MVC. Thanks
Mar 20, 2014 at 8:36 PM
One more thing does OpenLayer supports MS SQL as it's datasource provider? I need to read data from my SQL Server.

Thanks again.
Mar 20, 2014 at 10:27 PM
Openlayers is based coded in javascript, so you would normally extract your information from the db serialise it to json and then parse it using openlayers to display it.

The method felix was explaining was to use sharpmap to connect to your database and render the data, and then provide this as a wms layer to openlayers. I have done this and it works very well. If you want to be able to select items, you should be able to do this just by passing the clicked coordinates back to your server and have it query the database and return the results. The openlayers examples page is a good place to start.
Mar 20, 2014 at 11:07 PM
Hello Robert, thanks for the reply. I checked the openlayers example, but it is in MVC. Could you shared with me some links to web application that used both SharpMap and OpenLayers? I checked the openlayers example in MVC, I can't find a lot of code except the javascript code on the view. I just want to know how to create wms layer and how it is provided to OpenLayers.

Thank you very much.
Mar 21, 2014 at 2:27 PM
this is a very simple bit of HTML/javascript that will load a WMS layer.

If you run the sharpmap WMS demo you should be able to find the url the demo uses to get the layers from the sharpmap WMS. if you substitute the address in this file for that one, it should work ok.

<!DOCTYPE html>
<head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"> <meta name="apple-mobile-web-app-capable" content="yes"> <title>OpenLayers Basic Single WMS Example</title> <link rel="stylesheet" href="" type="text/css"> <script src=""></script> <script type="text/javascript"> var map, layer; function init(){ map = new OpenLayers.Map( 'map',{maxResolution:156543.0339, maxExtent: new OpenLayers.Bounds(-20037508.34, -20037508.34, 20037508.34, 20037508.34), restrictExtent: new OpenLayers.Bounds(-20037508.34, -20037508.34, 20037508.34, 20037508.34)}); layer = new OpenLayers.Layer.WMS( "OpenLayers WMS", "http://localhost:9006/api/wms/15", {layers:'HybridMapLayer', version: '1.3.0', format:"image/png"},{'tileSize': new OpenLayers.Size(512,512), singleTile:true, ratio:1, projection:"EPSG:0"} ); map.addControl(new OpenLayers.Control.MousePosition()); map.addLayer(layer); map.zoomToExtent(layer.getExtent()); } </script> </head> <body onload="init()">
<div style="width:800px; height:600px; border-style:solid; border-width:2px;" id="map"></div>
<h1 id="title">Basic Single WMS Example</h1>

<div id="docs">
    <p>This example shows a very simple map view of webApi self hosted wms</p>

if you look in the Demo WMS project, there is a script called script_ol that has the values in it. Namely this bit:

options = {
    wms: 'WMS',
    wmslayers: ['poly_landmarks', 'tiger_roads', 'poi'].join(),
    controls: [],
    projection: 'EPSG:900913',
    displayProjection: 'EPSG:4326',
    format: 'image/png',
    wmsparams: {
        'MAP_TYPE': 'SPH'
    map = new OpenLayers.Map('map', options);
    sharpmap = new OpenLayers.Layer.WMS(
        'SharpMap WMS',
        '/wms.ashx', {
            layers: options.wmslayers,
            service: options.wms,
            version: '1.3.0',
            format: options.format,
            transparent: true
        }, {
            isBaseLayer: false,
            transparent: true,
            visibility: true,
            buffer: 0,
            singleTile: false,
            ratio: 1.5
    map.addLayers([new OpenLayers.Layer.OSM(), sharpmap]);
Make sure you have the demo project running otherwise the service will not work!
Marked as answer by asplearning on 4/1/2014 at 4:27 AM
Apr 1, 2014 at 11:28 AM
Thanks, I will give it a try.