Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8826871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:14:58+00:00 2026-06-14T07:14:58+00:00

I’m using a plugin for Google Maps Geometry called GeoPortal to work our measurements

  • 0

I’m using a plugin for Google Maps Geometry called GeoPortal to work our measurements on the roof of buildings.

I’ve got the plugin working fine into my application, it picks up on the Longitude and Latitude of a previous page where they are dynamically created from an entered address.

The issue I am having is that people need to be able to navigate backwards and forwards through the application, meaning that the area plot needs to be remembered, so when they navigate back to that page they will not have to redraw the area every time.

In example I need to remember this plot layout for when the person navigates back to the page:

enter image description here

My code is as follows:

jQuery

var map;

var measure = {
    mvcLine: new google.maps.MVCArray(),
    mvcPolygon: new google.maps.MVCArray(),
    mvcMarkers: new google.maps.MVCArray(),
    line: null,
    polygon: null
};

jQuery(document).ready(function() {

    map = new google.maps.Map(document.getElementById("map"), {
        zoom: 21,
        center: new google.maps.LatLng(51.502378,-0.114348),
        mapTypeId: google.maps.MapTypeId.HYBRID,
        draggableCursor: "crosshair" 
    });


    google.maps.event.addListener(map, "click", function(evt) {
        measureAdd(evt.latLng);
    });

});


function measureAdd(latLng) {

    var marker = new google.maps.Marker({
        map: map,
        position: latLng,
        draggable: true,
        raiseOnDrag: false,
        title: "Drag me to change shape",
        icon: new google.maps.MarkerImage("http://maps.co.mecklenburg.nc.us/geoportal/img/measure-vertex.png", new google.maps.Size(9, 9), new google.maps.Point(0, 0), new google.maps.Point(5, 5))
    });

    measure.mvcLine.push(latLng);
    measure.mvcPolygon.push(latLng);

    measure.mvcMarkers.push(marker);

    var latLngIndex = measure.mvcLine.getLength() - 1;

    google.maps.event.addListener(marker, "mouseover", function() {
        marker.setIcon(new google.maps.MarkerImage("http://maps.co.mecklenburg.nc.us/geoportal/img/measure-vertex-hover.png", new google.maps.Size(15, 15), new google.maps.Point(0, 0), new google.maps.Point(8, 8)));
    });

    google.maps.event.addListener(marker, "mouseout", function() {
        marker.setIcon(new google.maps.MarkerImage("http://maps.co.mecklenburg.nc.us/geoportal/img/measure-vertex.png", new google.maps.Size(9, 9), new google.maps.Point(0, 0), new google.maps.Point(5, 5)));
    });

    google.maps.event.addListener(marker, "drag", function(evt) {
        measure.mvcLine.setAt(latLngIndex, evt.latLng);
        measure.mvcPolygon.setAt(latLngIndex, evt.latLng);
    });

    google.maps.event.addListener(marker, "dragend", function() {
        if (measure.mvcLine.getLength() > 1) {
            measureCalc();
        }
    });

    if (measure.mvcLine.getLength() > 1) {

        if (!measure.line) {

            measure.line = new google.maps.Polyline({
                map: map,
                clickable: false,
                strokeColor: "#FF0000",
                strokeOpacity: 1,
                strokeWeight: 3,
                path:measure. mvcLine
            });

        }

        if (measure.mvcPolygon.getLength() > 2) {

            if (!measure.polygon) {

                measure.polygon = new google.maps.Polygon({
                    clickable: false,
                    map: map,
                    fillOpacity: 0.25,
                    strokeOpacity: 0,
                    paths: measure.mvcPolygon
                });

            }

        }

    }

    if (measure.mvcLine.getLength() > 1) {
        measureCalc();
    }

}

function measureCalc() {

    var length = google.maps.geometry.spherical.computeLength(measure.line.getPath());
    jQuery("#span-length").text(length.toFixed(1))

    if (measure.mvcPolygon.getLength() > 2) {
        var area = google.maps.geometry.spherical.computeArea(measure.polygon.getPath());
        jQuery("#span-area").text(area.toFixed(1));
        document.getElementById('RoofArea').value = area.toFixed(1); 
        document.getElementById('submit').disabled = false;
    }


}

function measureReset() {

    if (measure.polygon) {
        measure.polygon.setMap(null);
        measure.polygon = null;
    }
    if (measure.line) {
        measure.line.setMap(null);
        measure.line = null
    }

    measure.mvcLine.clear();
    measure.mvcPolygon.clear();

    measure.mvcMarkers.forEach(function(elem, index) {
        elem.setMap(null);
    });
    measure.mvcMarkers.clear();

    jQuery("#span-length,#span-area").text(0);
    document.getElementById('submit').disabled = true;

}

