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 8035757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:24:19+00:00 2026-06-05T02:24:19+00:00

I created a SVG on google map and I want to control on the

  • 0

I created a SVG on google map and I want to control on the width and length of the SVG object

The size is ok but the problem that the location of the SVG is not in the right place.

How i can control also on the location of the object ?

I tried to add transform for the

.attr("transform", "translate(" + width / 2 + "," + height / 2 + ")")

but then the size didn’t work.
When I tried also to add scale and translate to the projection the size also didn’t work.
Could you advise me how I can control on the location and the size ?
The idea that the first location of the SVG should be the same location only the size should change but the location should be always the same.
The current issue that when I change the zoom the SVG also change the location

   <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://mbostock.github.com/d3/d3.v2.js?2.8.1"></script>
<script type="text/javascript"
    src="http://maps.google.com/maps/api/js?sensor=true"></script>
<style>
html,body,#map {
    width: 95%;
    height: 95%;
    margin: 0;
    padding: 0;
}

.stations,.stations svg {
    position: absolute;
}

.stations svg {
    width: 60px;
    height: 20px;
    padding-right: 100px;
    font: 10px sans-serif;
}

.stations circle {
    fill: brown;
    stroke: black;
    stroke-width: 1.5px;
}

.background {
    fill: none;
    pointer-events: all;
}

#states path:hover {
    stroke: white;
}

#state-titels text {
    font-family: "ff-dagny-web-pro-1", "ff-dagny-web-pro-2", sans-serif;
    font-size: 8px;
    font-weight: 700;
    font-style: normal;
    font-size-adjust: none;
    color: #333333;
    text-transform: none;
    text-decoration: none;
    letter-spacing: normal;
    word-spacing: 0;
    text-align: start;
    vertical-align: baseline;
    direction: ltr;
    text-overflow: clip;
}

#states path {
    fill: #ccc;
    stroke: #fff;
    stroke-width: 1.5px;
}
</style>
</head>
<body>
    <div id="map"></div>
    <script type="text/javascript">
        //Create the Google Map…

        var first = 1;
        var zoom = 2;
        var map = new google.maps.Map(d3.select("#map").node(), {
            zoom : 2,
            center : new google.maps.LatLng(-53.76487, -110.41948),
            mapTypeId : google.maps.MapTypeId.TERRAIN
        });

        google.maps.event.addListener(map, 'zoom_changed', function() {
            zoom = map.getZoom();
        });

        var width = 10000, height = 1000, centered;

        var projection = d3.geo.albersUsa();

        var path = d3.geo.path().projection(projection);

        var count = 1;

        d3.json("../d3/us-states.json", function(json) {

            var overlay = new google.maps.OverlayView();
                overlay.onAdd = function() {


                var layer = d3.select(this.getPanes().overlayLayer).append("div");

                var width1 = 1000;
                var height1 = 1000;
                var svg = layer.append("svg").attr("width", width1).attr(
                        "height", height1);


                var states = svg.append("g").attr("id",
                        "states");

                states.selectAll("path").data(json.features).enter()
                .append("path").attr("d", path)//.attr("transform", "scale(" + (zoom) + ")")//.each(transform)
                .style("opacity", "0.7");

                overlay.draw = function() {
                    if ( zoom == 2)
                states.transition().attr("transform", "scale(" + (zoom / 8 ) + ")").style("stroke-width", 2 / zoom + "px");
                    else if ( zoom == 3)
                         states.transition().attr("transform", "scale(" + (zoom / 6 ) + ")").style("stroke-width", 2 / zoom + "px");
                    else if ( zoom == 4)
                     states.transition().attr("transform", "scale(" + (zoom / 4 ) + ")").style("stroke-width", 2 / zoom + "px");
                    else if ( zoom == 5)
                         states.transition().attr("transform", "scale(" + (zoom / 2 ) + ")").style("stroke-width", 2 / zoom + "px");

                };

            };

            overlay.setMap(map);

        });
    </script>
</body>
</html>
  • 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-05T02:24:21+00:00Added an answer on June 5, 2026 at 2:24 am

    Unless I’m misunderstanding the question, you should be able to control the size of the SVG simply by using CSS. So, with d3, rather than using attr() use style():

    layer.append("svg")
      .style("width", width1 + 'px')
      .style("height", height1 + 'px');
    

    Similarily, you’d control the position with .style("left", ...) and .style("top", ...), presuming your svg is absolutely positioned.

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

Sidebar

Related Questions

This happens in Firefox, but not in Google Chrome. I create an SVG 'Image'
I want to replace a flash object that uses a single swf file (map
I require ASP.NET server side code in a SVG that I created. To accomplish
I use embedded SVG in XHTML and want to create animations from Javascript, but
I've created a sierpinski triangle code. But i want to shade the triangles according
I have created an algorithm that converts text formatted in SVG into HTML, the
I have a SVG path, created in Inkscape, that is a single Move (M
I've got a series of SVG files that have been created in inkscape (or
I have a 1 megabyte vector svg file that I created with Adobe Illustrator.
I want to work with the nodes of a pre-created svg image with the

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.