Skip to content

Commit

Permalink
create pre-set circle annotations from certain trigger zones
Browse files Browse the repository at this point in the history
If a trigger zone in the mission is named "MPMAP_BLUE <label>",
"MPMAP_RED <label>" or "MPMAP_BOTH <label>" it will be shown on
the mission planner map to the respective coalition(s).
  • Loading branch information
jboecker committed Mar 12, 2014
1 parent e22e0a7 commit 0c05bfa
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 7 deletions.
42 changes: 41 additions & 1 deletion admintool.html
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,47 @@ <h2 class="filename-h2"></h2>
}
data.objects[ann.id] = ann
end


-- add pre-set circle annotations
if (mission.triggers and mission.triggers.zones) then
for _, zone in pairs(mission.triggers.zones) do
if zone.x and zone.y and zone.radius and zone.name then
local show_zone = false
local zone_vis = nil
local zone_text = nil
if zone.name:match("MPMAP_RED") then
show_zone = true
zone_vis = "red"
zone_text = zone.name:sub(11)
end
if zone.name:match("MPMAP_BLUE") then
show_zone = true
zone_vis = "blue"
zone_text = zone.name:sub(12)
end
if zone.name:match("MPMAP_BOTH") then
show_zone = true
zone_vis = nil
zone_text = zone.name:sub(12)
end

if show_zone then
local ann = {
id = new_id(),
type = "PRESET_ZONE_ANNOTATION",
visibility = zone_vis,
label = zone_text,
radius = zone.radius,
x = zone.x,
z = zone.y
}
data.objects[ann.id] = ann
end
end
end
end

-- add bullseye markers
for _, coa in pairs({"blue", "red"}) do
local bullseye = {
id = new_id(),
Expand Down
48 changes: 42 additions & 6 deletions js/planner_ng-mapview.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
mp = mp || {};

LAYER_ID_AIRPORTS = 0;
LAYER_ID_UNITS = 1;
LAYER_ID_ANNOTATIONS = 2;
LAYER_ID_INACTIVE_ROUTES = 3;
LAYER_ID_ACTIVE_ROUTE_SEGMENTS = 4;
LAYER_ID_ACTIVE_WAYPOINTS = 5;
LAYER_ID_PRESET_ANNOTATIONS = 1;
LAYER_ID_UNITS = 2;
LAYER_ID_ANNOTATIONS = 3;
LAYER_ID_INACTIVE_ROUTES = 4;
LAYER_ID_ACTIVE_ROUTE_SEGMENTS = 5;
LAYER_ID_ACTIVE_WAYPOINTS = 6;

LAYER_ID_MAX = 5;

Expand Down Expand Up @@ -80,7 +81,23 @@ mp.MapView = function(map_type) {
styleMap: new OpenLayers.StyleMap({
}),
}));


vectorLayers.push(new OpenLayers.Layer.Vector("Preset Annotations", {
renderers: ["Canvas"],
projection: "EPSG:4326",
styleMap: new OpenLayers.StyleMap({
"annotation": new OpenLayers.Style(OpenLayers.Util.applyDefaults({
strokeColor: "grey",
fillColor: "grey",
strokeWidth: 2,
strokeOpacity: .5,
fillOpacity: .1,
label: "${label}",
labelAlign: "center",
}, OpenLayers.Feature.Vector.style["select"])),
})
}));

vectorLayers.push(new OpenLayers.Layer.Vector("Unit Display", {
renderers: ["Canvas"],
projection: "EPSG:4326",
Expand Down Expand Up @@ -380,6 +397,25 @@ mp.MapView = function(map_type) {
if (obj.type === "LINEARRING_ANNOTATION") redrawLinearRingAnnotation(obj);
if (obj.type === "UNIT") redrawUnit(obj);
if (obj.type === "BULLSEYE") redrawBullseye(obj);
if (obj.type == "PRESET_ZONE_ANNOTATION") redrawPresetZoneAnnotation(obj);
}

function redrawPresetZoneAnnotation(obj) {
var center = new OpenLayers.Geometry.Point(obj.lon, obj.lat).transform(this.map.getProjection(), 'EPSG:900913');
var feature = new OpenLayers.Feature.Vector();
var radius = obj.radius;
var poly = OpenLayers.Geometry.Polygon.createRegularPolygon(
center, radius, 24, 0
).transform("EPSG:900913", this.map.getProjection());
feature.geometry = poly.components[0];

features_by_object_id[obj.id] = [feature];
feature.renderIntent = "annotation";
feature.data.type = "annotation";
feature.data.object_id = obj.id;
feature.attributes.label = obj.label;
vectorLayers[LAYER_ID_PRESET_ANNOTATIONS].addFeatures([feature]);
vectorLayers[LAYER_ID_PRESET_ANNOTATIONS].redraw();
}

function redrawBullseye(obj) {
Expand Down

0 comments on commit 0c05bfa

Please sign in to comment.