The Arcgis for Javascript API is similar to how Baidu searches for a, B, C, D marker implementations

Source: Internet
Author: User

Original: Arcgis for Javascript API similar to Baidu search for a, B, C, D marker Implementation mode

More useless, first put two pictures to let us see the specific effect:


Figure 1, Baidu map search results


Figure 2, the effect of Arcgis for JavaScript implementation

See the effect, is not everyone a little chicken move, is not also spoil the move, there is wood? But how is it implemented? Let me give you a detailed talk about my idea of realization.


First, the data.

In fact, the object of the search from the type, should be points, lines, polygons are supported, but in the actual operation, whether Baidu or I do their own time, will be all the object of the point of the object, that is, to convert each object into a POI hotspot, and then the object's coordinate information extracted, all the objects into storage.


Second, realize.

To achieve this effect, first, based on the user's query criteria from the database to obtain data, the data returned to the Web is in JSON format. After getting to the data, then do the data on the left side of the page display and the map to the left of the list corresponding to the display, the left side of the list of the show I do not elaborate, have done the web there are 10,000 ways to achieve it, focusing on the display on the map.

These red bubbles are a graphiclayer, each bubble is a graphic, just according to different order, graphic Picturemarkersymbol is different, the following is the implementation of the Code:

[JavaScript]View Plaincopy print?
  1. <span style="White-space:pre" > </span>addquerypopup = function (data) {
  2. Redpopuplayer.clear ();
  3. var mlpoint = New Esri.geometry.Multipoint (new ESRI.  Spatialreference ({wkid:4326}));
  4. var graphic = null;
  5. For (var i=0;i<data.length;i++) {
  6. var att=data[i];
  7. var pt = New Esri.geometry.Point (Att.x,att.y,new ESRI.  Spatialreference ({wkid:4326}));
  8. Mlpoint.addpoint (PT);
  9. var SMS = null;
  10. switch (i) {
  11. Case 0:{
  12. SMS = New Esri.symbol.PictureMarkerSymbol ("Index/css/map/images/location_icon/a.png", 15,19);
  13. Break ;
  14. }
  15. Case 1:{
  16. SMS = New Esri.symbol.PictureMarkerSymbol ("Index/css/map/images/location_icon/b.png", 15,19);
  17. Break ;
  18. }
  19. Case 2:{
  20. SMS = New Esri.symbol.PictureMarkerSymbol ("Index/css/map/images/location_icon/c.png", 15,19);
  21. Break ;
  22. }
  23. Case 3:{
  24. SMS = New Esri.symbol.PictureMarkerSymbol ("Index/css/map/images/location_icon/d.png", 15,19);
  25. Break ;
  26. }
  27. Case 4:{
  28. SMS = New Esri.symbol.PictureMarkerSymbol ("Index/css/map/images/location_icon/e.png", 15,19);
  29. Break ;
  30. }
  31. Case 5:{
  32. SMS = New Esri.symbol.PictureMarkerSymbol ("Index/css/map/images/location_icon/f.png", 15,19);
  33. Break ;
  34. }
  35. Case 6:{
  36. SMS = New Esri.symbol.PictureMarkerSymbol ("Index/css/map/images/location_icon/g.png", 15,19);
  37. Break ;
  38. }
  39. Case 7:{
  40. SMS = New Esri.symbol.PictureMarkerSymbol ("Index/css/map/images/location_icon/h.png", 15,19);
  41. Break ;
  42. }
  43. Case 8:{
  44. SMS = New Esri.symbol.PictureMarkerSymbol ("Index/css/map/images/location_icon/i.png", 15,19);
  45. Break ;
  46. }
  47. default:{
  48. SMS = New Esri.symbol.PictureMarkerSymbol ("Index/css/map/images/location_icon/j.png", 15,19);
  49. }
  50. }
  51. Graphic = new ESRI.                         Graphic (PT, SMS, ATT);
  52. Redpopuplayer.add (graphic);
  53. }
  54. var extent = mlpoint.getextent ();
  55. Map.setextent (Extent.expand (2));
  56. };

In this way, a similar effect is achieved.


Thirdly, linkage.

Linkage, what is a concept? For the results of the search, click on the bubble, the object will pop up the information, as follows:


Figure 3, the information box of Baidu Map


Figure 4, Information box for ArcGIS

The so-called linkage, is to click on the left-hand list can also pop-up click on the red bubble like the message box, then how to implement in ArcGIS? Let's talk about my idea of how to achieve this effect.

Generally speaking, the content of the information box is mostly dynamically obtained, so my processing is to pass a unique encoding ID of the object parameters, in the background after obtaining data in the background to spell HTML code or to the foreground to spell HTML code, the implementation method is as follows:

[JavaScript]View Plaincopy print?
  1. <span style="White-space:pre" > </span>/**
  2. * Display object Information box Infowindow
  3. */
  4. Showobjinfo = function (ID) {
  5. $.ajax ({
  6. URL:"wateruserbasecontroller.do?baseinfosummary&id=" +id,
  7. Type:"POST",
  8. DataType:"html",
  9. Success:function (data) {
  10. Data=eval (data);
  11. var pt = new Esri.geometry.Point (data.x,data.y,{wkid:4326});
  12. var name = Data.name;
  13. Map.infoWindow.resize (350,300);
  14. Map.infoWindow.setTitle (name+"<a class= ' detailsinfo ' id= ' detailsinfo ' > Details </a>");
  15. $ ("#detailsinfo"). On ("click",function () {
  16. Showobjdetailinfo (Id,name);
  17. });
  18. Map.infoWindow.setContent (data.html);
  19. Map.infoWindow.show (PT);
  20. }
  21. });
  22. };

With the above method, the same method is called when the left list and the marker object are clicked, passing the parameter as the unique encoding ID of the object.

Eye-thin friends may see, in the Information box title bar There is a detailed link, yes, this link is working, click the Detailed link, pop up the details of the object, the method is called as follows:

[JavaScript]View Plaincopy print?
  1. <span style="White-space:pre" > </span>/**
  2. * Show Detailed information
  3. */
  4. Showobjdetailinfo = function (ID) {<pre name="code" class="javascript" ><span style="whit E-space:pre "> </span>$.ajax ({
  5. URL:"wateruserbasecontroller.do?baseinfo&id=" +id,
  6. Type:"POST",
  7. DataType:"html",
  8. Success:function (data) {
  9. Data=eval (data);
  10. var name = Data.name;
  11. $. Window.settitle (name);
[JavaScript]View Plaincopy print?
    1. <span style="White-space:pre" > </span>$.  Window.setcontent (data.html);
    2. $. Window.show ();
    3. }
    4. });

};

The Arcgis for Javascript API is similar to how Baidu searches for a, B, C, D marker implementations

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.