This project has moved and is read-only. For the latest updates, please go here.

client event on WMS map image

Topics: SharpMap v0.9 / v1.x, Web Controls
Jun 3, 2008 at 10:24 AM
Hi, everyone especially JonDiss :-)
Client get a map image from SharpMap WMS that include several points. I want to realize that when mouse move to these different points the corresponding request will send to Server to get detail info.
someone suggests me that use javascript "mousemove" event and set interval time. but the problem is if my mouse stop on the no-use district, the request still be triggered(at this time the request is no need).
Jun 3, 2008 at 10:36 AM
Edited Jun 3, 2008 at 10:39 AM
Hi again cdgrain, In the past I have solved this by rendering an html image map which is requested alonside the image and then 'overlayed' - in fact the images are tiled but the (html) image map isn't so there is one which spans the whole viewport. Then you can respond to the hotspots rather than querying arbitarily.. Another (preferable) way would be to have a wfs layer of features you wish to respond to - or overlayed images ala the points in google maps. that way the individual features can trigger events. To this end in the 1.1 experimental branch there is a GeoJSON renderer for creating a wfs and the beginnings of a crude HtmlImageMap renderer (which i dont think is quite right but dont have the time to look at presently..) The actual production (html)imagemap renderer we use doesnt really plug in to sharpmap and is kinda proprietary ;) hth jd
Jun 4, 2008 at 10:35 AM
thanks John.
in the 1.1 branch. what parameters should be sent to GeoJson.ashx to get features as GeoJson format? after that, i can use OpenLayers to overlay the GeoJson to map.
Is it feasible that on Server i write an intersect query method to get features(store their info with custom class serialized with Json) that the client need to display and trigger event. then use OpenLayers to draw them. and when mouse move to these features, the info will be showed without request to server.
When page load, I invoke this server method immediatelly. But i think in this way may cause rendering the map slowly when first load.
Jun 4, 2008 at 11:06 AM
Edited Jun 4, 2008 at 11:19 AM
Hi cdgrain, The demo uses the  BasicMapRequestConfigFactory to build an instance of  BasicMapRequestConfig which it uses to configure the map. The factory only takes BBOX and outputsize as parameters. But the idea is that you can create your own factory and implementation of IMapRequestConfig to take in and act on any parameters that you like..
You will notice on the GeoJSON renderer there is a property:
public Dictionary<string, Func<ILayer, FeatureDataRow, string>> AttributeProviders

this takes in the layer and the datarow for each feature and you can use it to append extra properties to the rendered Json. e.g. feature name, id, etc whatever you want really - and you can have multiple attributes per feature if you desire. So you can get all the data upfront and not have to requery - for certain datasets this is probably ok - for others you may want to add the id as a param and then requery using the id.. hth jd

Jun 12, 2008 at 11:03 AM
Edited Jun 12, 2008 at 11:05 AM
Hi,john. sorry for late reply.
I still cannot understand your code in 1.1experiment.But i define a web service method take in several parameters. then return object as JSON which contains features' point set and attribute. they are overlaied on the map well. these features are intersected with the specified bbox which represent the current visual area of client map. when pan the map, the bbox is changed correspondly. so, i must invoke the web service again then overlay these features. If i get all the features when page load, i dont need to requery. But i'm worry about that if features in shapefile contains thousands upon thousands. my solution will come up efficiency issue.
Jun 12, 2008 at 11:31 AM
Hi again cdgrain - I didnt mean get the whole dataset in one go - just all the features in the current viewport. When the viewport changes (pan/zoom etc) refresh the json layer accordingly.

If your viewport is likely to contain a lot of records just get the unique feature id as an attribute and requery the server on mouse over or click. If there are less features likely to display you can get a few extra attributes. Hope this is clearer.. jd
Jun 13, 2008 at 7:14 AM
Hi, John. thank you for your patient and warm heart.:)
Your description is very clear. But I still can not understand your demo code in 1.1 branch for my bad C# basis. But i understand your code principle under the help of your description. So i use web service method to implement similar function simply and it works fine.thanks.
I also have a question that when the viewport changed, json layer should be refreshed. if user change the viewport frequently, the refresh speed can keep up with the display speed, or does it cause pan or zoom map less smoothly? i use openlayers as client.
Jun 13, 2008 at 10:59 AM

Hi cdgrain, a few things come in to play here.. in my experience json is 'rendered' faster than an image because there is a lot less maths invloved,  but can be more verbose (but much less than gml) which requires more bandwidth to transmit - on a slow connection this could be bad...

But being text it compresses very well over the wire so bandwidth requirements can be reduced.
It should not aaffect the user interaction with open layers - but it may take a second or two for the data to arrive.. OTH If the server and the client are on the same machine open layers may respond less quickly because the machine is burning cpu doing the serving.. hth jd