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 displayInLayerSwitcher: false,
72 projection: new OpenLayers.Projection("EPSG:4326"),
73 styleMap: new OpenLayers.StyleMap(new OpenLayers.Style({
82 filter: new OpenLayers.Filter.Comparison({
83 type: OpenLayers.Filter.Comparison.EQUAL_TO,
88 externalGraphic: "<%= image_path 'new_note_marker.png' %>"
92 filter: new OpenLayers.Filter.Comparison({
93 type: OpenLayers.Filter.Comparison.EQUAL_TO,
98 externalGraphic: "<%= image_path 'open_note_marker.png' %>"
101 new OpenLayers.Rule({
102 filter: new OpenLayers.Filter.Comparison({
103 type: OpenLayers.Filter.Comparison.EQUAL_TO,
108 externalGraphic: "<%= image_path 'closed_note_marker.png' %>"
114 new OpenLayers.Strategy.BBOX()
116 protocol: new OpenLayers.Protocol.HTTP({
118 format: new OpenLayers.Format.GeoJSON(),
119 callback: noteCallback
123 map.noteLayer.events.register("beforefeaturesremoved", map, saveNewNotes);
124 map.noteLayer.events.register("featuresremoved", map, restoreNewNotes);
125 map.noteLayer.events.register("featureselected", map, noteSelected);
126 map.noteLayer.events.register("featureunselected", map, noteUnselected);
128 map.addLayer(map.noteLayer);
130 map.noteSelector = new OpenLayers.Control.SelectFeature(map.noteLayer, {
134 map.addControl(map.noteSelector);
136 map.noteMover = new OpenLayers.Control.DragFeature(map.noteLayer, {
137 onDrag: function (feature, pixel) {
138 feature.popup.lonlat = feature.geometry.getBounds().getCenterLonLat();
139 feature.popup.updatePosition();
142 over: function (feature) {
143 if (feature.attributes.status === "new") {
144 map.noteMover.overFeature.apply(map.noteMover, [feature]);
150 map.addControl(map.noteMover);
152 newNoteControls.click(addNote);
154 map.events.register("zoomend", map, allowNoteReports);
156 return map.noteLayer;