Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Map Function with GeoDjango and KML Layers
function init() {
map = new OpenLayers.Map("map", {'theme': null});
var gmap = new OpenLayers.Layer.GoogleNG({type: google.maps.MapTypeId.HYBRID});
var sheds = new OpenLayers.Layer.Vector("KML", {
projection: map.displayProjection,
strategies: [new OpenLayers.Strategy.Fixed()],
protocol: new OpenLayers.Protocol.HTTP({
url: "http://www.geosprocket.com/files/vthuc12a.kml",
format: new OpenLayers.Format.KML({
extractStyles: true,
extractAttributes: true
})
})
});
map.addLayers([gmap,sheds]);
map.zoomToExtent(new OpenLayers.Bounds(-9037508.34, -9037508.34, 9037508.34, 9037508.34));
//map.zoomToMaxExtent();
var layers = [];
for (var key in LAYER_CONFIG) {
var layer_info = LAYER_CONFIG[key];
var layer = new OpenLayers.Layer.Vector(layer_info['title'], {
strategies: [new OpenLayers.Strategy.Fixed(), new OpenLayers.Strategy.Save()],
protocol: new OpenLayers.Protocol.HTTP({
url: "/data/"+key,
format: new OpenLayers.Format.GeoJSON()
}),
layerKey: key
});
if (LAYER_CONFIG[key].styleMap) {
layer.styleMap = LAYER_CONFIG[key].styleMap;
}
LAYER_CONFIG[key].layer = layer;
map.addLayer(layer);
layer.events.register('loadend', layer, register);
layer.events.register('featureselected', null, featureSelected);
layers.push(layer);
}
MyToolbar = OpenLayers.Class(OpenLayers.Control.Panel, {
initialize: function(options) {
OpenLayers.Control.Panel.prototype.initialize.apply(this, [options]);
this.defaultControl = new OpenLayers.Control.SelectFeature(layers, {displayClass: 'olControlNavigation'});
this.addControls( [this.defaultControl]);
for (var layer in LAYER_CONFIG) {
var info = LAYER_CONFIG[layer];
this.addControls( [
new OpenLayers.Control.DrawFeature(info.layer, OpenLayers.Handler[info.type], {'displayClass': 'olControlDrawFeature'+info.type, 'title': LAYER_CONFIG[layer].title, multi: info.multi || false})
]);
if (info.editable) {
this.addControls( [
new OpenLayers.Control.ModifyFeature(info.layer, {vertexRenderIntent: 'temporary'})
]);
}
}
this.displayClass = 'myToolbar';
},
CLASS_NAME: 'MyToolbar'
});
var toolbar = new MyToolbar();
map.addControl(new MyToolbar());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.