JavaScript operation svgdom for map function

Source: Internet
Author: User

1, the customer requested to do a shop map, enter the store can view all the shop floor information, click on the map map of a block area, display the corresponding store information. (Provides floor screening, public facility inquiries), and map scaling. The customer requests the map through the H5 to operate the SVG picture to realize, the display uses the JS call native method to display the corresponding store information.

SVG images can be loaded directly into a Web page via <object><iframe><embed> four tags.

tags loading svg images cannot be obtained to svgdom, so only three additional tags can be used.

Three kinds of tags get DOM methods as follows:

HTML page Loading:

Get the corresponding Svgdom

Here I am using an iframe to load SVG images, because I am on the map page to provide the floor menu, click on different floors local refresh loading different SVG pictures. (object,embed I have tried to click on different floors, the page did not reload the SVG images on different floors).

Note: When using an iframe to get svgdom, you must wait until the IFRAME is loaded and call document.getElementById (' iframe '). Contentdocument get Svgdom, Otherwise, you will not get the svgdom. That's what I wrote:

if (iframe.attachevent) {
Iframe.attachevent (' onload ', function () {
Alert (' iframe is loaded ')
})
}else{
Iframe.onload = function () {
Get Svgdom here
var iframesvg = document.getElementById (' iframe '). Contentdocument;
Next, you can manipulate the svgdom, bind elements, click events, change the attributes of the elements, and so on.
Bind a point-and-click event to an element with Id ' l01n01 ' on SVG
Iframesvg.getelementbyid (' L01n01 '). AddEventListener (' click ', function () {
Click event Action
})
}
}

Appendix:
Reference article: http://javascript.ruanyifeng.com/htmlapi/svg.html

JavaScript operation svgdom for map function

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.