c# - change the location of zoom buttons (+-) in Xamarin.Forms.Maps -
i want change location of zoom button controls (+)(-)
on map
in xamarin.forms
. possible?
after research, think there no method relocate default zoom control of google map, said, can use custom renderer create own map control, can customize zoom control, example:
<grid> <controls:mapwithmyzoomcontrol x:name="map" horizontaloptions="fillandexpand" verticaloptions="fillandexpand" /> <stacklayout orientation="vertical"> <button text="zoom in" clicked="zoom_in" /> <button text="zoom out" clicked="zoom_out" /> </stacklayout> </grid>
mapwithmyzoomcontrol :
public class mapwithmyzoomcontrol : map { public zoomstate myzoom { { return (zoomstate)getvalue(myzoomproperty); } set { setvalue(myzoomproperty, value); } } public static readonly bindableproperty myzoomproperty = bindableproperty.create( propertyname: "myzoom", returntype: typeof(zoomstate), declaringtype: typeof(mapwithmyzoomcontrol), defaultvalue: zoomstate.normal, propertychanged: onzoompropertychanged); public static void onzoompropertychanged(bindableobject bindable, object oldvalue, object newvalue) { } public enum zoomstate { normal, zoomin, zoomout } }
renderer:
public class mapwithmyzoomcontrolrenderer : maprenderer, ionmapreadycallback { private googlemap map; public void onmapready(googlemap googlemap) { map = googlemap; map.uisettings.zoomcontrolsenabled = false; } protected override void onelementchanged(elementchangedeventargs<map> e) { base.onelementchanged(e); if (e.oldelement != null) { // unsubscribe } if (e.newelement != null) { var formsmap = (mapwithmyzoomcontrol)e.newelement; ((mapview)control).getmapasync(this); } } protected override void onelementpropertychanged(object sender, propertychangedeventargs e) { base.onelementpropertychanged(sender, e); var element = element mapwithmyzoomcontrol; if (e.propertyname == "myzoom" && map != null) { if (element.myzoom == mapwithmyzoomcontrol.zoomstate.zoomin) { map.animatecamera(cameraupdatefactory.zoomin()); } else if (element.myzoom == mapwithmyzoomcontrol.zoomstate.zoomout) { map.animatecamera(cameraupdatefactory.zoomout()); } element.myzoom = mapwithmyzoomcontrol.zoomstate.normal; } } }
don't forget add assembly in renderer this:
[assembly: exportrenderer(typeof(mapwithmyzoomcontrol), typeof(mapwithmyzoomcontrolrenderer))]
now can change button styles , locations.
Comments
Post a Comment