HTML/CSS

<style>
    #map {
    width: 500px;
    height: 400px;
    margin: 0 auto; 
    border: 5px solid #2F4B9E;
    }
</style>

<div>
    <div id="map"></div>
    <p>Length (red line): <span id="span-length">0</span> mt<br />
    Area (grey area): <span id="span-area">0</span> mt&sup2;<br /> 
    <a href="javascript:measureReset();">Reset Measure</a></p>
</div>

jsFiddle

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T07:14:59+00:00Added an answer on June 14, 2026 at 7:14 am

    I actually answered my own question, so for the sake of closing this question, I’ll post my solution here. I’ve used ColdFusion too.

    In the measureAdd() function, I added this block of code below
    measure.mvcMarkers.push(marker);

    var toJSON = JSON.stringify(latLng);
    var toOutput = $.parseJSON(toJSON);
    
        $.ajax({
            type: "POST",
            url: "panels_plot.cfc",
            data: {
                method: "setLatLon",
                theLat: toOutput.$a,
                theLon: toOutput.ab
            },
            dataType: "json"
        });
    

    which posted to this .cfc I created

    <cfcomponent>
      <cffunction name="setLatLon" access="remote">
        <cfargument name="theLat" type="any" required="yes">
        <cfargument name="theLon" type="any" required="yes">
        <cfif NOT IsDefined('SESSION.latLon')>
            <cfset SESSION.latLon = ArrayNew(1)> 
        </cfif>
        <cfset st = StructNew()> 
        <cfset st.theLat = theLat>
        <cfset st.theLon = theLon>
        <cfset ArrayAppend(SESSION.latLon, st)>
      </cffunction>
    </cfcomponent>
    

    Then, right at the top under the first declaration of map, I added this cfloop

        <cfif IsDefined('SESSION.latLon')>
            <cfloop from="1" to="#ArrayLen(SESSION.latLon)#" index="i">
                <cfoutput>
                var jsonObj = new google.maps.LatLng(#SESSION.latLon[i].theLat#, #SESSION.latLon[i].theLon#);
    
                var marker#i# = new google.maps.Marker({
                    map: map,
                    position: jsonObj,
                    draggable: true,
                    raiseOnDrag: false,
                    title: "Drag me to change shape",
                    icon: new google.maps.MarkerImage("../admin/measure-vertex.png", new google.maps.Size(9, 9), new google.maps.Point(0, 0), new google.maps.Point(5, 5))
                });
    
                measure.mvcLine.push(jsonObj);
                measure.mvcPolygon.push(jsonObj);
    
                measure.mvcMarkers.push(marker#i#);
    
                var latLngIndex#i# = measure.mvcLine.getLength() - 1;
    
                google.maps.event.addListener(marker#i#, "mouseover", function() {
                    marker#i#.setIcon(new google.maps.MarkerImage("../admin/measure-vertex-hover.png", new google.maps.Size(15, 15), new google.maps.Point(0, 0), new google.maps.Point(8, 8)));
                });
    
                google.maps.event.addListener(marker#i#, "mouseout", function() {
                    marker#i#.setIcon(new google.maps.MarkerImage("../admin/measure-vertex.png", new google.maps.Size(9, 9), new google.maps.Point(0, 0), new google.maps.Point(5, 5)));
                });
    
                google.maps.event.addListener(marker#i#, "drag", function(evt) {
                    measure.mvcLine.setAt(latLngIndex#i#, evt.latLng);
                    measure.mvcPolygon.setAt(latLngIndex#i#, evt.latLng);
    
                });
    
                google.maps.event.addListener(marker#i#, "dragend", function() {
                    if (measure.mvcLine.getLength() > 1) {
                        measureCalc();
                    }
                });
    
                if (measure.mvcLine.getLength() > 1) {
    
                    if (!measure.line) {
    
                        measure.line = new google.maps.Polyline({
                            map: map,
                            clickable: false,
    
                        });
    
                    }
    
                    if (measure.mvcPolygon.getLength() > 2) {
    
                        if (!measure.polygon) {
    
                            measure.polygon = new google.maps.Polygon({
                                clickable: false,
                                map: map,
                                strokeColor: "##FF0000",
                                strokeOpacity: 1,
                                strokeWeight: 3,
                                paths: measure.mvcPolygon
                            });
    
                        }
    
                    }
    
                }
    
                if (measure.mvcLine.getLength() > 1) {
                    measureCalc();
                }
                </cfoutput>
            </cfloop>
        </cfif>
    

    Which sorted my problem out just fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a simple page using Google Maps API 3. My first. One marker
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.