I just found something else out. If I add a RectangleShape too, clicking events work both on the point and on the rectangle but if I only add a point it doesn't.
With RectangleShape it aways works. What's the problem with PointShape? should I do something else?
ShapeFileFeatureLayer capitalLayer2 = new ShapeFileFeatureLayer(@"C:\Program Files\ThinkGeo\Map Suite Web Evaluation Edition 4.5\Samples\CSharp Samples\SampleData\World\capital.shp"); // We can customize our own Style. Here we passed in a color and a size. capitalLayer2.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.CreateSimpleCircleStyle(GeoColor.StandardColors.White, 7, GeoColor.StandardColors.Brown); // The Style we set here is available from ZoomLevel01 to ZoomLevel05. That means if we zoom in a bit more, the appearance we set here will not be visible anymore. capitalLayer2.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level05; capitalLayer2.ZoomLevelSet.ZoomLevel06.DefaultPointStyle = PointStyles.Capital3; // The Style we set here is available from ZoomLevel06 to ZoomLevel20. That means if we zoom out a bit more, the appearance we set here will not be visible any more. capitalLayer2.ZoomLevelSet.ZoomLevel06.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; capitalLayer2.FeatureSource.Projection = mproj4Projection;
Just for the record I’m using the “Map Suite Web Evaluation Edition 4.5” to find out if it serves my company needs so we can license or not and so far it kind of doesn’t. Let me describe in detail what I’m trying to do: - show a bunch of points spread across the map - when one of this points is clicked, should have his associated position stored in a array of sorts - with some of these positions stored in a array, calculate the distance of the created path
That means, I would be important to print some points across a map using PointShape or a Marker or whatever so the user could select some of them to create a path and see the calculated distance. Looking throught your forums it seems that it’s only possible to get a clicked marker by looking for the nearest objects of some point: gis.thinkgeo.com/Support/DiscussionForums/tabid/143/aff/12/aft/7791/afv/topic/Default.aspx
Would you mind showing me some code on how to do that the right way using PointShapes or Markers or whatever is best in this cenario? Or maybe point me to a good example on your pages or something, because I really can’t find then if they exists.
We confirmed it is a bug (Point can't be selected when there is only one in the highlightOverlay) in WebEditon 4.5.0.0, we have fixed it and you can get the latest Evalution WebEdition (4.5.115.0 or later) to have another try.
Chris,
In your "Map1_Click" method, you should use the following code to get the features near the point you clicked.
Nice answer but your code is only good for getting streets and city names like the other guy needed. I want to return markers I create and draw myself. If I wanted to get these kind of map elements there is plenty of examples not only on your samples but also on your foruns.
Let me try to explain again: fist step I create a lot of markers, each with its own position on the map, on a marker overlay. This is a snipet from my code where platLocs is a [n,2] array of positions using DecimalDegree unit:
for (int c = 0; c < platLocs.GetLength(0); c++) {
double fact = 0.05;
lotsOfFeatures[c] = new Feature(platLocs[c,0], platLocs[c,1]);
<markeroverlayclickeventargs>As you can see after I added all markers to the overlay I create a event handling for this overlay then I add this overlay to the Map1 object. So far so good, every marker show up on the map and all. The problem is, when I click one of this markers I wanted to get the position it's on, but inside "markerOverlay_Click" function I have no way of getting it.
Now I just tried to use your little function up there. The idea I had was to create a event handler for the Map1 object, then from inside "Map1_Click" function I would be able to retrieve the markerOverlay object and the clicked position and maybe use the "GetFeaturesNearestTo" function from markerOverlay to retrieve the right marker, except InMemoryMarkerOverlay have no "GetFeaturesNearestTo" function right?
Using the HighlightOverlay member of Map1 seems like a option but can I get the exact position of the PointShape Feature from inside a click event?
Do you understand what I'm trying to do here? Is it possible with your suite to do something like that at all?
If I'm not giving you enough info about what I'm trying to do just ask me.
I think I found a way to at least retrieve the position of a clicked PointShape on the map. From inside the HighlightOverlay click event:
PointShape platPoint = null; if (e.ClickedFeature.GetWellKnownText().Contains(“POINT”)) { platPoint = new PointShape(e.ClickedFeature.GetWellKnownText()); } else { platPoint = e.Location; }
Still this way I don’t have the own PointShape object. I can only rebuild it so I can get its position. That means I can’t, for example, change its color from inside the event handler function right?
I would like to point out a couple of Code Community web projects that deal with clicking on features and identifying them. Those projects show how to implement that so that it is intuitive for the user. Please, see those projects Get Features Clicked On (Web) and Get Features Clicked On (Web) 2. They show how to do that with different types of layers (point, line and polygon based). I think you will get inspired.
Also, I would like to add that it always important to take into account in what Map Unit your map is because this is used as a parameter in the geometric functions underneath.
You have to understand that Markers are use to represent points only. So, if you have a circle, a rectangle or a polygon, Marker is not the appropriate style. What you could do though, for example, you could get the center point of the shape and use a Marker to represent it as you can see in the code below. I don't know if this is what you want to do but I am giving you some ideas.
SimpleMarkerOverlay markerOverlay = new SimpleMarkerOverlay("MarkerOverlay"); markerOverlay.DragMode = MarkerDragMode.Drag;
markerOverlay.Markers.Add(new Marker(polygonShape.GetCenterPoint(), new WebImage(21, 25, -10.5f, -25f)));