Flash+xml realization of Electronic map query and location function

Source: Internet
Author: User
Tags functions query
On the XML, we realize how to mark the function of the place name online in the electronic map (see Flash+asp realize electronic interactive map online tagging function), in this case, we learn to realize the search and location function by name names.

The function of this example is divided into "query" and "positioning" two parts, the query function by invoking the data of the XML file to achieve. The positioning function enables the location of the queried name to be displayed in the center of the window by scaling and moving the map appropriately.

Production steps:
Make the interface as shown in the picture;

Figure 1 The interface of the query function

Use the Input_txt dynamic text box to receive the names of the names entered. With the external file xmldata.xml, in turn, place names and input_txt.text comparison, if two place names match, take the corresponding x, y axis coordinate value, map to do the corresponding scaling and moving operations. In this case, the map will be magnified 50 times times and the map center will be moved to the place where it was queried.

The contents of Xmldata.xml are as follows:


<r><n> jinding glorious century </n><x>37488</x><y>33882</y></r>
<r ><n> </n><x>38194</x><y>33651</y></r> building;
<r><n> Union City United Building </n><x>38402</x><y>33771</y></r>
<r><n> Foreign Trade light Industrial building </n ><X>38233</X><Y>32624</Y></R>
<r><n> Union Industrial Building </n><x> 13802</x><y>43238</y></r>
<r><n> Lo Wu Middle school </n><x>37225</x ><y>34520</y></r>
<r><n> Dongguan Foreign Trade mansion </n><x>37314</x><y >33971</y></r>
<r><n> Lido Mansion </n><x>37442</x><y>33995</y ></r>
<r><n> East Music Building </n><x>37746</x><y>33549</y></r>
<r><n> Hung Cheong Plaza </n><x>37996</x><y>33504</y></r>

(abbreviated) ...

Open the action panel of the timeline and enter the following ActionScript code:

input_text= "Please enter a place name"; Initialize input text box

var xmldata_xml:xml = new XML (); Loading external xmldata_xml files

Xmldata_xml.ignorewhite = true; Ignore whitespace

Xmldata_xml.load ("Http://www.wanggesz.com/XMLData/XMLData.xml");
Opens the XML file for the specified path

function XMLData () {//define query XMLData () functions

var input =_root. XMLData_mc.input_txt.text; Names of names entered

if (input== "") {_root. xmldata_mc.input_txt.text= "Please enter a place name"}
If the name of the place is empty, re-request the entry place

if (input!= "Please enter a place name") {//If a place name is correctly entered

var childitems:array = XMLData_xml.firstChild.childNodes;

for (Var i=0 i <childItems.length; i++) {

var sn= childitems[i].childnodes[0].childnodes[0].nodevalue;
Read the names in the XML file

if (sn==input) {//If input matches XML place name

var Sx=childitems[i].childnodes[1].childnodes[0].nodevalue;
Read the x-coordinate in the XML file

var Sy=childitems[i].childnodes[2].childnodes[0].nodevalue;
Read the y-coordinate in the XML file

_root.map_mc._xscale = _root.map_mc._yscale = 5000;
The map increases to 50 times times

_root.map_mc._x = 412.5-50* (10000*sx/1086848-412.5);
Map center Point moved to the location of the search

_root.map_mc._y = 213-50* (10000*sy/1086848-213);

_root.map_mc.roadname01_mc._visible=0; Hide Callout Place Name
}
}
}

Open the Action panel of the query button and enter the following ActionScript code:

On (release) {//When Mouse is released
XMLData (); Calling the query function
}

After the official release, enter "Lo Wu Secondary School", the corresponding code for "<r><n> Lo Wu Secondary school </n><x>37225</x><y>34520</y>< /r> ", Map automatically magnified 50 times times, map Center moved to (37225,34520). The effect is shown in Figure 2;

Figure 2 Query to place names, map to make the appropriate scaling and moving operations

At this point, flash electronic Map Production example series is over. Of course, the function of electronic map can be more rich, such as public transport query, the best path query, classification information query and so on. But scaling, moving, tagging, ranging, and querying are the basic functions of all electronic maps. As long as mastered these basic functions of the production method, you can make a more qualified electronic map.



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.