Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Parameters to be passed either from config file or some other source
- var mapPath="/cgi-bin/mapserv?map=/home/mark/htdocs/sandbox/contra_costa/mapdata/ccc.map";
- var map, base;
- function initMap(obj){
- var maxBounds=obj;
- var extent = new OpenLayers.Bounds(maxBounds[0], maxBounds[1], maxBounds[2], maxBounds[3]);
- var options = {
- restrictedExtent: extent
- };
- map = new OpenLayers.Map( 'map', options );
- base = new OpenLayers.Layer.WMS("Contra Costa County",
- mapPath,
- {
- layers: 'county,city,water,landmarks,roads'
- },
- {
- isBaseLayer: true,
- maxResolution: "auto",
- maxExtent: extent
- });
- var sirens = new OpenLayers.Layer.Vector("CWS Sirens",
- {
- strategies: [new OpenLayers.Strategy.Fixed()],
- protocol: new OpenLayers.Protocol.HTTP({
- url: "./sirens.kml",
- format: new OpenLayers.Format.KML(
- {
- extractStyles: true,
- extractAttributes: true,
- maxDepth: 1
- })
- })
- });
- var tens = new OpenLayers.Layer.WMS( "TENS Zones",
- mapPath,
- {
- layers: 'tens',
- transparent: true
- }, {
- isBaseLayer: false
- });
- tens.setVisibility(false);
- map.addLayers([base,sirens,tens]);
- select = new OpenLayers.Control.SelectFeature(sirens);
- sirens.events.on({
- "featureselected": onFeatureSelect,
- "featureunselected": onFeatureUnselect
- });
- map.addControl(select);
- map.addControl(new OpenLayers.Control.MousePosition());
- map.addControl(new OpenLayers.Control.LayerSwitcher());
- select.activate();
- map.zoomToMaxExtent();
- }
- function changeOption(obj) {
- var newBounds = obj.options[obj.selectedIndex].value.split(",");
- var newExtent = new OpenLayers.Bounds(newBounds[0], newBounds[1], newBounds[2], newBounds[3]);
- base.mergeNewParams({maxExtent: newExtent});
- map.zoomToExtent(newExtent);
- }
- function onPopupClose(evt) {
- select.unselectAll();
- }
- function onFeatureSelect(event) {
- var feature = event.feature;
- // Since KML is user-generated, do naive protection against Javascript.
- var content = "<h2>"+feature.attributes.name + "</h2>" + feature.attributes.description;
- if (content.search("<script") != -1) {
- content = "Content contained Javascript! Escaped content below.<br />" + content.replace(/</g, "<");
- }
- popup = new OpenLayers.Popup.FramedCloud("chicken",
- feature.geometry.getBounds().getCenterLonLat(),
- new OpenLayers.Size(100,100),
- content, null, true, onPopupClose);
- feature.popup = popup;
- map.addPopup(popup);
- }
- function onFeatureUnselect(event) {
- var feature = event.feature;
- if(feature.popup) {
- map.removePopup(feature.popup);
- feature.popup.destroy();
- delete feature.popup;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement