POST
|
My code like below: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Untitled Page</title> <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/2.3/js/dojo/dijit/themes/tundra/tundra.css"> <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/2.3/js/esri/dijit/css/Popup.css"> <link rel="stylesheet" type="text/css" href="css/layout.css"> <script type="text/javascript"> var djConfig = { parseOnLoad: true }; </script> <script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.3"></script> <script type="text/javascript" src="javascript/layout.js"></script> <script type="text/javascript"> dojo.require("dijit.dijit"); // optimize: load dijit layer dojo.require("dijit.layout.StackContainer"); dojo.require("dijit.layout.BorderContainer"); dojo.require("dijit.layout.ContentPane"); dojo.require("esri.map"); dojo.require("esri.layers.FeatureLayer"); dojo.require("esri.dijit.Popup"); dojo.require("esri.arcgis.utils"); dojo.require("esri.dijit.Scalebar"); dojo.require("esri.dijit.editing.Editor-all"); dojo.require("esri.tasks.geometry"); var gsvc = null; var map; var siteLayer; var resizeTimer; var identifyTask, identifyParams; var locationLayer, morningsideLayer; var webmap; function init() { //setup the map's initial extent var initExtent = new esri.geometry.Extent({ "xmin": -16075536.684978526, "ymin": 3886141.8596739126, "xmax": -5058820.67229557, "ymax": 9756505.631973889, "spatialReference": { "wkid": 102100} }); var popup = new esri.dijit.Popup(null, dojo.create("div")); map = new esri.Map("map", { extent: initExtent, infoWindow: popup, showInfoWindowOnClick: false }); dojo.place(popup.domNode, map.root); //Add the imagery layer to the map. var basemap = new esri.layers.ArcGISTiledMapServiceLayer("http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer"); map.addLayer(basemap); var content = "<b>${Comments}</b>"; var infoTemplate = new esri.InfoTemplate("Census", content); siteLayer = new esri.layers.FeatureLayer("http://fc-wapps-trial/ArcGIS/rest/services/FirstCapitalRealtyForDemo/MapServer/0/", { mode: esri.layers.FeatureLayer.MODE_ONDEMAND, outFields: ["*"], infoTemplate: infoTemplate }); map.addLayer(siteLayer); dojo.connect(map, "onClick", function (evt) { map.infoWindow.hide(); }); dojo.connect(siteLayer, "onMouseOver", function (evt) { evt.graphic.attributes.Comments = "test"; map.infoWindow.setFeatures([evt.graphic]); map.infoWindow.show(evt.mapPoint); map.infoWindow.resize(300, 150); }); //resize the map when the browser resizes - view the 'Resizing and repositioning the map' section in dojo.connect(map, 'onLoad', function () { dojo.connect(dijit.byId('map'), 'resize', function () { //resize the map if the div is resized clearTimeout(resizeTimer); resizeTimer = setTimeout(function () { map.resize(); map.reposition(); }, 500); }); }); } dojo.addOnLoad(init); function provinceChanged() { map.setExtent(new esri.geometry.Extent({ "xmin": -12449771.627754202, "ymin": 4911254.148340904, "xmax": -5904316.021639728, "ymax": 7846436.034490892, "spatialReference": { "wkid": 102100} })); var siteIDs = new Array(); siteIDs[0] = "13001"; siteIDs[1] = "10011"; siteIDs[2] = "11252"; dojo.forEach(siteLayer.graphics, function (graphic) { if (siteIDs.exists(graphic.attributes.SiteID)) { graphic.visible = true; } }); map.infoWindow.hide(); } Array.prototype.exists = function (o) { for (var i = 0; i < this.length; i++) if (this == o) return true; return false; } </script> </head> <body class="tundra"> <form id="form1" style="width:100%" runat="server"> <div width="100%"> <div id="map" style="width:100%; height:600px"></div> </div> <input type="button" onclick="provinceChanged()" value="hide some point" /> </form> </body> </html>
... View more
06-17-2011
05:40 AM
|
0
|
1
|
726
|
POST
|
1. I created a map and publish to the server; 2. In this map, there are total 4 layers. The first layer named "locations", its type is "Point Features"; 3. In web application, i loaded this map thru: var myLayer = new esri.layers.ArcGISDynamicMapServiceLayer(myMapUrl, { opacity: 0.5 }); map.addLayer(myLayer ); i want to add a "onMouseOver" event on each point within the first layer, how to do that? Thanks,
... View more
06-15-2011
08:55 PM
|
0
|
3
|
672
|
POST
|
Thanks. Actually, i already defined it named "featurelayer". it is my need. 🙂 Thanks a lot.
... View more
06-01-2011
06:30 AM
|
0
|
0
|
332
|
POST
|
Mike, since i don't have your complete code, i modified the ESRI sample (http://help.arcgis.com/en/webapi/javascript/arcgis/demos/fl/fl_featureCollection.html) a little bit to include your posted code. It worked. Maybe there are something else in your code (webmap?) that you need look into. Hi hzhu, Thank you very very much for your code. it work now. 🙂 Another question, after i added that featurelayer, how could i retrieve it? i don't know which object should be used, "map" or "esri". i mean i want to get that polygon in a event. thanks again, Mike
... View more
06-01-2011
06:04 AM
|
0
|
0
|
332
|
POST
|
mike, a couple of issues in your function requestPolygon(itemInfo). 1. features is undefined. 2. the attributes of the feature you added to your featureLayerPolygon are missing. Try this: function requestPolygon(itemInfo) { var polygonSymbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DOT, new dojo.Color([151, 249, 0, .80]), 3), new dojo.Color([151, 249, 0, 0.45])); var polygon = new esri.geometry.Polygon({ "rings": [ [ [-4226661.916056009, 8496372.808143634], [-3835304.3312360067, 8731187.359035634], [-2269873.991956003, 9005137.668409634], [-4304933.433020009, 7635386.121539632], [-4304933.433020009, 7674521.880021632], [-4226661.916056009, 8496372.808143634] ] ], "spatialReference": { "wkid": 102100 } }); var attr = {}; attr["description"] = your description string; attr["title"] = your title string; featureLayerPolygon.applyEdits([new esri.Graphic(polygon, polygonSymbol, attr)], null, null); } Hi hzhu, Thanks a lot for your code. But it still doesn't work. Thanks again.
... View more
05-31-2011
12:20 PM
|
0
|
0
|
332
|
POST
|
Please elaborate on what you've tried and what, specifically, is failing. I want to generate a featurelayer with polygon and add it to map. Actually, i could add it to map thru map.graphics.add(); But i want to use featurelayer. Thanks.
... View more
05-31-2011
12:18 PM
|
0
|
0
|
332
|
POST
|
Please see the code as below: <script type="text/javascript"> dojo.require("dijit.layout.BorderContainer"); dojo.require("dijit.layout.ContentPane"); dojo.require("esri.map"); dojo.require("esri.layers.FeatureLayer"); dojo.require("esri.dijit.Popup"); dojo.require("esri.arcgis.utils"); dojo.require("esri.dijit.Scalebar"); dojo.require("esri.dijit.editing.Editor-all"); dojo.require("esri.tasks.geometry"); var gsvc = null; var map; var featureLayer; var resizeTimer; var webmap; function init() { webmap = "da8e773cb68149a39e06f706c6d7cdb2"; var itemDeferred = esri.arcgis.utils.getItem(webmap); itemDeferred.addCallback(function (itemInfo) { var initExtent = new esri.geometry.Extent({ "xmin": -12734442.894989174, "ymin": 4942199.239293063, "xmax": -5342676.5117014535, "ymax": 8459525.5328628, "spatialReference": { "wkid": 102100} }); //create a popup to replace the map's info window var popup = new esri.dijit.Popup(null, dojo.create("div")); map = new esri.Map("map", { extent: initExtent, infoWindow: popup }); dojo.place(popup.domNode, map.root); var basemap = new esri.layers.ArcGISTiledMapServiceLayer("http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer"); map.addLayer(basemap); dojo.connect(map, "onLayersAddResult", function (results) { requestPhotos(itemInfo); }); map.addLayers([featureLayer]); //create a feature collection for the flickr photos var featureCollectionPolygon = { "layerDefinition": null, "featureSet": { "features": [], "geometryType": "esriGeometryPolygon" } }; featureCollectionPolygon.layerDefinition = { "geometryType": "esriGeometryPolygon", "objectIdField": "ObjectID", "drawingInfo": { "renderer": { "type": "simple", "symbol": { "type": "esriSFS", "style": "esriSFSSolid" } } }, "fields": [{ "name": "ObjectID", "alias": "ObjectID", "type": "esriFieldTypeOID" }, { "name": "description", "alias": "Description", "type": "esriFieldTypeString" }, { "name": "imagelink", "alias": "imagelink", "type": "esriFieldTypeString" }, { "name": "title", "alias": "Title", "type": "esriFieldTypeString" }] }; //define a popup template var popupTemplatePolygon = new esri.dijit.PopupTemplate({ title: "{title}", description: "{description}" }); //create a feature layer based on the feature collection featureLayerPolygon = new esri.layers.FeatureLayer(featureCollectionPolygon, { id: 'Building Information', infoTemplate: popupTemplatePolygon }); //associate the features with the popup on click dojo.connect(featureLayerPolygon, "onClick", function (evt) { map.infoWindow.setFeatures([evt.graphic]); map.infoWindow.show(evt.mapPoint); }); dojo.connect(map, "onLayersAddResult", function (results) { requestPolygon(itemInfo); }); map.addLayers([featureLayerPolygon]); dojo.connect(map, 'onLoad', function (theMap) { dojo.connect(dijit.byId('map'), 'resize', function () { //resize the map if the div is resized clearTimeout(resizeTimer); resizeTimer = setTimeout(function () { map.resize(); map.reposition(); }, 500); }); }); }); } function requestPolygon(itemInfo) { var polygonSymbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DOT, new dojo.Color([151, 249, 0, .80]), 3), new dojo.Color([151, 249, 0, 0.45])); var polygon = new esri.geometry.Polygon({ "rings": [ [ [-4226661.916056009, 8496372.808143634], [-3835304.3312360067, 8731187.359035634], [-2269873.991956003, 9005137.668409634], [-4304933.433020009, 7635386.121539632], [-4304933.433020009, 7674521.880021632], [-4226661.916056009, 8496372.808143634] ] ], "spatialReference": { "wkid": 102100 } }); features.push(new esri.Graphic(polygon, polygonSymbol)); featureLayerPolygon.applyEdits(features, null, null); } dojo.ready(init); </script>
... View more
05-31-2011
06:55 AM
|
0
|
8
|
699
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:24 AM
|