Override the start method to access OSGi services
Create your logic
Create your user interface (UI)
View a live sample.
Step 1: Override the start method to access OSGi services
To enable your widget to interact with the map, you need to override the Start method of the Widget Base and create an instance of the Service Tracker which will allow you to directly access the OSGi services. package com.esri.aws.awx.widget
{
public class MyZoomBaseWidget extends BaseWidget
{
import com.esri.aws.awx.map.IMap;
import com.esri.aws.osgi.framework.IBundleContext;
import com.esri.aws.osgi.framework.ServiceTracker;
import flash.utils.getQualifiedClassName;
// instance of service tracker
private var theTracker:ServiceTracker;
// Override the start() method
override public function start(context:IBundleContext):void
{
super.start(context);
theTracker = new ServiceTracker(context, getQualifiedClassName(IMap));
theTracker.open();
}
override public function createWidgetView(widgetState:String = null):IWidgetView
{
var theCustomView:MyZoomWidgetView = new MyZoomWidgetView();
theCustomView.widget = this;
theCustomView.widgetState = widgetState;
return theCustomView;
}
}
}
Step 2: Create your logic
Add a function in widget base that “does something”, for example: public function onZoom(value:Number):void
{
var map:IMap = IMap(theTracker.getService());
if(map)
{
map.scale *= value;
}
}
Step 3: Create your UI
Create your user interface.
Add a Map to your main MXML file:
Add the UI:
No comments:
Post a Comment