Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Clickable Boxes to all Maps #1

Open
wants to merge 2 commits into
base: 625bc2ba
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion imageryindex/django/oamcatalog/static/js/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,39 @@ var OAMFormat = OpenLayers.Class(OpenLayers.Format.JSON, {
var image = obj.images[i];
var bounds = OpenLayers.Bounds.fromArray(image.bbox);
var f = new OpenLayers.Feature.Vector(bounds.toGeometry());
f.image = image;
features.push(f);
}
return features;
}
});

var map, selectControl, selectedFeature;
function onPopupClose(evt) {
selectControl.unselect(selectedFeature);
evt.stopPropagation()
}

function onFeatureSelect(feature) {
selectedFeature = feature;
popup = new OpenLayers.Popup.FramedCloud("chicken",
feature.geometry.getBounds().getCenterLonLat(),
null,
'<div><a href="/image/' + feature.image.id + '">Image ' + feature.image.id + '</a></div>',
null, true, onPopupClose);
feature.popup = popup;
map.addPopup(popup);
}

function onFeatureUnselect(feature) {
map.removePopup(feature.popup);
feature.popup.destroy();
feature.popup = null;
selectedFeature = null;
}

function createMap(url, div){
var map = new OpenLayers.Map( 'map', {displayProjection: new OpenLayers.Projection("EPSG:4326")} );
map = new OpenLayers.Map( 'map', {displayProjection: new OpenLayers.Projection("EPSG:4326")} );
var layer = new OpenLayers.Layer.OSM("OSM");
map.addLayer(layer);
layer = new OpenLayers.Layer.Vector("", {
Expand All @@ -41,6 +66,10 @@ function createMap(url, div){
}
});
// map.addControl(new OpenLayers.Control.Permalink());
selectControl = new OpenLayers.Control.SelectFeature(layer,
{onSelect: onFeatureSelect, onUnselect: onFeatureUnselect});
map.addControl(selectControl);
selectControl.activate();

if (!map.getCenter()) {
map.zoomToMaxExtent();
Expand Down
2 changes: 2 additions & 0 deletions imageryindex/django/oamcatalog/util/oam.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ OpenLayers/Renderer/VML.js
OpenLayers/Control/Navigation.js
OpenLayers/Control/Attribution.js
OpenLayers/Control/ZoomPanel.js
OpenLayers/Control/SelectFeature.js
OpenLayers/StyleMap.js
OpenLayers/Protocol/HTTP.js
OpenLayers/Format/JSON.js
OpenLayers/Feature/Vector.js
OpenLayers/Strategy/BBOX.js
OpenLayers/Geometry/Polygon.js
OpenLayers/Popup/FramedCloud.js

[exclude]

Expand Down