Commit bb11f108 authored by Matt Strum's avatar Matt Strum
Browse files

Node group clusters are working better

parent ee55db43
<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"
width="140" height="150"
horizontalAlign="center" verticalGap="0">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import com.google.maps.Map;
import com.google.maps.LatLngBounds;
import com.google.maps.LatLng;
import com.google.maps.services.Placemark;
import com.google.maps.services.ClientGeocoder;
import com.google.maps.services.GeocodingEvent;
import mx.collections.ArrayCollection;
import mx.controls.Button;
public function Load(cluster:ArrayCollection):void
{
for each(var ng:NodeGroup in cluster)
addNodeGroup(ng);
}
public function addNodeGroup(ng:NodeGroup):void {
var ngButton:Button = new Button();
ngButton.percentWidth = 100;
ngButton.label = ng.collection.length.toString() + " Nodes";
ngButton.addEventListener(MouseEvent.CLICK,
function openNodeGroup(evt:Event):void
{
if(ng.collection.length > 1)
Common.viewNodeGroup(ng);
else
Common.viewNode(ng.collection[0]);
});
if(ng.city.length == 0)
{
var geocoder:ClientGeocoder = new ClientGeocoder();
geocoder.addEventListener(GeocodingEvent.GEOCODING_SUCCESS,
function(event:GeocodingEvent):void {
var placemarks:Array = event.response.placemarks;
var city:String = "";
if (placemarks.length > 0) {
try {
var p:Placemark = event.response.placemarks[0] as Placemark;
var fullAddress : String = p.address;
var splitAddress : Array = fullAddress.split(',');
if(splitAddress.length == 3)
city = splitAddress[0];
else
if(splitAddress.length == 4)
city = splitAddress[1];
else
city = fullAddress;
ng.city = city;
ngButton.label = city;
} catch (err:Error) { }
}
});
geocoder.addEventListener(GeocodingEvent.GEOCODING_FAILURE,
function(event:GeocodingEvent):void {
//main.console.appendText("Geocoding failed!\n");
});
geocoder.reverseGeocode(new LatLng(ng.latitude, ng.longitude));
} else {
ngButton.label = ng.city;
}
nodeGroupButtonsVbox.addChild(ngButton);
}
public function setZoomButton(bounds:LatLngBounds):void {
if(zoomButton == null)
{
Alert.show("ERR");
return;
}
zoomButton.addEventListener(MouseEvent.CLICK,
function zoomin(evt:MouseEvent):void {
var map : Map = Common.Main().map;
var bzl : Number = map.getBoundsZoomLevel(bounds);
if(map.getZoom() != bzl)
map.setZoom(bzl);
map.panTo( bounds.getCenter() );
});
}
]]>
</mx:Script>
<mx:Label text="Label"/>
<mx:VBox width="90%" height="100%" id="nodeGroupButtonsVbox">
</mx:VBox>
<mx:Button label="Zoom" id="zoomButton"/>
</mx:VBox>
......@@ -2,11 +2,10 @@ package pgmap
{
import com.google.maps.InfoWindowOptions;
import com.google.maps.LatLng;
import com.google.maps.LatLngBounds;
import com.google.maps.MapMouseEvent;
import com.google.maps.overlays.Marker;
import com.google.maps.overlays.MarkerOptions;
import com.google.maps.overlays.Polygon;
import com.google.maps.overlays.PolygonOptions;
import com.google.maps.overlays.Polyline;
import com.google.maps.overlays.PolylineOptions;
import com.google.maps.services.ClientGeocoder;
......@@ -21,12 +20,15 @@ package pgmap
import flash.geom.Point;
import mx.collections.ArrayCollection;
import mx.events.FlexEvent;
import mx.managers.PopUpManager;
public class ProtoGeniMapHandler
{
public var main : pgmap;
public function ProtoGeniMapHandler()
{
}
......@@ -69,34 +71,41 @@ package pgmap
var groupInfo:NodeGroupInfo = new NodeGroupInfo();
groupInfo.Load(drawGroup, main);
var geocoder:ClientGeocoder = new ClientGeocoder();
geocoder.addEventListener(GeocodingEvent.GEOCODING_SUCCESS,
function(event:GeocodingEvent):void {
var placemarks:Array = event.response.placemarks;
if (placemarks.length > 0) {
try {
var p:Placemark = event.response.placemarks[0] as Placemark;
var fullAddress : String = p.address;
var splitAddress : Array = fullAddress.split(',');
if(splitAddress.length == 3)
groupInfo.city = splitAddress[0];
else
if(splitAddress.length == 4)
groupInfo.city = splitAddress[1];
else
drawGroup.city = fullAddress;
} catch (err:Error) { }
}
});
geocoder.addEventListener(GeocodingEvent.GEOCODING_FAILURE,
function(event:GeocodingEvent):void {
main.console.appendText("Geocoding failed!\n");
});
geocoder.reverseGeocode(new LatLng(g.latitude, g.longitude));
if(drawGroup.city.length == 0)
{
var geocoder:ClientGeocoder = new ClientGeocoder();
geocoder.addEventListener(GeocodingEvent.GEOCODING_SUCCESS,
function(event:GeocodingEvent):void {
var placemarks:Array = event.response.placemarks;
if (placemarks.length > 0) {
try {
var p:Placemark = event.response.placemarks[0] as Placemark;
var fullAddress : String = p.address;
var splitAddress : Array = fullAddress.split(',');
if(splitAddress.length == 3)
groupInfo.city = splitAddress[0];
else
if(splitAddress.length == 4)
groupInfo.city = splitAddress[1];
else
groupInfo.city = fullAddress;
drawGroup.city = groupInfo.city;
} catch (err:Error) { }
}
});
geocoder.addEventListener(GeocodingEvent.GEOCODING_FAILURE,
function(event:GeocodingEvent):void {
main.console.appendText("******************\n");
main.console.appendText("Geocoding failed!\n");
main.console.appendText(event.status + "\n"); // 500
main.console.appendText(event.eventPhase + "\n"); //2
});
geocoder.reverseGeocode(new LatLng(g.latitude, g.longitude));
} else {
groupInfo.city = drawGroup.city;
}
m.addEventListener(MapMouseEvent.CLICK, function(e:Event):void {
m.openInfoWindow(
new InfoWindowOptions({
......@@ -128,11 +137,14 @@ package pgmap
private function addNodeGroupCluster(nodeGroups:ArrayCollection):void {
var totalNodes:Number = 0;
var l:LatLngBounds = new LatLngBounds();
var upperLat:Number = nodeGroups[0].nodeGroup.latitude;
var lowerLat:Number = nodeGroups[0].nodeGroup.latitude;
var rightLong:Number = nodeGroups[0].nodeGroup.longitude;
var leftLong:Number = nodeGroups[0].nodeGroup.longitude;
var nodeGroupsOnly:ArrayCollection = new ArrayCollection();
for each(var o:Object in nodeGroups) {
// Check to see if the new group expends the cluster size
if(o.nodeGroup.latitude > upperLat)
upperLat = o.nodeGroup.latitude;
else if(o.nodeGroup.latitude < lowerLat)
......@@ -143,38 +155,41 @@ package pgmap
leftLong = o.nodeGroup.longitude;
totalNodes += o.nodeGroup.collection.length;
nodeGroupsOnly.addItem(o.nodeGroup);
o.marker.visible = false;
}
var polygon:Polygon = new Polygon([
new LatLng(upperLat, leftLong),
new LatLng(upperLat, rightLong),
new LatLng(lowerLat, rightLong),
new LatLng(lowerLat, leftLong),
new LatLng(upperLat, leftLong)
],
new PolygonOptions({
strokeStyle: new StrokeStyle({
color: 0x0000ff,
thickness: 2,
alpha: 0.5}),
fillStyle: new FillStyle({
color: 0x0000ff,
alpha: 0.5})
}));
main.map.addOverlay(polygon);
// Save the bounds of the cluster
var bounds:LatLngBounds = new LatLngBounds(new LatLng(upperLat, leftLong), new LatLng(lowerLat, rightLong));
var clusterInfo:NodeGroupClusterInfo = new NodeGroupClusterInfo();
clusterInfo.addEventListener(FlexEvent.CREATION_COMPLETE,
function loadNodeGroup(evt:FlexEvent):void {
clusterInfo.Load(nodeGroupsOnly);
clusterInfo.setZoomButton(bounds);
});
var m:Marker = new Marker(
new LatLng((upperLat + lowerLat)/2, (rightLong + leftLong)/2),
bounds.getCenter(),
new MarkerOptions({
strokeStyle: new StrokeStyle({color: 0x092791}),
fillStyle: new FillStyle({color: 0xa0c8f1, alpha: 1}),
radius: 14,
hasShadow: true,
//tooltip: g.country,
label: totalNodes.toString()
icon:new iconLabelSprite(totalNodes.toString()),
iconAllignment:MarkerOptions.ALIGN_RIGHT,
iconOffset:new Point(-2, -2),
hasShadow: true
}));
m.addEventListener(MapMouseEvent.CLICK, function(e:Event):void {
m.openInfoWindow(
new InfoWindowOptions({
customContent:clusterInfo,
customoffset: new Point(0, 10),
width:150,
height:150,
drawDefaultFrame:true
}));
});
main.map.addOverlay(m);
}
......
package pgmap {
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
/**
* InfoWindowSprite is a sprite that contains sub sprites that function as tabs.
*/
public class iconLabelSprite extends Sprite {
[Embed('../../images/cloud.png')] private var CloudImg:Class;
public function iconLabelSprite(label:String) {
addChild(new CloudImg());
var radius:int = 60;
var labelMc:TextField = new TextField();
labelMc.autoSize = TextFieldAutoSize.LEFT;
labelMc.selectable = false;
labelMc.border = false;
labelMc.embedFonts = false;
labelMc.mouseEnabled = false;
labelMc.width = radius;
labelMc.height = radius;
labelMc.text = label;
labelMc.y = 8;
if(label.length == 1)
labelMc.x = 15;
else if(label.length == 2)
labelMc.x = 13;
else
labelMc.x = 11;
addChild(labelMc);
cacheAsBitmap = true;
buttonMode=true;
useHandCursor = true;
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment