MM Map API Documentation ReferenceMM Map API comes the Thailand map imageries from NuMAP called NuRasterMap. Usage of the MM Map API with this NuRasterMap is possible only under the condition specified in the MM Map API Term of Use. You will need to register for a key to be used with your web URL, see more information about how to obtain the key. For MM Route routing suggestion API reference, please visit MM Route API Reference. More demos code are available at http://mapdemo.longdo.com/. Include the MMMap engine JavaScript classPut this in the header (replace xxxxxxxxxxxxxx with the registered key): <script type="text/javascript" src=http://mmmap15.longdo.com/mmmap/mmmap.php?key=xxxxxxxxxxxxxxx></script> Create a map objectSpecify a div, latitude, longitude, and zoom level. You need create a div to hold the map, e.g., mmmap_div, first and create a variable linking to it. var mmmap_div = document.getElementById('my_map_div'); You can also specify mapmode, e.g., "icons", "normal" (without icons), "traffic" (gray-ish map), "hydro" Note that the given latatitude and longitude in MMMap constructor above can be overriden by the location-remembering feature using web browser cookie (i.e. user will see the same location if he/she revisits MM Map API pages). To avoid this, call the moveTo again: mmmap.moveTo(13.767734,100.5351375); This is way too complicated. Could you just show me a working example?Sure. Please visit our map demo site at http://mapdemo.longdo.com/. There are several examples, you can view HTML source code of each example to see how the APIs are used. Don't forget to replace the API key with yours one if you cut and paste those code to your files. Create a markervar marker_id = mmmap.createMarker(13.7654,100.538,"Victory Monoment", "<font face=tahoma>An important transportation hub of Bangkok.อนุสาวรีย์ชัยครับ</font>"); Note the the return value is the marker id (integer). Later on, you can also modify the contents of the marker. document.getElementById("marker_" + marker_id).detail += "<br><br><span style='cursor:pointer;text-decoration:underline' onclick='mmmap.deleteMarker("+marker_id+")'>Delete</span>"; Delete a markermarkerid = id of the marker you get as a return value of the call mmmap.createMarker(...) (see the previous question) mmmap.deleteMarker(markerid); Show a popupmmmap.showPopUp(lat, lon, title, content); The width and height of the pop-up will be automatically determined based on the contents inside. Optionally popup parameters can be also given in case we want to hint the proper width and height. var popup_params = { mmmap.showPopUp(lat, lon, title, content, popup_params); Other possible parameters:
To close an open popup, use mmmap.closeLocationDetailPopup(); See the demo at http://mapdemo.longdo.com/index-popupdemo.php. Display a user-defined divvar testdiv = document.createElement("div"); function testclick(){ Also you can draw a custom div only at some zoom level: min_zoom = 3; Or draw custom div together with add a pop-up mmmap.drawCustomDivWithPopup(testdiv, 13.752016, 100.53059, "what is this", "this is a pop-up"); By default the center of the testdiv will be positioned at the given latitude and longitude. The center of the testdiv is defiend by its width/2 and height/2. In some cases you might want to specify these offsets, you can do so by: var attributes = { mmmap.drawCustomDiv(testdiv, 13.752016, 100.53059, "HEY", attributes); Other possible attributes:
Delete a user-defined divcustomdiv_id = id of the custom div you get as a return value of the call mmmap.drawCustomDiv(...) (see the previous question) mmmap.removeCustomDivs(markerimage.customdiv_id); Or you can delete all custom divs: mmmap.clearCustomDivs(); Get the position of a user-defined divcustomdivholder_id = id of the custom div you get as a return value of the call mmmap.drawCustomDivHolder(...) var mydiv = mmmap.getCustomDivHolder(customdivholder_id); alert(mydiv.latitude + ", " + mydiv.longitude); Resize the mapmmmap.setSize(newwidth,newheight); Move to a locationmmmap.moveTo(latitude, longitude); Get and set the zoom levelmmmap.getZoom(); mmmap.setZoom(3); Get/Set map modeTo change the base map layer, one can use the following functions: mmmap.setMapMode("normal"); mmmap.setMapAttributes( {"opacity": 0.65}); // set the opacity attribute of the base layer Available base layer map modes are: icons, icons-en, normal, normal-en, hydro, political, political-en, rail, rail-en, traffic, traffic-en, water, minimal, hydro (subject to change). Add custom items to the right-click menuDefine a function that will print the HTML content for the menu items and register it with mmmap.extraRightClickFunction. function myExtraRightClickFunction() { then do: mmmap.setExtraRightClickFunction(myExtraRightClickFunction); Cannot type "+", "-", "z", "x" in my search box. How do I fix?This is because those keys' events are used for map navigation. One work around is to do something like this. <input type=text name="searchfor" id="searchfor" size=14 onfocus="document.onkeydown='return true'" onblur="setKeyFocusAtMaparea()" onclick="document.onkeydown='return true'"> And setKeyFocusAtMaparea() should be something like: function setKeyFocusAtMaparea() { document.onkeydown=kh.doKeyDown; Get the current latitudeUse mmmap.centerLat() and mmmap.centerLong() (Accessing the global variables "latitude" and "longitude" are depreciated) Drawing Lines, Polygons, and EllipsesThere are two ways to draw lines as shown below but for polygons, use only the latter method. Use mmmap.drawLine functions (old way):
mmmap.drawLine(x1,y1, x2,y2, startzoom,stopzoom,title,detail, detailpopup , pointmode)
mmmap.drawPolyline(points, startzoom,stopzoom,title,detail, detailpopup, pointmode) Example: mmmap.gssetopacity(0.7); Use MMLine class (new way) Example: var points = [ var polygon = new MMLine(mmmap); polygon.hide(); polygon.show(); polygon.remove(); // remove permanently var polygon2 = new MMLine(mmmap); var points3 = [13.8337, 100.59461]; By default, the newly drawn objects will appear on top of the existing ones. Order of drawn objects can be changed by using setOrder(): polygon.setOrder(1000);polygon.rePaint(); To draw label use setCenter(lat, long) and setLabel(text): polygon.setCenter(13.123, 100.456);polygon.setLabel("My polygon"); In some cases in some browsers (notably IE), not all the line and polygon objects are shown unless the user moves the map a little or zoom to other levels. In such cases, adding this line to force the re-drawing of objects might help: setTimeout("mmmap.reDrawLines()", 2000); // *** to ensure that all objects are properly displayed *** Please see http://mapdemo.longdo.com/index-drawpolygons.php.
Advance Lines, Polygons, and Ellipses
Keyboard-related
Custom Event Handlers
function f() {
alert("Current location is " + latitude + ", " + longitude); }; mmmap.setMouseMoveHandler(f); Adding controlsControls will be displayed at the top left corner of the maps. var canvas= mmmap.addControl("canvas"); canvas.addButtons("measure"); canvas.addButtons("poly"); canvas.addButtons("clear");
Advanced controls
Show/Hide ThingsFor minimalists:
Data APIWe provide a function to draw several pre-defined objects (points, lines, and polygons), e.g., province/district/subdistrict boundary, roads, Longdo Map contributed points, lines and polygons. Usage is as below: mmmap.showObject(myid,ds,showdefaulttitle,forcetitle,forcemode,linecolor,fillcolor,linetransp,filltransp) Note that by using this API to display too many data, the client browser might become less responsive. Example: mmmap.showObject('5710', "IG"); // แสดงขอบเขตอำเภอ อ.แม่สรวย โดย 5710 เป็น Geocode ตามของกระทรวงมหาดไทย ของ อ.แม่สรวย mmmap.showObject('ถนนพญาไท', "RNM"); // แสดงเส้นถนนพญาไท
mmmap.showObject('M00000001', "LONGDO"); // แสดง Longdo Map contributed map หมายเลข M00000001 (ซึ่งประกอบด้วยเส้นทางรถไฟฟ้าสายใหม่ๆ ของ กทม. และปริมณฑล) The return value of showObject is of MMMapObject class, you can also do: new MMMapObject(mymmmap, myid,ds,showdefaulttitle,forcetitle,forcemode,linecolor,fillcolor,linetransp,filltransp) Example: var x1 = new MMMapObject(mmmap, 'จ.นนทบุรี', "ADM", true, "เมืองนนทน์", "polygon", "FF0000", "FF0000"); TagMM Map API allows displaying of Object-Of-Interests (OOI) from Longdo Map web site by using the mmmap.showOOITag() method:
LayersMM Map API allows displaying of map layers together with the base one. In layers, image tiles will be retrieved from image servers using the protocol specified in the configuration. Currently two protocols are supported: the WMS (Web Map Service) and the LONGDO own map image server protocol.
The usage of the Layer API can be illustrated in the example JavaScript code below:
More information please view the example at http://mapdemo.longdo.com/index-layers.php Etc
|