一区二区三区日韩精品-日韩经典一区二区三区-五月激情综合丁香婷婷-欧美精品中文字幕专区

分享

Openlayers _ using The jQuery UI Dialog

 LibraryPKU 2014-05-12

5.3. The jQuery UI Dialog

If you are adding a map to a larger website, and you are already using jQuery UI for interface components, it makes good sense to create “popups” for your map that will be integrated with the style of the rest of your site. The jQuery UI dialog function provides a flexible way to produce themeable dialogs that serve a variety of purposes.

The previous example <openlayers.integration.jqui-slider.example started with existing markup and used the jQuery function to select and modify DOM elements. The jQuery function can also be used to create elements given a string of HTML.

The code below creates a <div> element and turns it into a modeless dialog:

jQuery("<div>Hello!</div>").dialog();

This technique is used in the tasks below to create dialogs populated with information from a feature’s attribute values.

5.3.1. Displaying Feature Information in a Dialog

Tasks

  1. At the end of the previous section, you should have something like the code below in your map.html file. Open this file in your text editor and confirm the contents are similar to the following:

    <!DOCTYPE html>
    <html>
        <head>
            <title>My Map</title>
            <link rel="stylesheet" href="openlayers/theme/default/style.css" type="text/css">
            <style>
                #map-id {
                    width: 512px;
                    height: 256px;
                }
                #slider-id {
                    width: 492px;
                    margin: 10px;
                }
            </style>
            <script src="openlayers/lib/OpenLayers.js"></script>
            <link rel="stylesheet" href="jquery-ui/css/smoothness/jquery-ui-1.8.14.custom.css" type="text/css">
            <script src="jquery-ui/js/jquery-1.5.1.min.js"></script>
            <script src="jquery-ui/js/jquery-ui-1.8.14.custom.min.js"></script>    </head>
        <body>
            <h1>My Map</h1>
            <div id="map-id"></div>
            <div id="slider-id"><div class="ui-slider-handle"></div>
            <script>
                var medford = new OpenLayers.Bounds(
                    4284890, 253985,
                    4288865, 257980
                );
                var map = new OpenLayers.Map("map-id", {
                    projection: new OpenLayers.Projection("EPSG:2270"),
                    units: "ft",
                    maxExtent: medford,
                    restrictedExtent: medford,
                    maxResolution: 2.5,
                    numZoomLevels: 5
                });
    
                var base = new OpenLayers.Layer.WMS(
                    "Medford Streets & Buildings",
                    "/geoserver/wms",
                    {layers: "medford"}
                );
                map.addLayer(base);
    
                var buildings = new OpenLayers.Layer.Vector("Buildings", {
                    strategies: [new OpenLayers.Strategy.BBOX()],
                    protocol: new OpenLayers.Protocol.WFS({
                        version: "1.1.0",
                        url: "/geoserver/wfs",
                        featureType: "buildings",
                        featureNS: "http://medford.",
                        srsName: "EPSG:2270"
                    })
                });
                map.addLayer(buildings);
    
                map.zoomToMaxExtent();
                $("#slider-id").slider({
                    value: 100,
                    slide: function(e, ui) {
                        base.setOpacity(ui.value / 100);
                    }
                });
    
            </script>
        </body>
    </html>
    
  2. To this example, we’ll be adding an OpenLayers.Control.SelectFeature control so that the user can select a feature. In your map initialization code, add the following after the creation of your buildings layer:

    var select = new OpenLayers.Control.SelectFeature([buildings]);
    map.addControl(select);
    select.activate();
    
  3. Next we need to create a listener for the featureselected event on our buildings layer. We’ll create a dialog that populates with feature information, when the user selects a feature by clicking on it with the mouse. In addition, we want to remove the dialog when a feature is unselected. We can do this by listening for the featureunselected event. Insert the following in your map initialization code somewhere after the creation of the buildings layer:

    var dialog;
    buildings.events.on({
        featureselected: function(event) {
            var feature = event.feature;
            var area = feature.geometry.getArea();
            var id = feature.attributes.key;
            var output = "Building: " + id + " Area: " + area.toFixed(2);
            dialog = $("<div title='Feature Info'>" + output + "</div>").dialog();
        },
        featureunselected: function() {
            dialog.dialog("destroy").remove();
        }
    });
    
  4. Save your changes to map.html and open the page in your browser: @workshop_url@/map.html

    ../_images/jqui-dialog1.png

    A map that displays feature information in a dialog.

Bonus Tasks

  1. Find the appropriate documentation to determine how to make the feature dialog with modal behavior. Create a modal dialog for displaying feature information so a user will need to close it before interacting with anything else in the application.
  2. Experiment with editing the style declarations in the head of the page in order to change the look of the displayed information. You can use the jQuery addClass function to add a class name to an element before calling dialog().

    本站是提供個(gè)人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多

    欧美精品亚洲精品日韩专区| 人妻少妇久久中文字幕久久| 日韩欧美一区二区不卡看片| 丰满少妇被猛烈插入在线观看 | 国产高清一区二区白浆| 国产一级不卡视频在线观看| 在线观看视频成人午夜| 欧美不卡高清一区二区三区| 黄色国产精品一区二区三区| 好吊日在线视频免费观看| 日韩人妻一区二区欧美| 国产激情一区二区三区不卡| 在线免费国产一区二区三区| 99久久精品午夜一区二区| 精品人妻一区二区三区免费看| 久久精品国产99国产免费| 午夜精品久久久99热连载| 午夜福利92在线观看| 在线观看视频日韩精品| 精品人妻精品一区二区三区| 亚洲一区二区三区免费的视频| 黄片在线免费看日韩欧美| 一区中文字幕人妻少妇| 久久碰国产一区二区三区| 粉嫩内射av一区二区| 亚洲乱妇熟女爽的高潮片| 一级片二级片欧美日韩| 99久久精品午夜一区二| 国产亚洲精品俞拍视频福利区| 五月情婷婷综合激情综合狠狠| 日韩中文字幕欧美亚洲| 欧美一区二区三区播放| 日韩蜜桃一区二区三区| 中日韩美女黄色一级片| 欧美日韩国产一级91| 日韩精品一区二区三区含羞含羞草| 亚洲av专区在线观看| 亚洲中文字幕视频在线观看| 又色又爽又黄的三级视频| 蜜桃传媒视频麻豆第一区| 国产激情国产精品久久源|