1 function addNoteLayer(map, notesUrl, newNoteControls, minZoom) {
4 var noteCallback = function (scope, response) {
5 for (var f = 0; f < response.features.length; f++) {
6 var feature = response.features[f];
10 var saveNewNotes = function (o) {
12 newNotes = layer.getFeaturesByAttribute("status", "new")
13 layer.removeFeatures(newNotes, { silent: true });
16 var restoreNewNotes = function (o) {
18 layer.addFeatures(newNotes);
22 var noteSelected = function (o) {
23 var feature = o.feature;
24 var location = feature.geometry.getBounds().getCenterLonLat();
26 feature.popup = new OpenLayers.Popup.FramedCloud(
27 feature.attributes.id, location, null,
28 "<p>" + feature.attributes.id + "</p>",
30 feature.attributes.status !== "new",
31 function (e) { map.noteSelector.unselect(feature) }
34 map.addPopup(feature.popup);
35 // feature.popup.show();
38 var noteUnselected = function (o) {
39 var feature = o.feature;
41 map.removePopup(feature.popup);
46 var allowNoteReports = function () {
47 if (map.getZoom() > minZoom) {
48 newNoteControls.show();
50 newNoteControls.hide();
54 var addNote = function () {
55 var lonlat = map.getCenter();
56 var layer = map.noteLayer;
57 var geometry = new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat);
58 var feature = new OpenLayers.Feature.Vector(geometry, {
62 layer.addFeatures(feature);
63 map.noteSelector.unselectAll();
64 map.noteSelector.select(feature);
65 map.noteMover.activate();
66 map.noteLayer.setVisibility(true);
69 map.noteLayer = new OpenLayers.Layer.Vector("Notes", {
71 projection: new OpenLayers.Projection("EPSG:4326"),
72 styleMap: new OpenLayers.StyleMap(new OpenLayers.Style({
81 filter: new OpenLayers.Filter.Comparison({
82 type: OpenLayers.Filter.Comparison.EQUAL_TO,
87 externalGraphic: "<%= image_path 'new_note_marker.png' %>"
91 filter: new OpenLayers.Filter.Comparison({
92 type: OpenLayers.Filter.Comparison.EQUAL_TO,
97 externalGraphic: "<%= image_path 'open_note_marker.png' %>"
100 new OpenLayers.Rule({
101 filter: new OpenLayers.Filter.Comparison({
102 type: OpenLayers.Filter.Comparison.EQUAL_TO,
107 externalGraphic: "<%= image_path 'closed_note_marker.png' %>"
113 new OpenLayers.Strategy.BBOX()
115 protocol: new OpenLayers.Protocol.HTTP({
117 format: new OpenLayers.Format.GeoJSON(),
118 callback: noteCallback
122 map.noteLayer.events.register("beforefeaturesremoved", map, saveNewNotes);
123 map.noteLayer.events.register("featuresremoved", map, restoreNewNotes);
124 map.noteLayer.events.register("featureselected", map, noteSelected);
125 map.noteLayer.events.register("featureunselected", map, noteUnselected);
127 map.addLayer(map.noteLayer);
129 map.noteSelector = new OpenLayers.Control.SelectFeature(map.noteLayer, {
133 map.addControl(map.noteSelector);
135 map.noteMover = new OpenLayers.Control.DragFeature(map.noteLayer, {
136 onDrag: function (feature, pixel) {
137 feature.popup.lonlat = feature.geometry.getBounds().getCenterLonLat();
138 feature.popup.updatePosition();
141 over: function (feature) {
142 if (feature.attributes.status === "new") {
143 map.noteMover.overFeature.apply(map.noteMover, [feature]);
149 map.addControl(map.noteMover);
151 newNoteControls.click(addNote);
153 map.events.register("zoomend", map, allowNoteReports);
155 return map.noteLayer;