leaflet call onclick javascript from ASP.NEt codebehind

311 views
Skip to first unread message

fifamaniac04

unread,
Sep 24, 2013, 3:03:11 PM9/24/13
to leafl...@googlegroups.com

I have a leaflet map that puts a marker where the mouse clicks:

javascript:

map.on('click', onMapClick); // event fired when user clicks the mouse
function onMapClick(e)
{
    L.marker(e.latlng, { icon: myIcon }).addTo(map);
}

I want to select from a radiobutton list the number of markers to add at specified locations;

codebehind:

Point docMapCoordinate = new Point(90, 187);
string Script = String.Format("onMapClick('{0}');", docMapCoordinate.ToString());
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "click", Script, true);

Part of my problem too is the Point to latlng for the leaflet mouse click event, but I've also tried to get a simply alert up like this:

this.Page.ClientScript.RegisterStartupScript(this.GetType(), "click", "alert('Does this work?');", true); 

What is wrong in my attempt to call RegisterStartupScript with Script and any hints on the Point to LatLng conversion?

Diego Guidi

unread,
Sep 25, 2013, 2:47:56 AM9/25/13
to leafl...@googlegroups.com
On Tue, Sep 24, 2013 at 9:03 PM, fifamaniac04 <fifama...@yahoo.com> wrote:
> What is wrong in my attempt to call RegisterStartupScript with Script
try with this:
http://stackoverflow.com/questions/16484978/clientscript-registerstartupscript-not-working

>and any hints on the Point to LatLng conversion?
Point should match the clientside api, so actually you need to pass an
"Event" object with a property named "latlng"... so a code like this:

string Script = String.Format("onMapClick('{0}');",
JsonSerializer.Serialize(new {
latlng: {
lat: XX,
lng: YY
}
})
);



Diego Guidi
Reply all
Reply to author
Forward
0 new messages