Hi, I have a problem with my proof of concept for my project. The project offers a feature that will convert shapefile (.shp) to spatial database inside SQL Server, each shp will be converted into a table. Once the spatial data has been validated and ready to be used, a small program will recognize all the tables then show to users which table that he wants to enable. He can enable either one, several, or all of the tables. Those enabled tables will be shown in WinformMap.
Now the problem is, I want to implement mouse click and mouse hover on that WinformMap. Assigning each table to MsSql2008FeatureLayer using List isn’t a big deal. What I’ve already known in order for clicking/hovering can grab a/some feature(s) on those MsSql2008FeatureLayer is each MsSql2008FeatureLayer must call Open(), get any features based on mouse pointer location, call Close(), then I can deal with features that has been taken (if there’s any).
The process of calling Open() and Close() on each MsSql2008FeatureLayer a bit inconvenient, is there any way to recognize/identify which MsSql2008FeatureLayer that need to be opened first, so we can just call Open() and Close() for the needed MsSql2008FeatureLayer only, not all of them?
Identifying FeatureLayer
Hi Ariestya,
Yes, “IsOpen” property is the right way for solving your issue, the latest version 7.0.275.0 can be download, you can try it with this version.
Best Regards
Summer
I think you didn’t get my question is… Is there any function, regarding recognizing which layer that should be opened first, before it’s opened?
The analogy is like opening a file… in older C, there’s no File.Exist like in C#, instead, in C we can try to force the open the file using fopen(), look for its return value, if it can be opened, then the file exists, if it can’t, then the file “might” not exist, but we know it’s not a proper way just to check whether the file exist or not. If he develops in Win32, he can call GetFileAttributes to determine whether the file is exist first before forcing try to open it.
It’s the same for this problem… is there any function, a function that works something like this - whenever the mouse is hover above a feature it tells this feature is available on this xx featurelayer, that’s all it can do. If I want to do something with its feature (to peek inside the feature, get its value, etc), then I have to call Open(), do whatever you want with it, then Close() it… But not to open every featurelayer that I load, check every time the mouse is moving which featurelayer this feature is belong to, grab the feature if it belongs to one of the featurelayer, then close all the featurelayer…
My code will closely look like this if this function doesn’t exist
foreach(var individualLayer in ListOfLoadedLayers)
{
individualLayer.Open();
selectedFeatures = individualLayer.QueryTools.GetFeaturesContaining(point, ReturningColumnsType.
// check which one is returning at least 1
if (selectedFeatures.Count > 0)
{
// then do something in here, e.g. transfer each selectedFeatures to a highlight
}
else
{
continue;
}
individualLayer.Close();
}
This code might a bit heavy if it’s needed to be executed each time the mouse moves (hovers), can it be reduced to something like this instead perhaps:
selectedFeatureLayer = somenamespace.classes.QueryTools.GetFeatureLayerByMouseLocation(ScreenPointF pointerLoc);
if(selectedFeatureLayer != null)
{
selectedFeatureLayer.Open();
// then do something in here
selectedFeatureLayer.Close();
}
So I don’t need to open all of the featurelayer that I’ve loaded, just open the only one that I need according to my mouse pointer location (ScreenPointF).
Hi Ariestya,
Thanks for your detailed description, I think I have understood your point now, following code if the code for your requirement:
first add layer info into a feature’s columnvalues
feature.ColumnValues[“LayerName”] = layer.name
then use a feature.ColumnValues(“LayerName”) to find corresponding layer with following code:
ListOfLoadedLayers[feature.ColumnValues[“LayerName”]].
Hope it helps,
Thanks,
Summer