[fusion-dev] Creating Vector Points on the Map from Task Pane
Nolte, Tim
Tim.Nolte at ipcswirelessinc.com
Mon Nov 30 08:27:44 EST 2009
OK, well after a bunch of trial-and-error I finally got this working.
The key was a small error:
vectorLayer.addFeatures([pointFeature]);
should have been:
vectorLayer.addFeatures(pointFeature);
Nothing like such a small item causing a bunch of headache. Maybe this
will help someone else.
- Tim
----
Timothy J Nolte - tnolte at ilpcs.com
Network Planning Engineer
iPCS Wireless, Inc.
4717 Broadmoor Ave, Suite G
Kentwood, MI 49512
Office: 616-656-5163
PCS: 616-706-2438
Fax: 616-554-6484
Web: www.ipcswirelessinc.com
-----Original Message-----
From: fusion-dev-bounces at lists.osgeo.org
[mailto:fusion-dev-bounces at lists.osgeo.org] On Behalf Of Nolte, Tim
Sent: Saturday, November 21, 2009 12:30 AM
To: fusion-dev at lists.osgeo.org
Subject: [fusion-dev] Creating Vector Points on the Map from Task Pane
OK Guys,
So I've been banging my head against the wall trying to figure out how
to get a geocoded point to display as a vector star on the map. I've got
things working to the point of getting my lat/long and zooming the map
to the extents that the point falls in. The part that I just can't seem
to get working, no matter what combination I try, is taking my lat/long
and sticking a point(star) on the map. I'm including my code so you can
see where I'm at. You'll notice that in some cases I've got some
hard-coded items, this is just due to my custom widget not really being
general purpose anyways. Any tips here would be hugely appreciated.
Thanks!
function GetParent() {
if (parent.Fusion) {
return parent;
} else if (parent.parent.Fusion) {
return parent.parent;
}
return null;
}
function getMapAddress() {
return
GetParent().Fusion.applicationDefinition.widgetSets[0].widgetTagsByName.
menuMapAddress;
}
function createPoint(nLat, nLon, sLabel) {
var OpenLayers = GetParent().OpenLayers;
var mapWidget = getMapAddress().getMapWidget();
var json = getMapAddress().extension;
// calculate & zoom to new extents
var ur = new Object;
var ll = new Object;
ur.x = nLon;
ll.x = nLon;
ur.y = nLat;
ll.y = nLat;
// create one default layer, unless other widgets have created
it
var vectorLayer = mapWidget.oMapOL.getLayersByName('Geocoded
Points');
var mapServerLayer =
mapWidget.oMapOL.getLayersByName('ipcs_cell_sites');
if (vectorLayer) { mapWidget.oMapOL.removeLayer(vectorLayer,
false); }
vectorLayer = new OpenLayers.Layer.Vector('Geocoded Points', {
styleMap: new OpenLayers.StyleMap({'default':{
strokeColor: "#00FF00",
strokeOpacity: 1,
strokeWidth: 3,
fillColor: "#000000",
fillOpacity: 0.5,
pointRadius: 6,
pointerEvents: "visiblePainted",
label : "${label}",
fontColor: "#000000",
fontSize: "7px",
fontFamily: "Arial",
fontWeight: "bold",
labelAlign: "rt",
labelXOffset: "${xOffset}",
labelYOffset: "${yOffset}"
}})
});
// create a point feature
var point = new OpenLayers.Geometry.Point(nLon, nLat);
var pointFeature = new OpenLayers.Feature.Vector(point);
pointFeature.attributes = {
label: sLabel,
// positive value moves the label to the right
xOffset: 50,
// negative value moves the label down
yOffset: 0
};
mapWidget.oMapOL.addLayer(vectorLayer);
vectorLayer.maxScale = mapServerLayer.maxScale;
vectorLayer.numZoomLevels = mapServerLayer.numZoomLevels;
vectorLayer.addFeatures([pointFeature]);
var zoomFactor = json.Factor ? json.Factor[0] : 2;
var margin = .0125;
var zoom_size = zoomFactor * margin / 2;
//var zoom_size = zoomFactor * Math.max( Math.abs(ur.x - ll.x),
Math.abs(ur.y - ll.y)) / 2;
var cX = (ur.x + ll.x)/2;
var cY = (ur.y + ll.y)/2;
ll.x = cX - zoom_size;
ur.x = cX + zoom_size;
ll.y = cY - zoom_size;
ur.y = cY + zoom_size;
mapWidget.oMapOL.zoomToExtent(new
OpenLayers.Bounds(ll.x,ll.y,ur.x,ur.y));
mapWidget._oCurrentExtents = mapWidget.oMapOL.getExtent();
}
----
Timothy J Nolte - tnolte at ilpcs.com
Network Planning Engineer
iPCS Wireless, Inc.
4717 Broadmoor Ave, Suite G
Kentwood, MI 49512
Office: 616-656-5163
PCS: 616-706-2438
Fax: 616-554-6484
Web: www.ipcswirelessinc.com
_______________________________________________
fusion-dev mailing list
fusion-dev at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/fusion-dev
More information about the fusion-dev
mailing list