How to use onMarkerRollOver for polygons
Does anyone know how to add an onMarkerRollOver for polygons? I've added polygons from a postGIS database but can't seem to catch when the mouse is over the polygon. I'll paste the code below in case anyone has ideas.
Thanks
private function placePolygons(_dbArray:Array):void {
var o:Object;
var p:Object;
var extLocations:Array = new Array;
//add children for polygon marker
polygonClip=new PolygonClip(map);
polygonClip.addEventListener(MarkerEvent.MARKER_ROLL_OVER, onMarkerRollOver);
polygonClip.addEventListener(MarkerEvent.MARKER_ROLL_OUT, onMarkerRollOut);
map.addChild(polygonClip);
//loop through the dataset and place the polygons
for each (o in _dbArray) {
var locations:Array = new Array;
var geomString:String=o.astext;
var pattern1:RegExp= /MULTIPOLYGON\(\(\(/g;
var pattern2:RegExp=/\)\)\)/g;
if (o.astext != null) {
geomString=geomString.replace(pattern1,"");
geomString=geomString.replace(pattern2,"");
var coords:Array=geomString.split(",");
for each (p in coords) {
var str:String = p.toString();
var parts:Array = str.split(/\s* \s*/, 2);
parts=parts.reverse();
locations.push(new Location(parseFloat(parts[0]),parseFloat(parts[1])));
extLocations.push(new Location(parseFloat(parts[0]),parseFloat(parts[1])));
}
var polygon:PolygonMarker=new PolygonMarker(map,locations,false);
polygon.fillAlpha=.7;
polygonClip.attachMarker(polygon,polygon.location);
}
}
map.setExtent(MapExtent.fromLocations(extLocations));
}
Thanks
private function placePolygons(_dbArray:Array):void {
var o:Object;
var p:Object;
var extLocations:Array = new Array;
//add children for polygon marker
polygonClip=new PolygonClip(map);
polygonClip.addEventListener(MarkerEvent.MARKER_ROLL_OVER, onMarkerRollOver);
polygonClip.addEventListener(MarkerEvent.MARKER_ROLL_OUT, onMarkerRollOut);
map.addChild(polygonClip);
//loop through the dataset and place the polygons
for each (o in _dbArray) {
var locations:Array = new Array;
var geomString:String=o.astext;
var pattern1:RegExp= /MULTIPOLYGON\(\(\(/g;
var pattern2:RegExp=/\)\)\)/g;
if (o.astext != null) {
geomString=geomString.replace(pattern1,"");
geomString=geomString.replace(pattern2,"");
var coords:Array=geomString.split(",");
for each (p in coords) {
var str:String = p.toString();
var parts:Array = str.split(/\s* \s*/, 2);
parts=parts.reverse();
locations.push(new Location(parseFloat(parts[0]),parseFloat(parts[1])));
extLocations.push(new Location(parseFloat(parts[0]),parseFloat(parts[1])));
}
var polygon:PolygonMarker=new PolygonMarker(map,locations,false);
polygon.fillAlpha=.7;
polygonClip.attachMarker(polygon,polygon.location);
}
}
map.setExtent(MapExtent.fromLocations(extLocations));
}
1
person has this question
I have this question, too!
Tell me when someone answers.
The more people who ask this question, the more it gets noticed.
The more people who ask this question, the more it gets noticed.
Create a customer community for your own organization
Plans starting at $19/month
-
Inappropriate?PolygonMarker has mouseEnabled=false by default, so the MarkerEvents won't fire.
However, if you set mouseEnabled to true for the PolygonMarkers, and add the PolygonClip as a child of Map, then you won't be able to drag the map around through the polygons.
This is because the dragging listeners are added to the TileGrid, so the solution to your problem is to set mouseEnabled to true on your PolygonMarkers and add the PolygonClip as a child of map.grid instead of map.
Hope that makes sense! -
Inappropriate?Thanks again! That worked. I'll paste the working code below.
private function placePolygons(_dbArray:Array):void {
var o:Object;
var p:Object;
var extLocations:Array = new Array;
//add children for polygon marker
polygonClip=new PolygonClip(map);
polygonClip.addEventListener(MarkerEvent.MARKER_ROLL_OVER, onMarkerRollOver);
polygonClip.addEventListener(MarkerEvent.MARKER_ROLL_OUT, onMarkerRollOut);
map.grid.addChild(polygonClip);
//loop through the dataset and place the polygons
for each (o in _dbArray) {
var locations:Array = new Array;
var geomString:String=o.astext;
var pattern1:RegExp= /MULTIPOLYGON\(\(\(/g;
var pattern2:RegExp=/\)\)\)/g;
if (o.astext != null) {
geomString=geomString.replace(pattern1,"");
geomString=geomString.replace(pattern2,"");
var coords:Array=geomString.split(",");
for each (p in coords) {
var str:String = p.toString();
var parts:Array = str.split(/\s* \s*/, 2);
parts=parts.reverse();
locations.push(new Location(parseFloat(parts[0]),parseFloat(parts[1])));
extLocations.push(new Location(parseFloat(parts[0]),parseFloat(parts[1])));
}
var polygon:PolygonMarker=new PolygonMarker(map,locations,false);
polygon.fillAlpha=.7;
polygon.mouseEnabled=true;
polygonClip.attachMarker(polygon,polygon.location);
}
}
map.setExtent(MapExtent.fromLocations(extLocations));
}
Loading Profile...



EMPLOYEE