I'm working on a widget based framework and the map control inside a widget will have different client id each time it is instantiated. How can I retrieve the client id (aside from saving it in a hidden field and getting that value via javascript)?
I'm working on a widget based framework and the map control inside a widget will have different client id each time it is instantiated. How can I retrieve the client id (aside from saving it in a hidden field and getting that value via javascript)?
Hi Allan,
The map’s clientId can be got via the code as following on the client:
Var mapclientId = ‘<%=this.Map1.ClientID%>’
Or we can get it via the Mapparser. Please check the client APIs at gis.thinkgeo.com/Support/Dis...aspx#22023
Thanks,
Johnny
Hi Johnny,
I'm running an external JS file so ‘<%=this.Map1.ClientID%>’ won't work for me. What I want to do is create a marker client side from an external JS file.
And if say I got the map client id, what am I doing wrong on the code below? I'm trying this within the page for now.
var OnMapCreated = function(map) {
var markers = new OpenLayers.Layer.Markers("Markers");
map.addLayer(markers);
}
var CreateMarker = function(id, lat, lng) {
var size = new OpenLayers.Size(32, 32);
var offset = new OpenLayers.Pixel(-(size.w / 2), -size.h);
var icon = new OpenLayers.Icon('/mover.gif', size, offset);
var mapClientID = '<%= this.Map1.ClientID %>';
var map = mapClientID.GetOpenLayersMap();
var markers = map.getLayersByName('Markers')[0];
markers.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat(lat, lng), icon));
}
I get an 'Object doesn't support this property error' on the highlighted line.
Oh and if I place this in an external JS, OnMapCreated doesn't get called.
Hi Allan,
Can let us know what’s the clientID you got? Can you try the attached sample which has the map in a UserControl, I think it’s similar to your scenario. Please check if there is any difference with yours.
Thanks,
Johnny
MultipleMapsSample.zip (8.79 KB)
Hi Johnny,
After reading and trying the posts on other threads, I was able to do my objective of placing a marker client side.
My question now is it possible to place all the script on an external JS? I tried and OnMapCreated didnt get fired. And for sure <%= this.Map1.ClientID %>’ wont work coz its only parsed in the .aspx/.ascx page.
Also, I am trying to plot the marker at this position > lat: 1.33246 lng:103.89636. I was using Google Map API before and it works fine (should show in Singapore area) but in Map Suite it is displayed in the sea (position 0,0 if I’m not mistaken).
Thanks!
below is the code:
var webmap, markers;
var OnMapCreated = function(map) {
markers = new OpenLayers.Layer.Markers(“MarkerOverlay”);
markers.id = “MarkerOverlay”;
map.addLayer(markers);
webmap = map;
}
var CreateMarker = function(id) {
var size = new OpenLayers.Size(32, 32);
var offset = new OpenLayers.Pixel(-(size.w / 2), -size.h);
var icon = new OpenLayers.Icon(’/primemover.gif’, size, offset);
marker = new OpenLayers.Marker(new OpenLayers.LonLat(1.33246, 103.89636), icon);
markers.addMarker(marker);
}
It seems like I need to convert the projection to match Google Map. I saw some server side codes but can I do it client side?
Hi Allan,
I agree with you that the problem is related to projection. We need to convert the coordinates to Projection “EPSG: 900913” from “EPSG: 4326”. I think the client code as following is helpful to you:
var googleProjection = new OpenLayers.Projection("EPSG:900913");
var normalProjection = new OpenLayers.Projection("EPSG:4326");
// The point converted
var point = new OpenLayers.Geometry.Point(10, 36);
//OpenLayers.Projection.transform = function( point, sourceProjection, destProjection )
var projectedPoint = OpenLayers.Projection.transform(point, normalProjection, googleProjection);
Thanks,
Johnny
Thanks Johnny. Can you answer my other question which is if I can move all the scripts to an external JS file?
Hi Allan,
Sorry for the missing. In Asp.net page, it’s easy to get the client id via “<%= control.ClientID%>, but Microsoft Asp.net control doesn’t allow us to generate the clientID in external JS file. To get around it, two steps can help us:
1. Include the script for GetClientID function in the .aspx page.
2. Access the ClientID in external JS file from the GetClientID function which is included in the aspx page.
Thanks,
Johnny