Hi all,
I have an issue with web edition 3 where I can't seem to refresh the map with a custom overlay that
I just put on it, at least, not without physically moving the map around first. How can I refresh the map so
that the overlay shows up through code ? I have a windows timer that I am using and initialize on
Page_Init to do the asynchronous updates to the markers (which I will be getting the positions for
from a database). The map control itself is within an AJAX updatepanel. I read a post prior
where support told the person not to put the map in an updatepanel but I don't want the map to
cause a postback every time I zoom in or move the map around? I just want to be able to have my
timer update the marker positions, put them in an overlay and replace the previous overlay with the
generated one. Any help would be appreciated! I have posted the code I am using below just in
case it was needed.
Thanks in advance.
Bob
Protected _timer As System.Timers.Timer
Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
_timer = New System.Timers.Timer(5000)
AddHandler _timer.Elapsed, AddressOf timer_Elapsed
End Sub
Private Sub timer_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs)
If Not tgMap.CustomOverlays.Contains("MarkerOverlay") Then
Dim markerOverlay As New SimpleMarkerOverlay("MarkerOverlay")
markerOverlay.DragMode = MarkerDragMode.Drag
markerOverlay.Markers.Add(New Marker(-8922952.93266, 2984101.58384, New WebImage(21, 25, -10.5F, -25.0F)))
markerOverlay.Markers.Add(New Marker(-10830821.09801, 4539747.98328, New WebImage(21, 25, -10.5F, -25.0F)))
markerOverlay.Markers.Add(New Marker(-12454955.13517, 4980025.26614, New WebImage(21, 25, -10.5F, -25.0F)))
markerOverlay.Markers.Add(New Marker(-10772117.52067, 3864656.14956, New WebImage(21, 25, -10.5F, -25.0F)))
markerOverlay.Markers.Add(New Marker(-13164290.75755, 4035875.0929R, New WebImage(21, 25, -10.5F, -25.0F)))
markerOverlay.Markers.Add(New Marker(-9754587.80028, 5156136.17929, New WebImage(21, 25, -10.5F, -25.0F)))
tgMap.CustomOverlays.Add(markerOverlay)
Else
tgMap.CustomOverlays.Remove("MarkerOverlay")
End If
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim bRes As Boolean = My.Computer.Network.IsAvailable
If bRes Then
tgMap.MapBackground.BackgroundBrush = New GeoSolidBrush(GeoColor.FromHtml("#B3C6D4"))
tgMap.CurrentExtent = New RectangleShape(-13939426.6371, 6701997.4056, -7812401.86, 2626987.386962)
tgMap.MapUnit = GeographyUnit.Meter
'tgMap.MapTools.OverlaySwitcher.Enabled = True
tgMap.MapTools.MouseCoordinate.Enabled = True
Dim google As New GoogleOverlay("Google Map")
google.JavaScriptLibraryUri = New Uri(ConfigurationManager.AppSettings("GoogleUri"))
google.GoogleMapType = GoogleMapType.Normal
tgMap.CustomOverlays.Add(google)
End If
End Sub
Unable to refresh map with markers after adding them to map
Hi Bob,
I remember that post you mentioned which you can access at:
gis.thinkgeo.com/Support/Dis....aspx#4905
In that post, we have two samples in the attachment. One is use Update Panel (Default.aspx) while another one is the one you specified which we recommend not to use Update Panel (DefaultByJavaScript.aspx).
That’s a sample for the performance of refreshing the markers quickly. If you want to refresh the map using .NET Timer control, in another word, if you want to write refreshing map code on the server side not JavaScript, you can choose using the first sample which is less performance that the second sample but easy to implement.
Also you can implement using client scripts which will take you more performance. Here is another post which may give you more suggestions.
gis.thinkgeo.com/Support/Dis....aspx#8323
If you have any questions please let me know.
Thanks,
Howard
Thanks for the info Howard! I moved the map control out of the UpdatePanel now but, as I feared, it is now posting back every time I move the map around or when I zoom in and out. How can I prevent this? I have looked at code-behind as well as the properties of the map control and the form containing it, and also, web.config. Nothing stands out at me for preventing postback
Also, when I use google map instead of the base one in the example, the marker moves very little and the bounding box seems to have shrinked by orders of magnitude and is just off the coast of Aftica. Why is that? I would like to use google as the base map in my case. The current code I am using is below.
Thanks in advance for any insight!
Bob
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim bRes As Boolean = My.Computer.Network.IsAvailable
If Not IsPostback Then
If bRes Then
tgMap.MapBackground.BackgroundBrush = New GeoSolidBrush(GeoColor.FromHtml("#B3C6D4"))
tgMap.CurrentExtent = New RectangleShape(-132, 40, -76, 16.91)
tgMap.MapUnit = GeographyUnit.DecimalDegree
' tgMap.CurrentExtent = New RectangleShape(-13939426.6371, 6701997.4056, -7812401.86, 2626987.386962)
' tgMap.MapUnit = GeographyUnit.Meter
' tgMap.MapTools.OverlaySwitcher.Enabled = True
tgMap.MapTools.MouseCoordinate.Enabled = True
Dim google As New GoogleOverlay("Google Map")
google.JavaScriptLibraryUri = New Uri(ConfigurationManager.AppSettings("GoogleUri"))
google.GoogleMapType = GoogleMapType.Normal
tgMap.CustomOverlays.Add(google)
Dim markerOverlay As New InMemoryMarkerOverlay("MarkerOverlay")
markerOverlay.ZoomLevelSet.ZoomLevel01.DefaultMarkerStyle.WebImage = New WebImage("theme/default/img/marker_blue.gif", 21, 25)
markerOverlay.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20
markerOverlay.Features.Add("TrackMarker", New Feature(-123, 40))
tgMap.CustomOverlays.Add(markerOverlay)
End If
End If
End Sub
Function UpdateMapIcons() As Boolean
Dim markerOverlay As InMemoryMarkerOverlay = New InMemoryMarkerOverlay("MarkerOverlay")
markerOverlay.ZoomLevelSet.ZoomLevel01.DefaultMarkerStyle.WebImage = _
New WebImage("theme/default/img/marker_blue.gif", 21, 25, -10.5F, -25.0F)
markerOverlay.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20
markerOverlay.Features.Add("TrackMarker", New Feature(-80, 43.42))
markerOverlay.Features.Add("TrackMarker2", New Feature(-90, 43.42))
tgMap.CustomOverlays.Add(markerOverlay)
' tgMap.MapBackground.BackgroundBrush = New GeoSolidBrush(GeoColor.FromHtml("#B3C6D4"))
' tgMap.CurrentExtent = New RectangleShape(-131.22, 55.05, -54.03, 16.91)
' tgMap.MapUnit = GeographyUnit.DecimalDegree
' Dim worldLayer As New ShapeFileFeatureLayer(MapPath("~/SampleData/world/cntry02.shp"))
' worldLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.FromArgb(255, 243, 239, 228), GeoColor.FromArgb(255, 218, 193, 163), 1)
' worldLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20
End Function
Protected Sub Timer1_Tick(ByVal sender As Object, ByVal e As EventArgs)
UpdateTrackShape()
End Sub
Hi Bob,
First of all, I want to confirm what’s the version of web edition are you using? The following code helps you find the correct version of our product. Please let me know.String version = Map.Version;
I’m a little confused that how do you navigate your map? Is there some buttons for panning while some buttons for zooming? Map control supports client panning and zooming, so it won’t raise post back. Hope there is no misunderstanding.
Also, when you use GoogleOverlay, you need to set the map unit as GeographyUnit.Meter; and if the features which will be added into the MarkerOverlay are in DecimalDegree, you need to set the projection for the feature source of the marker overlay. Otherwise the markser will be added in to the map in decimal degree. That’s incorrect.
Here is an online sample for adding markers on GoogleMap.
websamples.thinkgeo.com/webe...rkers.aspx
This is all I found in your code; if possible, please send us your quick sample and provide us more information. If your code is not public, please send to support@thinkgeo.com and ask to forward to me.
If you have any queries please let me know.
Thanks,
Howard
Hi Howard,
The version string reports as follows:
"MapSuiteCore:3.1.16;WebEdition:3.1.16"
Now, I have done a little digging this morning and found that if I add a map to a brand new page,
it does NOT postback at all when simply moving the map around or zooming/unzooming in. I also
added a brand new map object to my original default.aspx page and it also does not postback
when moving or zooming the map. Only the one where I have the moving marker. If this doesn't
give you enough then I will have to send the code to you over the support email. I've looked all over
for any postback specific settings and just cannot figure out why it is posting back. Given the evidence,
it appears to be something to do with the tgMap object specifically since the other map did not
exhibit this behaviour. Just for reference, I have also tried replacing the tgMap control by deleting both
it and the associated scriptmanager control and then re-adding it. It still postsback if I give it the
name "tgMap". Any ideas?
Bob
Also, just a note for all of you, that I have noticed some oddities when re-compiling that sometimes the built-in page server in .NET seems to be pulling cached copies of previous versions of pages and serving those instead of the current compiled version! I find that sometimes I have to delete all cookies and temp files in IE every once in awhile for the new compiled page to be served.
Bob,
The version you are using is a little old. Currently, our public release is 3.1.182. It fixed many bugs and added some new features. Please download the latest version and see if the issue still exists.
Also, in the sample, we have an UpdatePanel containing the timer; please see if this is the difference.
Looking forward your code.
Thanks,
Howard
I will try the update but have my doubts it will fix it due to the various results of the tests I’ve outlined above. The only thing that I can see that is different between a normal page and the one I am using is the fact that my page references the ajaxcontroltoolkit as I have some extenders applied to various controls on the form. I will send the code shortly.
Tx again!
Bob
Oh! forgot to mention too in my last reply that the timer is in an updatepanel and updates without a postback. It is just when I physically move things around on tgMap where I experience the postback.
Bob,
I guess this may caused by some JavaScript issue which raises the postback event by mistake. I’ll check it when I get your code. Also, you can upgrade the application to our latest version.
Any questions please let me know.
Thanks,
Howard
Bob,
I found something in your code. Please see the code which I copied from your solution:Protected Sub tgMap_ExtentChanged(ByVal sender As Object, ByVal e As ThinkGeo.MapSuite.WebEdition.ExtentChangedEventArgs) Handles tgMap.ExtentChanged
'Stop
Dim Cent As PointShape
Cent = tgMap.CurrentExtent.GetCenterPoint()
Session("X") = Cent.X
Session("Y") = Cent.Y
Dim dZoom As Double = GetZoomLevel(tgMap)
End Sub
This code hook an event handler to map's ExtentChanged event. It's a server event in our product which rises whenever extent changed; in your app, when you zooming and panning, it causes the extent changes so that it posts back and rises the tgMap_ExtentChanged event; it will be fine if you delete this event. Also you can use our client API to get the center x and y instead.
If you have any questions please let me know.
Thanks,
Howard
Thanks Howard! That did it! Wow. I should have seen that one! Anyway, are there any examples out there you could point me to on how to use the APIs? The API docs strictly have the definitions of all the API's. I was keeping track of the current extent of the map before because, after clicking save on a setup form I have, it would postback (as it should) and proceed to change the map extent back to its startup default. It doesn't seem to do that now however.
Tx a million!
Bob
Oh! I also forgot to ask:
You mentioned that with google maps, I have to convert use meters for the coordinate system. Are there examples of how I can convert coordinates to meters?
Also, how specify a different image for every unit I want to display on the map like simplemarker object does with the code above (instead of applying a default icon to every unit)?
Just for completeness sake, there was a post at the top of the web forums showing examples of how to use the API here:
gis.thinkgeo.com/Support/Dis...fault.aspx
I also found a code example for populating a google map that included conversion of the lat & lon output by most GPS' to meters.
This example does that here:
gis.thinkgeo.com/Support/DiscussionForums/tabid/143/aff/12/aft/5456/afv/topic/Default.aspx
I am still looking for a way to change the markers for each marker I may decide to plot on a map (users can select what
units display which icon and they have hundreds to choose from). But will post the code once I've found it or someone
posts it here.
Thanks again for all the help Howard!! You really helped me out!!
Cheers,
Bob
Bob,
You are welcome.
First of all, the API you posted is our client APIs. As you know, our Web Edition is a normal web control which cans easily config by the server code. Normally, people like this way and if they use UpdatePanel with our control, it’ll be synchronize update.
But some advanced user like you doesn’t like post back; they get rid of using UpdatePanel and use JavaScript or call back technolege instead to gain higher performance. Our control accepts this way too.
In web edition, we wrap OpenLayers library and our client APIs are some easy ways to find the OpenLayers object we are using. In another word, you can choose using our APIs or using OpenLayers APIs directly.
In our forum, there are a lot of existing sample using Client APIs but we don’t have any regular article for it. Sorry for the inconvenience. Please let me know if you have any queries about it.
For the projection issue. You can find an online sample at:
websamples.thinkgeo.com/webeditionsamples/
The sample you need is under Samples/Markers/Add Projected Markers which you can check the source code.
See these lines of code which automatically projects the shapes from decimal degree to meters. If it’s null, it doesn’t project at all but keep its original shapes in decimal degree.Proj4Projection proj4 = new Proj4Projection();
proj4.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326);
proj4.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString();
markerOverlay.FeatureSource.Projection = proj4;
Hope it helps. Please let me know if you have more questions.
Thanks,
Howard